From 44fa06620ddc578c86f43e6bfc97837711b754d8 Mon Sep 17 00:00:00 2001 From: Hunter Bown Date: Sat, 9 May 2026 22:37:47 -0500 Subject: [PATCH] fix(test): make CHANGELOG-aware gate robust to packaged-crate runs `changelog_entry_exists_for_current_package_version` reached for `CARGO_MANIFEST_DIR/../../CHANGELOG.md`, which assumes a workspace checkout. Running the test from a packaged crate (no parent workspace) panicked instead of skipping. Walk up from `CARGO_MANIFEST_DIR` looking for `CHANGELOG.md`. Inside the workspace it still finds the top-level file; outside the workspace the gate quietly skips with a printed note instead of panicking. Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/tui/src/prompts.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/tui/src/prompts.rs b/crates/tui/src/prompts.rs index 4650e2e3..aa653b73 100644 --- a/crates/tui/src/prompts.rs +++ b/crates/tui/src/prompts.rs @@ -682,13 +682,32 @@ mod tests { /// `## [X.Y.Z]` heading matching the current `CARGO_PKG_VERSION`. No /// hardcoded version string — the test self-updates with the workspace /// version bump and only fires when the CHANGELOG is the missing piece. + /// + /// Walks up from `CARGO_MANIFEST_DIR` to find `CHANGELOG.md` instead of + /// assuming a fixed `../../CHANGELOG.md` layout. The workspace root is + /// the common case, but the walk also tolerates deeper crate layouts and + /// the packaged-crate case (where the workspace root has been stripped + /// out): if no `CHANGELOG.md` is reachable, the gate quietly skips + /// rather than panicking, so consumers running the suite outside the + /// workspace checkout don't see a spurious failure. #[test] fn changelog_entry_exists_for_current_package_version() { let version = env!("CARGO_PKG_VERSION"); - let changelog_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) - .join("..") - .join("..") - .join("CHANGELOG.md"); + let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")); + let Some(changelog_path) = manifest_dir + .ancestors() + .map(|dir| dir.join("CHANGELOG.md")) + .find(|candidate| candidate.is_file()) + else { + eprintln!( + "changelog_entry_exists_for_current_package_version: no \ + CHANGELOG.md found above {} — skipping (this gate only \ + fires inside a workspace checkout).", + manifest_dir.display() + ); + return; + }; + let contents = std::fs::read_to_string(&changelog_path).unwrap_or_else(|err| { panic!( "failed to read CHANGELOG.md at {}: {err}",