From d745047498afdac42927d376ccda7b4651e7f813 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 21:23:08 +0000 Subject: [PATCH 1/4] Start fix for the gem refresh build label The hosted refresh of an installed native gem says it builds "from its patched gem" in both directions, also when rollback or remove installs the upstream gem (#2152). Assisted-by: Claude Code:claude-fable-5-2 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeNXZ8oGYWanAWxsCiy From 6c92ec5a25747616625b47fa2b401e1c1bdf2a2e Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 21:36:16 +0000 Subject: [PATCH 2/4] Test the build label of a gem's upstream refresh A native gem's staged build through a stand-in Ruby, in both directions. It fails for the upstream gem, which rollback and remove install: the progress line says "from its patched gem" (#2152). Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeNXZ8oGYWanAWxsCiy Assisted-by: Claude Code:claude-fable-5-2 --- .../src/patch/gem_refresh.rs | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/crates/socket-patch-core/src/patch/gem_refresh.rs b/crates/socket-patch-core/src/patch/gem_refresh.rs index 0f9c9fcc9..e47b404c6 100644 --- a/crates/socket-patch-core/src/patch/gem_refresh.rs +++ b/crates/socket-patch-core/src/patch/gem_refresh.rs @@ -1129,4 +1129,106 @@ mod tests { ); assert!(!home.join(STAGE_DIR).exists()); } + + /// The progress line of a native gem's staged build names the gem + /// that is built (#2152): `rollback` and `remove` build the upstream + /// gem, and the line said "from its patched gem" for them as well. + #[cfg(unix)] + #[tokio::test] + async fn a_native_build_names_the_gem_it_builds() { + use std::os::unix::fs::PermissionsExt; + use std::sync::Mutex; + static SAID: Mutex> = Mutex::new(Vec::new()); + fn say(line: &str) { + SAID.lock().unwrap().push(line.to_string()); + } + + let tmp = tempfile::tempdir().unwrap(); + // A gem home under a Ruby prefix, whose `bin/ruby` is the Ruby + // asked first. This one answers the extensions-dir question for + // the home and "installs" into the stage home what RubyGems would. + let prefix = tmp.path().join("prefix"); + let home = prefix.join("lib/ruby/gems/3.4.0"); + std::fs::create_dir_all(prefix.join("bin")).unwrap(); + let fake = prefix.join("bin/ruby"); + std::fs::write( + &fake, + "#!/bin/sh + if [ \"$3\" = extensions_dir ]; then + printf 'sp_extensions_dir\\t%s\\n' \"$4/extensions/p/3.4.0\" + elif [ \"$3\" = install ]; then + mkdir -p \"$5/gems/rack-2.2.3/lib\" \"$5/extensions/p/3.4.0/rack-2.2.3\" + printf 'BUILT\\n' > \"$5/gems/rack-2.2.3/lib/rack.rb\" + : > \"$5/extensions/p/3.4.0/rack-2.2.3/gem.build_complete\" + printf 'sp_installed\\track-2.2.3\\t%s\\n' \"$5/extensions/p/3.4.0/rack-2.2.3\" + else exit 1; fi +", + ) + .unwrap(); + std::fs::set_permissions(&fake, std::fs::Permissions::from_mode(0o755)).unwrap(); + let proj = tmp.path().join("proj"); + std::fs::create_dir_all(&proj).unwrap(); + + let native_meta = metadata("rack", "2.2.3", &["ext/rack/extconf.rb"]); + let old = gem_with(&native_meta, &[("lib/rack.rb", PATCHED_LIB, 0o644)]); + let new = gem_with(&native_meta, &[("lib/rack.rb", UPSTREAM_LIB, 0o644)]); + let gem_dir = install(&home, "PATCHED\n", &old); + std::fs::write( + home.join("specifications/rack-2.2.3.gemspec"), + "Gem::Specification.new do |s|\n s.name = \"rack\".freeze\n s.require_paths = \ + [\"lib\".freeze]\n s.extensions = [\"ext/rack/extconf.rb\".freeze]\nend\n", + ) + .unwrap(); + std::fs::create_dir_all(home.join("extensions/p/3.4.0/rack-2.2.3")).unwrap(); + let source = tmp.path().join("upstream.gem"); + std::fs::write(&source, &new).unwrap(); + + let env = RubyEnv { + cwd: proj, + rebuild: true, + offline: true, + progress: Some(say), + }; + // The unwind direction first, then the same build as a scan runs + // it, for the patched gem. + for kind in ["upstream", "patched"] { + let wanted = Wanted { + kind, + ..wanted(&new, &[&source]) + }; + let targets = [Target::Installed(gem_dir.clone())]; + // A sibling test forking while the script was being written + // holds its write fd until it execs: ETXTBSY (os error 26). + let out = loop { + SAID.lock().unwrap().clear(); + let out = refresh(&wanted, &targets, &Source::DiskOnly, &env).await; + match &out[0] { + Err(why) if why.contains("os error 26") => { + tokio::time::sleep(std::time::Duration::from_millis(20)).await; + } + _ => break out, + } + }; + assert_eq!(out, [Ok(())], "{kind}"); + assert_eq!( + std::fs::read(gem_dir.join("lib/rack.rb")).unwrap(), + b"BUILT\n", + "{kind}: the staged install replaces the copy" + ); + let said = SAID.lock().unwrap().clone(); + assert_eq!(said.len(), 2, "{kind}: {said:?}"); + assert_eq!( + said[0], + format!( + "Rebuilding the native extension of rack-2.2.3 from its {kind} gem; this \ + can take several minutes." + ), + "{kind}" + ); + assert!( + said[1].starts_with("The build of rack-2.2.3 finished after "), + "{kind}: {said:?}" + ); + } + } } From 451db6490245c316abca95a5c86d81845e905496 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 21:37:55 +0000 Subject: [PATCH 3/4] Name the gem a hosted gem refresh builds The staged install of a native gem labelled every build "from its patched gem". rollback and remove run it for the upstream gem, so their progress line said the patch was being rebuilt while the upstream gem was installed. The refresh already knows which gem it installs (patched or upstream) for its other messages, and now hands that to the staged install for the progress line. Fixes #2152 Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeNXZ8oGYWanAWxsCiy Assisted-by: Claude Code:claude-fable-5-2 --- crates/socket-patch-core/src/patch/gem_ext.rs | 7 +++++-- crates/socket-patch-core/src/patch/gem_refresh.rs | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/socket-patch-core/src/patch/gem_ext.rs b/crates/socket-patch-core/src/patch/gem_ext.rs index 2b4975d0e..add9e13c4 100644 --- a/crates/socket-patch-core/src/patch/gem_ext.rs +++ b/crates/socket-patch-core/src/patch/gem_ext.rs @@ -2546,10 +2546,13 @@ fn parse_installed(stdout: &str) -> Option<(String, PathBuf)> { /// Nothing of the installed copy is changed. The Ruby is found as for a /// rebuild ([`find_ruby`]): the one whose extension dir for the gem is the /// installed one, so the staged build has the installed build's platform -/// and ABI. `Err` says why there is no staged install to use. +/// and ABI. `kind` says which gem `archive` is, for the build's progress +/// line: `patched`, or `upstream` when `rollback` or `remove` puts that +/// one back (#2152). `Err` says why there is no staged install to use. pub(crate) async fn install_staged( installed: &Path, archive: &Path, + kind: &str, stage_home: &Path, env: &RubyEnv, ) -> Result { @@ -2571,7 +2574,7 @@ pub(crate) async fn install_staged( archive, stage_home, }; - let stdout = run_build(&probe, run, ©, env, "its patched gem").await?; + let stdout = run_build(&probe, run, ©, env, &format!("its {kind} gem")).await?; let (full_name, built) = parse_installed(&stdout) .ok_or_else(|| format!("{}: unreadable install output", probe.ruby.display()))?; let staged = StagedInstall { diff --git a/crates/socket-patch-core/src/patch/gem_refresh.rs b/crates/socket-patch-core/src/patch/gem_refresh.rs index e47b404c6..85cd4321b 100644 --- a/crates/socket-patch-core/src/patch/gem_refresh.rs +++ b/crates/socket-patch-core/src/patch/gem_refresh.rs @@ -437,6 +437,7 @@ async fn refresh_installed( crate::patch::gem_ext::install_staged( &install.gem_dir, &staged_archive, + kind, &stage.join("home"), ruby, ) From e116787f886fc7b5be4e5eef7cf631df135b34e1 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 21:53:01 +0000 Subject: [PATCH 4/4] Tighten the gem refresh label test and docs Review follow-ups: the installed file is reset before each pass, so the second pass also proves the staged install replaced it, and the doc comments name every unwind, not only rollback and remove. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_011f9aeNXZ8oGYWanAWxsCiy Assisted-by: Claude Code:claude-fable-5-2 --- crates/socket-patch-core/src/patch/gem_ext.rs | 6 +++--- crates/socket-patch-core/src/patch/gem_refresh.rs | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/socket-patch-core/src/patch/gem_ext.rs b/crates/socket-patch-core/src/patch/gem_ext.rs index add9e13c4..c72a3e036 100644 --- a/crates/socket-patch-core/src/patch/gem_ext.rs +++ b/crates/socket-patch-core/src/patch/gem_ext.rs @@ -1623,7 +1623,7 @@ fn took(elapsed: Duration) -> String { } /// Run a build of `copy`'s extension (`run`, `from`: "its source gem with -/// the patch applied", "its patched gem"), saying when it starts and how it +/// the patch applied", "its upstream gem"), saying when it starts and how it /// ended /// ([`RubyEnv::progress`]). What the build was worth is the caller's to /// say: one that exits cleanly may still have built nothing of the patch. @@ -2547,8 +2547,8 @@ fn parse_installed(stdout: &str) -> Option<(String, PathBuf)> { /// rebuild ([`find_ruby`]): the one whose extension dir for the gem is the /// installed one, so the staged build has the installed build's platform /// and ABI. `kind` says which gem `archive` is, for the build's progress -/// line: `patched`, or `upstream` when `rollback` or `remove` puts that -/// one back (#2152). `Err` says why there is no staged install to use. +/// line: `patched`, or `upstream` when an unwind puts that one back +/// (#2152). `Err` says why there is no staged install to use. pub(crate) async fn install_staged( installed: &Path, archive: &Path, diff --git a/crates/socket-patch-core/src/patch/gem_refresh.rs b/crates/socket-patch-core/src/patch/gem_refresh.rs index 85cd4321b..fb70463a4 100644 --- a/crates/socket-patch-core/src/patch/gem_refresh.rs +++ b/crates/socket-patch-core/src/patch/gem_refresh.rs @@ -1132,8 +1132,8 @@ mod tests { } /// The progress line of a native gem's staged build names the gem - /// that is built (#2152): `rollback` and `remove` build the upstream - /// gem, and the line said "from its patched gem" for them as well. + /// that is built (#2152): an unwind (`rollback`, `remove`) builds the + /// upstream gem, and the line said "from its patched gem" for it too. #[cfg(unix)] #[tokio::test] async fn a_native_build_names_the_gem_it_builds() { @@ -1198,6 +1198,7 @@ mod tests { ..wanted(&new, &[&source]) }; let targets = [Target::Installed(gem_dir.clone())]; + std::fs::write(gem_dir.join("lib/rack.rb"), "INSTALLED\n").unwrap(); // A sibling test forking while the script was being written // holds its write fd until it execs: ETXTBSY (os error 26). let out = loop {