Skip to content

Commit 89e8337

Browse files
committed
Test pip marker split across includes end to end
Vendor a six marker split whose branches sit in different files of the -r tree, in both layouts, then install the result with pip --no-index in a fresh checkout and check the patched module is imported, and that revert restores both files byte for byte. Refs #1104 Assisted-by: Claude Code:claude-opus-5-5
1 parent ba77e57 commit 89e8337

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

‎crates/socket-patch-cli/tests/e2e_vendor_pypi_build.rs‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,119 @@ fn pip_vendored_requirements_evaluate_environment_markers() {
18741874
}
18751875
}
18761876

1877+
/// #1104: the #928 marker split with its branches in different files of
1878+
/// the `-r` tree (a layered `base.txt` plus a root file). pip merges the
1879+
/// tree into one requirement set, so vendoring must rewrite the 1.16.0
1880+
/// branch where it lives, leave the other version's branch alone in either
1881+
/// layout, install the patched wheel from a fresh `--no-index` checkout,
1882+
/// and revert byte-identically. Before the fix the file holding only the
1883+
/// other branch made vendored refuse with a false
1884+
/// `pypi_requirement_not_pinned`.
1885+
#[test]
1886+
#[serial_test::serial]
1887+
fn pip_vendored_requirements_marker_split_across_includes() {
1888+
let python =
1889+
find_python().expect("Python is required for the pip cross-file marker-split regression");
1890+
let target = "six==1.16.0 ; python_full_version >= '3'\n";
1891+
// Never matches the running interpreter.
1892+
let other = "six==1.17.0 ; python_full_version < '3'\n";
1893+
for (label, root_pin, include_pin) in [("root", target, other), ("include", other, target)] {
1894+
let tmp = tempfile::tempdir().unwrap();
1895+
let project = tmp.path().join("proj");
1896+
std::fs::create_dir_all(&project).unwrap();
1897+
assert_tool_ok(
1898+
&tool(Path::new(python), &project, &["-m", "venv", ".venv"], &[]),
1899+
"create source venv",
1900+
);
1901+
let venv = project.join(".venv");
1902+
assert_tool_ok(
1903+
&tool(
1904+
&venv.join("bin/pip"),
1905+
&project,
1906+
&["install", "--disable-pip-version-check", "six==1.16.0"],
1907+
&[],
1908+
),
1909+
"install upstream six",
1910+
);
1911+
let patched = stage_patch(&project, &site_packages(&venv).join("six.py"));
1912+
let root_original = format!("-r base.txt\n{root_pin}");
1913+
let base_original = include_pin.to_string();
1914+
std::fs::write(project.join("requirements.txt"), &root_original).unwrap();
1915+
std::fs::write(project.join("base.txt"), &base_original).unwrap();
1916+
1917+
let (code, stdout, stderr) = run_vendored(&VendorDriver::VendorOffline, &project);
1918+
assert_eq!(code, 0, "[{label}] vendor failed: {stdout}\n{stderr}");
1919+
assert_vendored_applied(&parse_envelope(&stdout));
1920+
let (wired, untouched, untouched_original) = if label == "root" {
1921+
("requirements.txt", "base.txt", &base_original)
1922+
} else {
1923+
("base.txt", "requirements.txt", &root_original)
1924+
};
1925+
assert_eq!(
1926+
&std::fs::read_to_string(project.join(untouched)).unwrap(),
1927+
untouched_original,
1928+
"[{label}] the other branch's file must stay untouched"
1929+
);
1930+
let wired_now = std::fs::read_to_string(project.join(wired)).unwrap();
1931+
let vendor_line = wired_now.lines().last().unwrap();
1932+
assert!(
1933+
vendor_line.starts_with("./.socket/vendor/pypi/")
1934+
&& vendor_line.contains(" ; python_full_version >= '3' # socket-patch vendor:"),
1935+
"[{label}] the 1.16.0 branch becomes a marker-carrying vendor line: {vendor_line}"
1936+
);
1937+
1938+
let fresh = project.join("fresh");
1939+
std::fs::create_dir_all(&fresh).unwrap();
1940+
for file in ["requirements.txt", "base.txt"] {
1941+
std::fs::copy(project.join(file), fresh.join(file)).unwrap();
1942+
}
1943+
copy_dir_recursive(&project.join(".socket"), &fresh.join(".socket"));
1944+
assert_tool_ok(
1945+
&tool(Path::new(python), &fresh, &["-m", "venv", ".venv"], &[]),
1946+
"create fresh venv",
1947+
);
1948+
let fresh_venv = fresh.join(".venv");
1949+
assert_tool_ok(
1950+
&tool(
1951+
&fresh_venv.join("bin/pip"),
1952+
&fresh,
1953+
&[
1954+
"install",
1955+
"--disable-pip-version-check",
1956+
"--no-index",
1957+
"-r",
1958+
"requirements.txt",
1959+
],
1960+
&[],
1961+
),
1962+
"install vendored cross-file marker-split requirements",
1963+
);
1964+
assert_eq!(python_oracle(&fresh_venv, &fresh), "1", "[{label}]");
1965+
// The VEX steps un-wire by restoring the root file, which holds the
1966+
// vendor line only in this layout.
1967+
if label == "root" {
1968+
manifestless_vex(
1969+
&fresh,
1970+
"pip vendored cross-file marker split",
1971+
&patched,
1972+
root_original.as_bytes(),
1973+
);
1974+
}
1975+
1976+
let (code, stdout, stderr) =
1977+
run_socket(&project, &["vendor", "--revert", "--offline", "--json"]);
1978+
assert_eq!(code, 0, "[{label}] revert failed: {stdout}\n{stderr}");
1979+
assert_eq!(
1980+
std::fs::read_to_string(project.join("requirements.txt")).unwrap(),
1981+
root_original
1982+
);
1983+
assert_eq!(
1984+
std::fs::read_to_string(project.join("base.txt")).unwrap(),
1985+
base_original
1986+
);
1987+
}
1988+
}
1989+
18771990
/// #928: `uv pip compile --universal` splits a package across marker
18781991
/// branches when it resolves differently per Python. Vendoring the patched
18791992
/// 1.16.0 must rewrite only that branch (marker and hash kept) and leave

0 commit comments

Comments
 (0)