@@ -5442,18 +5442,20 @@ pub(crate) struct VendorGcSummary {
54425442 /// (b) entries whose package left the lockfile dependency graph —
54435443 /// reverted, and their manifest entries dropped.
54445444 pub unused_reverted : Vec < String > ,
5445- /// Entries a wet revert drift-kept ([`RevertOutcome::kept_artifact`]):
5446- /// the backend left the drifted lock alone, so artifacts, ledger entry
5447- /// and (in (b)) manifest records were all retained — nothing reclaimed.
5448- /// Always empty on dry runs: backends detect drift only during a wet
5449- /// wiring replay, so the preview still lists such entries as revertable.
5450- pub kept : Vec < String > ,
5445+ /// Entries a wet revert kept ([`RevertOutcome::kept_artifact`]), each
5446+ /// with why: the backend left a drifted lock alone, or restored the
5447+ /// recorded wiring while another project file still installs from the
5448+ /// artifact. Artifacts, ledger entry and (in (b)) manifest records were
5449+ /// all retained — nothing reclaimed. Always empty on dry runs: the
5450+ /// preview runs no revert, so it still lists such entries as
5451+ /// revertable.
5452+ pub kept : Vec < ( String , KeepCause ) > ,
54515453 /// (c) orphan uuid dirs (no owning ledger entry) swept.
54525454 pub orphan_dirs : usize ,
5453- /// Entries (ledger keys) that could not be reverted — kept in the
5454- /// ledger, nothing reclaimed. Only purls; the pass-level outcomes below
5455- /// have their own fields.
5456- pub failed : Vec < String > ,
5455+ /// Entries (ledger keys) that could not be reverted, each with the
5456+ /// backend's reason — kept in the ledger, nothing reclaimed. The
5457+ /// pass-level outcomes below have their own fields.
5458+ pub failed : Vec < ( String , String ) > ,
54575459 /// Post-revert rewrites that failed: `("vendor_state_write_failed" |
54585460 /// "manifest_write_failed", <detail>)`. The reverts themselves already
54595461 /// happened on disk; the stale record is what the caller must report.
@@ -5465,7 +5467,8 @@ pub(crate) struct VendorGcSummary {
54655467 /// `vendor_vlt_reinstall_required`, and, for a manifest-dropped PyPI
54665468 /// entry under pip, PDM, uv or Pipenv, `vendor_pypi_reinstall_required`
54675469 /// (#477). Every other reverting command surfaces these, and the GC
5468- /// must not drop them.
5470+ /// must not drop them. Also the `vendor_revert_residual_reference`
5471+ /// warning of an entry kept for one: it names the file to fix.
54695472 pub advisories : Vec < ( & ' static str , String ) > ,
54705473}
54715474
@@ -5475,7 +5478,9 @@ pub(crate) struct VendorGcSummary {
54755478/// revert's other warnings are routine for a prune and stay out:
54765479/// `vendor_lock_entry_removed` is the normal leg-(b) case (the dependency
54775480/// was uninstalled), and a drift keep is already reported through
5478- /// `keptVendoredEntries` and its own `GC: kept …` line.
5481+ /// `keptVendoredEntries` and its own `GC: kept …` line. A keep for a
5482+ /// residual reference forwards the warning that names the file
5483+ /// ([`VendorGcSummary::note_unreclaimed`]).
54795484const GC_FORWARDED_ADVISORIES : & [ & str ] = & [
54805485 socket_patch_core:: vendor:: bun_lock:: REINSTALL_REQUIRED ,
54815486 socket_patch_core:: vendor:: vlt_lock:: REINSTALL_REQUIRED ,
@@ -5485,10 +5490,12 @@ const GC_FORWARDED_ADVISORIES: &[&str] = &[
54855490
54865491impl VendorGcSummary {
54875492 /// Keep a revert's reinstall advisories. Only a revert that actually
5488- /// restored the lock (succeeded, not drift-kept) can leave a stale
5489- /// installed copy behind.
5493+ /// restored the lock can leave a stale installed copy behind: one that
5494+ /// succeeded and was not drift-kept. A keep for a residual reference
5495+ /// restored it too.
54905496 fn take_advisories ( & mut self , outcome : & RevertOutcome ) {
5491- if !outcome. success || outcome. kept_artifact {
5497+ let drift_kept = outcome. kept_artifact && KeepCause :: of ( outcome) == KeepCause :: Drift ;
5498+ if !outcome. success || drift_kept {
54925499 return ;
54935500 }
54945501 self . advisories . extend (
@@ -5499,6 +5506,39 @@ impl VendorGcSummary {
54995506 . map ( |w| ( w. code , w. detail . clone ( ) ) ) ,
55005507 ) ;
55015508 }
5509+
5510+ /// File a wet revert of `purl` that reclaimed nothing: a failure with
5511+ /// the backend's reason, or a keep with its cause, classified as for
5512+ /// `remove` and `rollback` ([`KeepCause::of`]). A keep for a residual
5513+ /// reference carries the warning that names the file still installing
5514+ /// from the artifact, without which its remedy cannot be followed; the
5515+ /// purl leads its detail, since the backend names only the uuid dir.
5516+ /// `false` when the revert went through.
5517+ fn note_unreclaimed ( & mut self , purl : & str , outcome : & RevertOutcome ) -> bool {
5518+ if !outcome. success {
5519+ let why = outcome. error . clone ( ) ;
5520+ self . failed . push ( (
5521+ purl. to_string ( ) ,
5522+ why. unwrap_or_else ( || "unknown error" . into ( ) ) ,
5523+ ) ) ;
5524+ return true ;
5525+ }
5526+ if !outcome. kept_artifact {
5527+ return false ;
5528+ }
5529+ let cause = KeepCause :: of ( outcome) ;
5530+ if cause == KeepCause :: Reference {
5531+ self . advisories . extend (
5532+ outcome
5533+ . warnings
5534+ . iter ( )
5535+ . filter ( |w| w. code == vendor:: RESIDUAL_REFERENCE_CODE )
5536+ . map ( |w| ( w. code , format ! ( "{purl}: {}" , w. detail) ) ) ,
5537+ ) ;
5538+ }
5539+ self . kept . push ( ( purl. to_string ( ) , cause) ) ;
5540+ true
5541+ }
55025542}
55035543/// The manifest keys an unused vendored `entry`, stored under ledger key
55045544/// `purl`, owns: every key with the same [`PurlKey`] as the ledger key OR
@@ -5532,12 +5572,12 @@ pub(crate) fn unused_vendored_manifest_keys<V>(
55325572/// prune + blob sweep reclaims the rest in the same pass;
55335573/// (c) sweep orphan uuid dirs.
55345574///
5535- /// A drift-skipped revert ([`RevertOutcome::kept_artifact`]) keeps the
5536- /// ledger entry — and, in (b), the purl's manifest records — exactly like
5537- /// every other `dispatch_revert_one` caller; the kept purl is reported in
5538- /// [`VendorGcSummary::kept`] so `scan --prune` can explain it. Wet-only: a
5539- /// dry [`dispatch_revert_one `] returns before the wiring replay that
5540- /// detects drift .
5575+ /// A revert that kept its artifact ([`RevertOutcome::kept_artifact`]: a
5576+ /// drifted lock, or another project file that still installs from it)
5577+ /// keeps the ledger entry — and, in (b), the purl's manifest records —
5578+ /// exactly like every other `dispatch_revert_one` caller; the kept purl is
5579+ /// reported with its cause in [`VendorGcSummary::kept `] so `scan --prune`
5580+ /// can explain it. Wet-only: the dry pass runs no revert .
55415581///
55425582/// Detached entries — every `scan`/`get --mode vendored` entry — are exempt
55435583/// from (a) alone: they are never manifest-tracked, so "absent from the
@@ -5617,14 +5657,10 @@ pub(crate) async fn run_vendor_gc(
56175657 . await ;
56185658 }
56195659 out. take_advisories ( & outcome) ;
5620- if !outcome. success {
5621- out. failed . push ( purl) ;
5622- } else if outcome. kept_artifact {
5623- // Drift-skip keep: the ledger entry must survive too (which
5624- // also shields the uuid dir from the (c) orphan sweep), and
5625- // the purl is reported as kept, never as reverted.
5626- out. kept . push ( purl) ;
5627- } else {
5660+ // A kept artifact: the ledger entry must survive too (which
5661+ // also shields the uuid dir from the (c) orphan sweep), and
5662+ // the purl is reported as kept, never as reverted.
5663+ if !out. note_unreclaimed ( & purl, & outcome) {
56285664 state. entries . remove ( & purl) ;
56295665 ledger_dirty = true ;
56305666 out. dropped_reverted . push ( purl) ;
@@ -5665,16 +5701,11 @@ pub(crate) async fn run_vendor_gc(
56655701 }
56665702 let outcome = dispatch_revert_one ( & entry, & common. cwd , false ) . await ;
56675703 out. take_advisories ( & outcome) ;
5668- if !outcome. success {
5669- out. failed . push ( purl) ;
5670- continue ;
5671- }
5672- if outcome. kept_artifact {
5673- // Drift-skip keep, same gate as (a) — and the purl's manifest
5674- // records must survive too: pruning them would make the next
5675- // `vendor` reconcile re-revert an entry whose backing record is
5676- // gone.
5677- out. kept . push ( purl) ;
5704+ // A kept artifact, same gate as (a) — and the purl's manifest
5705+ // records must survive too: pruning them would make the next
5706+ // `vendor` reconcile re-revert an entry whose backing record is
5707+ // gone.
5708+ if out. note_unreclaimed ( & purl, & outcome) {
56785709 continue ;
56795710 }
56805711 state. entries . remove ( & purl) ;
@@ -7476,7 +7507,7 @@ mod gc_tests {
74767507 assert ! ( out. failed. is_empty( ) , "a keep is not a failure: {out:?}" ) ;
74777508 assert_eq ! (
74787509 out. kept,
7479- vec![ PURL . to_string( ) ] ,
7510+ vec![ ( PURL . to_string( ) , KeepCause :: Drift ) ] ,
74807511 "the drift-keep must be COUNTED — scan --prune's only signal \
74817512 that the entry its preview listed was deliberately not \
74827513 reclaimed: {out:?}"
@@ -7522,7 +7553,7 @@ mod gc_tests {
75227553 assert ! ( out. failed. is_empty( ) , "a keep is not a failure: {out:?}" ) ;
75237554 assert_eq ! (
75247555 out. kept,
7525- vec![ PURL . to_string( ) ] ,
7556+ vec![ ( PURL . to_string( ) , KeepCause :: Drift ) ] ,
75267557 "the drift-keep must be COUNTED — scan --prune's only signal \
75277558 that the entry its preview listed was deliberately not \
75287559 reclaimed: {out:?}"
@@ -7775,10 +7806,61 @@ mod gc_tests {
77757806 ) ;
77767807 }
77777808
7809+ /// What the pass keeps of a kept revert follows from why it was kept.
7810+ /// A keep for a residual reference restored the lock: its reinstall
7811+ /// advisory stands, and the warning that names the file is carried
7812+ /// under the purl. A drift keep restored nothing and repeats nothing.
7813+ #[ test]
7814+ fn a_kept_revert_is_filed_by_its_cause ( ) {
7815+ use socket_patch_core:: vendor:: vlt_lock:: REINSTALL_REQUIRED ;
7816+ let dir = format ! ( ".socket/vendor/npm/{UUID}" ) ;
7817+ let reinstall = || VendorWarning :: new ( REINSTALL_REQUIRED , "run `vlt ci`" ) ;
7818+
7819+ let mut reference = RevertOutcome :: ok ( ) ;
7820+ reference. warnings . push ( reinstall ( ) ) ;
7821+ reference. warnings . push ( VendorWarning :: new (
7822+ vendor:: RESIDUAL_REFERENCE_CODE ,
7823+ format ! ( "kept {dir}/: apps/web/package.json still names it" ) ,
7824+ ) ) ;
7825+ reference. keep_artifact_for_reference ( & dir) ;
7826+ let mut out = VendorGcSummary :: default ( ) ;
7827+ out. take_advisories ( & reference) ;
7828+ assert ! ( out. note_unreclaimed( PURL , & reference) ) ;
7829+ assert_eq ! ( out. kept, vec![ ( PURL . to_string( ) , KeepCause :: Reference ) ] ) ;
7830+ assert_eq ! (
7831+ out. advisories,
7832+ vec![
7833+ ( REINSTALL_REQUIRED , "run `vlt ci`" . to_string( ) ) ,
7834+ (
7835+ vendor:: RESIDUAL_REFERENCE_CODE ,
7836+ format!( "{PURL}: kept {dir}/: apps/web/package.json still names it" ) ,
7837+ ) ,
7838+ ]
7839+ ) ;
7840+
7841+ let mut drift = RevertOutcome :: ok ( ) ;
7842+ drift. warnings . push ( reinstall ( ) ) ;
7843+ drift. warnings . push ( VendorWarning :: new (
7844+ "vendor_lock_entry_drifted" ,
7845+ "node_modules/left-pad was re-resolved" ,
7846+ ) ) ;
7847+ drift. keep_artifact ( & dir) ;
7848+ let mut out = VendorGcSummary :: default ( ) ;
7849+ out. take_advisories ( & drift) ;
7850+ assert ! ( out. note_unreclaimed( PURL , & drift) ) ;
7851+ assert_eq ! ( out. kept, vec![ ( PURL . to_string( ) , KeepCause :: Drift ) ] ) ;
7852+ assert ! ( out. advisories. is_empty( ) , "{out:?}" ) ;
7853+
7854+ // A revert that went through is neither kept nor failed.
7855+ let mut out = VendorGcSummary :: default ( ) ;
7856+ assert ! ( !out. note_unreclaimed( PURL , & RevertOutcome :: ok( ) ) ) ;
7857+ assert ! ( out. kept. is_empty( ) && out. failed. is_empty( ) , "{out:?}" ) ;
7858+ }
7859+
77787860 /// (a) revert FAILURE accounting: a ledger entry whose ecosystem has no
77797861 /// revert backend (a tampered/hand-edited state.json) lands in
7780- /// `out.failed`, is KEPT in the ledger, and is excluded from pass (b)
7781- /// (no double count).
7862+ /// `out.failed` with the backend's reason , is KEPT in the ledger, and
7863+ /// is excluded from pass (b) (no double count).
77827864 #[ tokio:: test]
77837865 async fn vendor_gc_failed_dropped_revert_keeps_entry ( ) {
77847866 let ( tmp, common, manifest_path) = gc_fixture ( false ) . await ;
@@ -7790,7 +7872,14 @@ mod gc_tests {
77907872 save_state ( tmp. path ( ) , & state) . await . unwrap ( ) ;
77917873
77927874 let out = run_vendor_gc ( & common, & manifest_path, false ) . await ;
7793- assert_eq ! ( out. failed, vec![ PURL . to_string( ) ] , "{out:?}" ) ;
7875+ assert_eq ! (
7876+ out. failed,
7877+ vec![ (
7878+ PURL . to_string( ) ,
7879+ "this build has no vendor backend for ecosystem `frobnicate`" . to_string( )
7880+ ) ] ,
7881+ "{out:?}"
7882+ ) ;
77947883 assert ! ( out. dropped_reverted. is_empty( ) , "{out:?}" ) ;
77957884 assert ! (
77967885 out. unused_reverted. is_empty( ) ,
@@ -7824,7 +7913,16 @@ mod gc_tests {
78247913 save_state ( tmp. path ( ) , & state) . await . unwrap ( ) ;
78257914
78267915 let out = run_vendor_gc ( & common, & manifest_path, false ) . await ;
7827- assert_eq ! ( out. failed, vec![ PURL . to_string( ) ] , "{out:?}" ) ;
7916+ assert_eq ! (
7917+ out. failed,
7918+ vec![ (
7919+ PURL . to_string( ) ,
7920+ "refusing revert: `deadbeef` is not a canonical patch uuid (tampered \
7921+ state.json?)"
7922+ . to_string( )
7923+ ) ] ,
7924+ "{out:?}"
7925+ ) ;
78287926 assert ! ( out. unused_reverted. is_empty( ) , "{out:?}" ) ;
78297927 assert ! ( out. dropped_reverted. is_empty( ) , "{out:?}" ) ;
78307928 assert ! (
0 commit comments