Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion crates/socket-patch-cli/tests/hosted_memory_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2281,7 +2281,9 @@ async fn user_patched_npm_packages_are_never_pinned() {
.unwrap_or_else(|| panic!("{fixture} {file}: {:?}", project.skipped));
assert_eq!(skip.purl, "pkg:npm/left-pad@1.3.0");
assert!(
skip.detail.as_deref().is_some_and(|d| d.contains(file)),
skip.detail
.as_deref()
.is_some_and(|d| d.replace('\\', "/").contains(file)),
"{fixture}: {:?}",
skip.detail
);
Expand Down
35 changes: 21 additions & 14 deletions crates/socket-patch-core/src/patch/user_patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,12 @@ impl Bound {
)
}
Bound::Disk { root, repo } => {
!normalize_lexically_keeping_escapes(&root.join(rel)).starts_with(repo)
// `repo` is canonical (`\\?\C:\...` on Windows) while a
// script names a directory as users type it (`C:\...`), and
// `starts_with` treats the two prefixes as different.
use crate::utils::pnpm_workspace::without_verbatim_prefix;
!without_verbatim_prefix(normalize_lexically_keeping_escapes(&root.join(rel)))
.starts_with(without_verbatim_prefix(repo.clone()))
}
}
}
Expand Down Expand Up @@ -2058,14 +2063,14 @@ mod tests {
assert!(
left_pad
.iter()
.any(|s| s.ends_with("fixes/left-pad+1.3.0.patch")),
.any(|s| s.replace('\\', "/").ends_with("fixes/left-pad+1.3.0.patch")),
"{left_pad:?}"
);
let is_number = global.conflicts("pkg:npm/is-number@7.0.0");
assert!(
is_number
.iter()
.any(|s| s.ends_with("shared/a/patches/is-number+7.0.0.patch")),
is_number.iter().any(|s| s
.replace('\\', "/")
.ends_with("shared/a/patches/is-number+7.0.0.patch")),
"{is_number:?}"
);
assert!(global.conflicts("pkg:npm/right-pad@1.3.0").is_empty());
Expand Down Expand Up @@ -2115,15 +2120,17 @@ mod tests {
let tmp = tempfile::tempdir().unwrap();
let repo = std::fs::canonicalize(tmp.path()).unwrap();
write(&repo, ".git/HEAD", "ref: refs/heads/main\n");
let fixes = repo.join("fixes");
write(
&repo,
"package.json",
&format!(
r#"{{"scripts":{{"postinstall":"patch-package --patch-dir {}"}}}}"#,
fixes.display()
),
);
// Spelled as a user types it: on Windows without the `\\?\` prefix
// `canonicalize` adds to `repo`, quoted in case the temp dir has a
// space, and built as JSON so its backslashes are escaped.
let fixes =
crate::utils::pnpm_workspace::without_verbatim_prefix(repo.clone()).join("fixes");
let manifest = serde_json::json!({
"scripts": {
"postinstall": format!("patch-package --patch-dir \"{}\"", fixes.display())
}
});
write(&repo, "package.json", &manifest.to_string());
write(&repo, "fixes/left-pad+1.3.0.patch", "diff\n");
let index = UserPatchIndex::discover(&repo).await;
assert!(
Expand Down
8 changes: 7 additions & 1 deletion crates/socket-patch-core/src/utils/cargo_build_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,13 @@ mod tests {
.unwrap();
let warnings = invalidate_project(ReadScope::Workspace, &app, purls);
assert_eq!(warnings.len(), 1, "{warnings:?}");
assert!(warnings[0].1.contains(".cargo/config.toml"), "{warnings:?}");
assert!(
warnings[0]
.1
.replace('\\', "/")
.contains(".cargo/config.toml"),
"{warnings:?}"
);
// A global run reads it as before.
assert!(invalidate_project(ReadScope::Global, &app, purls).is_empty());
}
Expand Down
3 changes: 2 additions & 1 deletion crates/socket-patch-core/src/utils/repo_root_upward_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ fn pnpm_workspace_file_above_the_repository_fails_closed() {
write(&file, "packages:\n - other\n");
assert_eq!(
crate::utils::pnpm_workspace::governing_workspace_file(&l.app),
Some(file)
// Reported without Windows' `\\?\` prefix, which `layout` keeps.
Some(crate::utils::pnpm_workspace::without_verbatim_prefix(file))
);
let plain = layout(false);
write(
Expand Down
3 changes: 2 additions & 1 deletion crates/socket-patch-core/src/vex/discover/user_patched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ mod tests {
assert!(
out.unattested[0]
.detail
.replace('\\', "/")
.contains("patches/left-pad+1.3.0.patch"),
"{}",
out.unattested[0].detail
Expand Down Expand Up @@ -420,7 +421,7 @@ mod tests {
all_marked(&out, what);
let member = files[files.len() - 1].0.rsplit_once('/').unwrap().0;
assert!(
out.unattested[0].detail.contains(member),
out.unattested[0].detail.replace('\\', "/").contains(member),
"{what}: {}",
out.unattested[0].detail
);
Expand Down
Loading