From 063d78c6a6345ce54de2a53b2da4a9c653dcfbfb Mon Sep 17 00:00:00 2001 From: piquel Date: Fri, 20 Nov 2026 09:34:08 +0100 Subject: [PATCH 1/2] refactor: xtask reads the workspace root directly, and its release test is a table --- tools/xtask/src/main.rs | 5 +---- tools/xtask/src/publish.rs | 2 +- tools/xtask/src/release.rs | 39 +++++++++++++++----------------------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/tools/xtask/src/main.rs b/tools/xtask/src/main.rs index b81a664b6..9694f8193 100644 --- a/tools/xtask/src/main.rs +++ b/tools/xtask/src/main.rs @@ -64,6 +64,7 @@ fn main() -> Result<()> { /// The checkout `cargo xtask` runs in, which may be one of several worktrees. struct Workspace { + /// The checkout's top directory, which every command runs from. root: PathBuf, /// The workspace's crates, as `cargo metadata` describes them. packages: Vec, @@ -107,10 +108,6 @@ impl Workspace { Ok(Self { root, packages }) } - fn root(&self) -> &Path { - &self.root - } - /// The crates published to crates.io: every one without `publish = false`. fn published(&self) -> impl Iterator { self.packages.iter().filter(|package| { diff --git a/tools/xtask/src/publish.rs b/tools/xtask/src/publish.rs index 814f78fa0..4fd081f25 100644 --- a/tools/xtask/src/publish.rs +++ b/tools/xtask/src/publish.rs @@ -100,7 +100,7 @@ impl Publish<'_> { let package = self.workspace.npm_package(None)?; let mut npm = self.workspace.command("npm"); npm.arg("publish") - .current_dir(self.workspace.root().join(NPM_PACKAGE)); + .current_dir(self.workspace.root.join(NPM_PACKAGE)); if self.dry_run { npm.arg("--dry-run"); } else { diff --git a/tools/xtask/src/release.rs b/tools/xtask/src/release.rs index 611230946..56dabc764 100644 --- a/tools/xtask/src/release.rs +++ b/tools/xtask/src/release.rs @@ -37,7 +37,7 @@ impl<'a> Release<'a> { let tag = self.tag(); let notes = self .workspace - .root() + .root .join(format!("target/release-notes-{tag}.md")); // `target` may not exist yet when `CARGO_TARGET_DIR` puts builds elsewhere. if let Some(directory) = notes.parent() { @@ -291,32 +291,23 @@ mod tests { /// Titles go in their type's section without the type, led by their scope. #[test] fn titles_are_grouped_by_type() { - let line = |subject| { - let (section, line) = Section::of(subject); - (section.title(), line) - }; - assert_eq!( - line("feat(sdk): cookie keys accept hex (#502)"), + for (subject, title, line) in [ ( + "feat(sdk): cookie keys accept hex (#502)", "Features", - "**sdk:** cookie keys accept hex (#502)".to_owned() - ) - ); - assert_eq!(line("fix: a fix (#1)"), ("Fixes", "a fix (#1)".to_owned())); - assert_eq!( - line("refactor(auth)!: drop the v1 routes (#2)"), + "**sdk:** cookie keys accept hex (#502)", + ), + ("fix: a fix (#1)", "Fixes", "a fix (#1)"), ( + "refactor(auth)!: drop the v1 routes (#2)", "Breaking changes", - "**auth:** drop the v1 routes (#2)".to_owned() - ) - ); - assert_eq!( - line("add AGENTS.md"), - ("Other changes", "add AGENTS.md".to_owned()) - ); - assert_eq!( - line("Merge: things"), - ("Other changes", "Merge: things".to_owned()) - ); + "**auth:** drop the v1 routes (#2)", + ), + ("add AGENTS.md", "Other changes", "add AGENTS.md"), + ("Merge: things", "Other changes", "Merge: things"), + ] { + let (section, written) = Section::of(subject); + assert_eq!((section.title(), written.as_str()), (title, line)); + } } } From 8e5e1a5f2110dcf9b540985e3c83afaf3d1a0b22 Mon Sep 17 00:00:00 2001 From: piquel Date: Fri, 20 Nov 2026 09:52:51 +0100 Subject: [PATCH 2/2] refactor: the release test names a failing case, and the workspace root's doc says what is relative to it --- tools/xtask/src/main.rs | 2 +- tools/xtask/src/release.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/xtask/src/main.rs b/tools/xtask/src/main.rs index 9694f8193..29e18dcbc 100644 --- a/tools/xtask/src/main.rs +++ b/tools/xtask/src/main.rs @@ -64,7 +64,7 @@ fn main() -> Result<()> { /// The checkout `cargo xtask` runs in, which may be one of several worktrees. struct Workspace { - /// The checkout's top directory, which every command runs from. + /// The checkout's top directory, which commands run from and paths are relative to. root: PathBuf, /// The workspace's crates, as `cargo metadata` describes them. packages: Vec, diff --git a/tools/xtask/src/release.rs b/tools/xtask/src/release.rs index 56dabc764..f84ad1458 100644 --- a/tools/xtask/src/release.rs +++ b/tools/xtask/src/release.rs @@ -307,7 +307,8 @@ mod tests { ("Merge: things", "Other changes", "Merge: things"), ] { let (section, written) = Section::of(subject); - assert_eq!((section.title(), written.as_str()), (title, line)); + let grouped = (section.title(), written.as_str()); + assert_eq!(grouped, (title, line), "{subject}"); } } }