Skip to content

Commit d9c1df0

Browse files
mikolalysenkoclaude
andcommitted
fix: correct e2e force tests to use file corruption instead of version swap
npm test: Swapping to minimist@1.2.5 changes the PURL version so the crawler never matches the manifest key — apply returns success without reaching the hash check. Instead, corrupt the file content in-place. pypi test: The pydantic-ai patch variant may have files with empty beforeHash (new files). Dynamically find a file with a non-empty beforeHash to corrupt. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c3e4da8 commit d9c1df0

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

crates/socket-patch-cli/tests/e2e_npm.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ fn test_npm_save_only() {
440440
);
441441
}
442442

443-
/// `apply --force` should apply patches even when the installed version differs.
443+
/// `apply --force` should apply patches even when file hashes don't match.
444444
#[test]
445445
#[ignore]
446446
fn test_npm_apply_force() {
@@ -452,7 +452,6 @@ fn test_npm_apply_force() {
452452
let dir = tempfile::tempdir().unwrap();
453453
let cwd = dir.path();
454454

455-
// Install minimist@1.2.2 first, get the patch, then swap to a different version.
456455
write_package_json(cwd);
457456
npm_run(cwd, &["install", "minimist@1.2.2"]);
458457

@@ -462,13 +461,12 @@ fn test_npm_apply_force() {
462461
// Save the patch without applying.
463462
assert_run_ok(cwd, &["get", NPM_UUID, "--save-only"], "get --save-only");
464463

465-
// Now reinstall a different version to create a hash mismatch.
466-
npm_run(cwd, &["install", "minimist@1.2.5"]);
467-
468-
let mismatched_hash = git_sha256_file(&index_js);
464+
// Corrupt the file to create a hash mismatch (keep same version so PURL matches).
465+
std::fs::write(&index_js, b"// corrupted content\n").unwrap();
469466
assert_ne!(
470-
mismatched_hash, BEFORE_HASH,
471-
"minimist@1.2.5 should have a different index.js hash"
467+
git_sha256_file(&index_js),
468+
BEFORE_HASH,
469+
"corrupted file should have a different hash"
472470
);
473471

474472
// Normal apply should fail due to hash mismatch.

crates/socket-patch-cli/tests/e2e_pypi.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -594,22 +594,33 @@ fn test_pypi_apply_force() {
594594
let (_, files_value) = read_patch_files(&manifest_path);
595595
let files = files_value.as_object().unwrap();
596596

597-
// Corrupt one of the files to create a hash mismatch.
598-
let messages_py = site_packages.join("pydantic_ai/messages.py");
599-
let before_hash = files["pydantic_ai/messages.py"]["beforeHash"]
600-
.as_str()
601-
.unwrap();
597+
// Find a file with a non-empty beforeHash (i.e., an existing file, not a new one).
598+
let (target_rel, target_before_hash) = files
599+
.iter()
600+
.filter_map(|(rel_path, info)| {
601+
let bh = info["beforeHash"].as_str().unwrap_or("");
602+
if !bh.is_empty() {
603+
Some((rel_path.clone(), bh.to_string()))
604+
} else {
605+
None
606+
}
607+
})
608+
.next()
609+
.expect("patch should have at least one file with a non-empty beforeHash");
610+
611+
let target_path = site_packages.join(&target_rel);
602612
assert_eq!(
603-
git_sha256_file(&messages_py),
604-
before_hash,
605-
"file should match beforeHash before corruption"
613+
git_sha256_file(&target_path),
614+
target_before_hash,
615+
"{target_rel} should match beforeHash before corruption"
606616
);
607617

608-
std::fs::write(&messages_py, b"# corrupted content\n").unwrap();
618+
// Corrupt the file to create a hash mismatch.
619+
std::fs::write(&target_path, b"# corrupted content\n").unwrap();
609620
assert_ne!(
610-
git_sha256_file(&messages_py),
611-
before_hash,
612-
"file should have a different hash after corruption"
621+
git_sha256_file(&target_path),
622+
target_before_hash,
623+
"{target_rel} should have a different hash after corruption"
613624
);
614625

615626
// Normal apply should fail due to hash mismatch.

0 commit comments

Comments
 (0)