@@ -17,7 +17,7 @@ use wiremock::matchers::{method, path};
1717use wiremock:: { Mock , MockServer , ResponseTemplate } ;
1818
1919use super :: apply_fixture:: {
20- hashed_file , install_npm_pkg , patch_record, stage_blob, write_manifest, write_root_package_json,
20+ install_npm_pkg , one_file , patch_record, stage_blob, write_manifest, write_root_package_json,
2121} ;
2222use crate :: common:: { binary, git_sha256, hermetic} ;
2323
@@ -51,7 +51,6 @@ fn run_apply(cwd: &Path, api_url: &str, extra: &[&str]) -> (i32, String, String)
5151async fn apply_online_fetches_missing_blob_and_patches_file ( ) {
5252 let before = b"before\n " ;
5353 let after = b"after\n " ;
54- let before_hash = git_sha256 ( before) ;
5554 let after_hash = git_sha256 ( after) ;
5655
5756 let mock = MockServer :: start ( ) . await ;
@@ -74,7 +73,7 @@ async fn apply_online_fetches_missing_blob_and_patches_file() {
7473 let socket = tmp. path ( ) . join ( ".socket" ) ;
7574 write_manifest (
7675 tmp. path ( ) ,
77- json ! ( { purl: patch_record( uuid, hashed_file ( "package/index.js" , & before_hash , & after_hash ) ) } ) ,
76+ json ! ( { purl: patch_record( uuid, one_file ( "package/index.js" , before , after ) ) } ) ,
7877 ) ;
7978
8079 let ( code, stdout, stderr) = run_apply ( tmp. path ( ) , & mock. uri ( ) , & [ ] ) ;
@@ -167,8 +166,6 @@ async fn apply_online_fetches_missing_blob_and_patches_file() {
167166async fn apply_with_ecosystem_filter_excluding_npm_skips_all_npm_patches ( ) {
168167 let before = b"before\n " ;
169168 let after = b"after\n " ;
170- let before_hash = git_sha256 ( before) ;
171- let after_hash = git_sha256 ( after) ;
172169
173170 let mock = MockServer :: start ( ) . await ;
174171 let purl = "pkg:npm/skipped@1.0.0" ;
@@ -179,7 +176,7 @@ async fn apply_with_ecosystem_filter_excluding_npm_skips_all_npm_patches() {
179176 install_npm_pkg ( tmp. path ( ) , "skipped" , "1.0.0" , Some ( before) ) ;
180177 write_manifest (
181178 tmp. path ( ) ,
182- json ! ( { purl: patch_record( uuid, hashed_file ( "package/index.js" , & before_hash , & after_hash ) ) } ) ,
179+ json ! ( { purl: patch_record( uuid, one_file ( "package/index.js" , before , after ) ) } ) ,
183180 ) ;
184181
185182 let ( code, stdout, stderr) = run_apply ( tmp. path ( ) , & mock. uri ( ) , & [ "--ecosystems" , "pypi" ] ) ;
@@ -250,15 +247,14 @@ async fn apply_with_ecosystem_filter_excluding_npm_skips_all_npm_patches() {
250247async fn apply_dry_run_emits_verified_event_without_writing ( ) {
251248 let before = b"before\n " ;
252249 let after = b"after\n " ;
253- let before_hash = git_sha256 ( before) ;
254250 let after_hash = git_sha256 ( after) ;
255251
256252 let tmp = tempfile:: tempdir ( ) . expect ( "tempdir" ) ;
257253 write_root_package_json ( tmp. path ( ) ) ;
258254 install_npm_pkg ( tmp. path ( ) , "dryrun-target" , "1.0.0" , Some ( before) ) ;
259255 write_manifest (
260256 tmp. path ( ) ,
261- json ! ( { "pkg:npm/dryrun-target@1.0.0" : patch_record( "11111111-1111-4111-8111-111111111111" , hashed_file ( "package/index.js" , & before_hash , & after_hash ) ) } ) ,
257+ json ! ( { "pkg:npm/dryrun-target@1.0.0" : patch_record( "11111111-1111-4111-8111-111111111111" , one_file ( "package/index.js" , before , after ) ) } ) ,
262258 ) ;
263259 // Pre-stage the after blob so we don't need to mock the network
264260 // path; we just want to verify dry-run reports the action correctly.
@@ -318,14 +314,13 @@ async fn apply_with_force_overrides_hash_mismatch() {
318314 let after_hash = git_sha256 ( after) ;
319315 let expected_before = b"expected-before\n " ;
320316 let actual_before = b"DIFFERENT-CONTENT\n " ; // wrong before content
321- let expected_before_hash = git_sha256 ( expected_before) ;
322317
323318 let tmp = tempfile:: tempdir ( ) . expect ( "tempdir" ) ;
324319 write_root_package_json ( tmp. path ( ) ) ;
325320 install_npm_pkg ( tmp. path ( ) , "force-target" , "1.0.0" , Some ( actual_before) ) ;
326321 write_manifest (
327322 tmp. path ( ) ,
328- json ! ( { "pkg:npm/force-target@1.0.0" : patch_record( "11111111-1111-4111-8111-111111111111" , hashed_file ( "package/index.js" , & expected_before_hash , & after_hash ) ) } ) ,
323+ json ! ( { "pkg:npm/force-target@1.0.0" : patch_record( "11111111-1111-4111-8111-111111111111" , one_file ( "package/index.js" , expected_before , after ) ) } ) ,
329324 ) ;
330325 // Pre-stage the after blob so we don't need the network.
331326 stage_blob ( tmp. path ( ) , & after_hash, after) ;
@@ -372,15 +367,14 @@ async fn apply_hash_mismatch_opt_in_warns_and_applies_strict_fails() {
372367 let after_hash = git_sha256 ( after) ;
373368 let expected_before = b"expected-before\n " ;
374369 let actual_before = b"DIFFERENT-CONTENT\n " ;
375- let expected_before_hash = git_sha256 ( expected_before) ;
376370
377371 let fixture = || {
378372 let tmp = tempfile:: tempdir ( ) . expect ( "tempdir" ) ;
379373 write_root_package_json ( tmp. path ( ) ) ;
380374 install_npm_pkg ( tmp. path ( ) , "mismatch" , "1.0.0" , Some ( actual_before) ) ;
381375 write_manifest (
382376 tmp. path ( ) ,
383- json ! ( { "pkg:npm/mismatch@1.0.0" : patch_record( "11111111-1111-4111-8111-111111111111" , hashed_file ( "package/index.js" , & expected_before_hash , & after_hash ) ) } ) ,
377+ json ! ( { "pkg:npm/mismatch@1.0.0" : patch_record( "11111111-1111-4111-8111-111111111111" , one_file ( "package/index.js" , expected_before , after ) ) } ) ,
384378 ) ;
385379 stage_blob ( tmp. path ( ) , & after_hash, after) ;
386380 tmp
@@ -467,7 +461,6 @@ async fn apply_hash_mismatch_opt_in_warns_and_applies_strict_fails() {
467461async fn apply_pypi_package_uses_python_crawler ( ) {
468462 let before = b"def hello():\n return 'before'\n " ;
469463 let after = b"def hello():\n return 'after'\n " ;
470- let before_hash = git_sha256 ( before) ;
471464 let after_hash = git_sha256 ( after) ;
472465
473466 let tmp = tempfile:: tempdir ( ) . expect ( "tempdir" ) ;
@@ -503,7 +496,7 @@ async fn apply_pypi_package_uses_python_crawler() {
503496
504497 write_manifest (
505498 tmp. path ( ) ,
506- json ! ( { "pkg:pypi/pypi_target@1.0.0" : patch_record( "11111111-1111-4111-8111-111111111111" , hashed_file ( "package/index.js" , & before_hash , & after_hash ) ) } ) ,
499+ json ! ( { "pkg:pypi/pypi_target@1.0.0" : patch_record( "11111111-1111-4111-8111-111111111111" , one_file ( "package/index.js" , before , after ) ) } ) ,
507500 ) ;
508501 stage_blob ( tmp. path ( ) , & after_hash, after) ;
509502
@@ -552,7 +545,6 @@ async fn apply_pypi_package_uses_python_crawler() {
552545async fn apply_uses_locally_cached_blob_without_fetching ( ) {
553546 let before = b"before\n " ;
554547 let after = b"after\n " ;
555- let before_hash = git_sha256 ( before) ;
556548 let after_hash = git_sha256 ( after) ;
557549
558550 let tmp = tempfile:: tempdir ( ) . expect ( "tempdir" ) ;
@@ -561,7 +553,7 @@ async fn apply_uses_locally_cached_blob_without_fetching() {
561553 let socket = tmp. path ( ) . join ( ".socket" ) ;
562554 write_manifest (
563555 tmp. path ( ) ,
564- json ! ( { "pkg:npm/cached@1.0.0" : patch_record( "22222222-2222-4222-8222-222222222222" , hashed_file ( "package/index.js" , & before_hash , & after_hash ) ) } ) ,
556+ json ! ( { "pkg:npm/cached@1.0.0" : patch_record( "22222222-2222-4222-8222-222222222222" , one_file ( "package/index.js" , before , after ) ) } ) ,
565557 ) ;
566558 stage_blob ( tmp. path ( ) , & after_hash, after) ;
567559
@@ -613,7 +605,6 @@ async fn apply_uses_locally_cached_blob_without_fetching() {
613605async fn apply_mismatch_redownloads_full_blob_and_applies ( ) {
614606 let after = b"after\n " ;
615607 let after_hash = git_sha256 ( after) ;
616- let expected_before_hash = git_sha256 ( b"expected-before\n " ) ;
617608
618609 let mock = MockServer :: start ( ) . await ;
619610 Mock :: given ( method ( "GET" ) )
@@ -636,7 +627,10 @@ async fn apply_mismatch_redownloads_full_blob_and_applies() {
636627 let socket = tmp. path ( ) . join ( ".socket" ) ;
637628 write_manifest (
638629 tmp. path ( ) ,
639- json ! ( { "pkg:npm/mismatch@1.0.0" : patch_record( uuid, hashed_file( "package/index.js" , & expected_before_hash, & after_hash) ) } ) ,
630+ json ! ( { "pkg:npm/mismatch@1.0.0" : patch_record(
631+ uuid,
632+ one_file( "package/index.js" , b"expected-before\n " , after) ,
633+ ) } ) ,
640634 ) ;
641635 // A leftover LOCAL package archive exists, but nothing reads it: only
642636 // the blob can produce the patched bytes, and no blob is cached.
@@ -705,7 +699,6 @@ async fn apply_mismatch_redownloads_full_blob_and_applies() {
705699async fn offline_apply_with_token_makes_zero_network_requests ( ) {
706700 let before = b"offline airgap before\n " ;
707701 let after = b"offline airgap after\n " ;
708- let before_hash = git_sha256 ( before) ;
709702 let after_hash = git_sha256 ( after) ;
710703
711704 // No mocks mounted: every request is a violation, and all are recorded.
@@ -716,7 +709,7 @@ async fn offline_apply_with_token_makes_zero_network_requests() {
716709 install_npm_pkg ( tmp. path ( ) , "airgap-test" , "1.0.0" , Some ( before) ) ;
717710 write_manifest (
718711 tmp. path ( ) ,
719- json ! ( { "pkg:npm/airgap-test@1.0.0" : patch_record( "33333333-3333-4333-8333-333333333333" , hashed_file ( "package/index.js" , & before_hash , & after_hash ) ) } ) ,
712+ json ! ( { "pkg:npm/airgap-test@1.0.0" : patch_record( "33333333-3333-4333-8333-333333333333" , one_file ( "package/index.js" , before , after ) ) } ) ,
720713 ) ;
721714 stage_blob ( tmp. path ( ) , & after_hash, after) ;
722715
@@ -798,7 +791,6 @@ fn write_package_archive(packages: &Path, uuid: &str, entries: &[(&str, &[u8])])
798791async fn apply_online_ignores_legacy_package_archive_when_downloads_fail ( ) {
799792 let before = b"pkgcache before\n " ;
800793 let after = b"pkgcache after\n " ;
801- let before_hash = git_sha256 ( before) ;
802794 let after_hash = git_sha256 ( after) ;
803795 let uuid = "44444444-4444-4444-8444-444444444444" ;
804796
@@ -812,7 +804,7 @@ async fn apply_online_ignores_legacy_package_archive_when_downloads_fail() {
812804 let socket = tmp. path ( ) . join ( ".socket" ) ;
813805 write_manifest (
814806 tmp. path ( ) ,
815- json ! ( { "pkg:npm/pkgcache@1.0.0" : patch_record( uuid, hashed_file ( "package/index.js" , & before_hash , & after_hash ) ) } ) ,
807+ json ! ( { "pkg:npm/pkgcache@1.0.0" : patch_record( uuid, one_file ( "package/index.js" , before , after ) ) } ) ,
816808 ) ;
817809 write_package_archive (
818810 & socket. join ( "packages" ) ,
@@ -857,7 +849,6 @@ async fn apply_online_ignores_legacy_package_archive_when_downloads_fail() {
857849async fn mismatch_overwrites_every_copy_of_a_duplicated_package ( ) {
858850 let before = b"before\n " ;
859851 let after = b"after\n " ;
860- let before_hash = git_sha256 ( before) ;
861852 let after_hash = git_sha256 ( after) ;
862853
863854 let mock = MockServer :: start ( ) . await ;
@@ -889,7 +880,7 @@ async fn mismatch_overwrites_every_copy_of_a_duplicated_package() {
889880 let socket = tmp. path ( ) . join ( ".socket" ) ;
890881 write_manifest (
891882 tmp. path ( ) ,
892- json ! ( { purl: patch_record( uuid, hashed_file ( "package/index.js" , & before_hash , & after_hash ) ) } ) ,
883+ json ! ( { purl: patch_record( uuid, one_file ( "package/index.js" , before , after ) ) } ) ,
893884 ) ;
894885 let ( code, stdout, stderr) = run_apply ( tmp. path ( ) , & mock. uri ( ) , & [ "--allow-patch-conflicts" ] ) ;
895886 let v: serde_json:: Value = serde_json:: from_str ( stdout. trim ( ) ) . expect ( "valid JSON" ) ;
0 commit comments