Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Wire vendor fixtures the way cargo vendor does
Three fixtures staged a bare `vendor/` with no source replacement and
relied on the crawler treating it as cargo's source. They now write the
`.cargo/config.toml` that `cargo vendor` asks for, and the resolver
strips a BOM through the shared text helper.

Refs #338

Assisted-by: Claude Code:claude-opus-5-5
  • Loading branch information
claude committed Oct 12, 2026
commit d20147a9811c6da4137822aac1fbe7757698b70b
14 changes: 14 additions & 0 deletions crates/socket-patch-cli/tests/e2e_cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ async fn scan_discovers_vendor_crates() {
// a crate source once the root is identified as a Cargo project. A vendored
// project always carries a lockfile, so stage one as the project marker.
std::fs::write(dir.path().join("Cargo.lock"), "version = 3\n").unwrap();
// `cargo vendor`'s source replacement: only a wired tree is where
// cargo builds from (#338).
std::fs::create_dir_all(dir.path().join(".cargo")).unwrap();
std::fs::write(
dir.path().join(".cargo/config.toml"),
"[source.crates-io]\nreplace-with = \"v\"\n[source.v]\ndirectory = \"vendor\"\n",
)
.unwrap();

// Set up vendor directory
let vendor_dir = dir.path().join("vendor");
Expand Down Expand Up @@ -494,6 +502,12 @@ async fn sync_keeps_shared_cache_entry_behind_a_cargo_vendor_dir() {
.unwrap();
let registry = root.join(".cargo/registry/src/index.crates.io-test");
let itoa_old = fake_registry_crate(&registry, "itoa", "1.0.11", patched);
// The source replacement that makes `vendor/` cargo's source (#338).
std::fs::write(
root.join(".cargo/config.toml"),
"[source.crates-io]\nreplace-with = \"v\"\n[source.v]\ndirectory = \"vendor\"\n",
)
.unwrap();

let socket = root.join(".socket");
let itoa = "pkg:cargo/itoa@1.0.11";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ pub fn crates_io_source(layers: &[ConfigLayer<'_>]) -> CratesIoSource {
let docs: Vec<(&Path, DocumentMut)> = layers
.iter()
.filter_map(|l| {
let text = l.text.strip_prefix('\u{feff}').unwrap_or(l.text);
text.parse::<DocumentMut>().ok().map(|d| (l.base, d))
crate::formats::text::strip_bom(l.text)
.parse::<DocumentMut>()
.ok()
.map(|d| (l.base, d))
})
.collect();
let lookup = |name: &str, key: &str| -> Option<(&Path, String)> {
Expand Down
12 changes: 11 additions & 1 deletion crates/socket-patch-core/tests/crawlers_empty_paths_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,23 @@ async fn cargo_crawler_crawl_all_empty_returns_empty() {
)
.await
.unwrap();
// The vendor tree is only scanned when cwd is a Rust project.
// The vendor tree is only scanned when cwd is a Rust project whose
// cargo config replaces crates.io with it (#338).
tokio::fs::write(
populated.path().join("Cargo.toml"),
"[package]\nname = \"root\"\nversion = \"0.1.0\"\n",
)
.await
.unwrap();
tokio::fs::create_dir_all(populated.path().join(".cargo"))
.await
.unwrap();
tokio::fs::write(
populated.path().join(".cargo/config.toml"),
"[source.crates-io]\nreplace-with = \"v\"\n[source.v]\ndirectory = \"vendor\"\n",
)
.await
.unwrap();
let found = crawler.crawl_all(&options_at(populated.path())).await;
assert!(
found.iter().any(|p| p.purl == "pkg:cargo/serde@1.0.200"),
Expand Down
Loading