Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

test(guards): name both crate paths when the styling guards report a violation (#3888)

Worktrunk Bot617dd0df1f6c
diff --git a/.claude/skills/writing-user-outputs/SKILL.md b/.claude/skills/writing-user-outputs/SKILL.md
index 067cc6f65..e71878ffd 100644
--- a/.claude/skills/writing-user-outputs/SKILL.md
+++ b/.claude/skills/writing-user-outputs/SKILL.md
@@ -55,6 +55,14 @@ println!("{}", table_output);
stderr().flush()?;
```
+`src/` holds two crates, and the path differs between them: `worktrunk::styling`
+from the binary's modules — the ones `src/main.rs` declares (`commands`, `cli`,
+`display`, …), which the examples throughout this skill are written for — and
+`crate::styling` from the library's, the ones `src/lib.rs` declares (`git`,
+`config`, `shell_exec`, …), where `worktrunk::` does not resolve at all. The
+guard tests accept either, so the compiler is the only thing that tells you the
+path is wrong for the file.
+
Which `println!` is in scope decides whether a closed pipe panics: std's
panics on the `BrokenPipe` write error, anstream's drops it. `wt … | head`
closes the pipe, so command code imports the `worktrunk::styling` one and no
diff --git a/tests/integration_tests/output_system_guard.rs b/tests/integration_tests/output_system_guard.rs
index ec2ba865e..bf9888e1c 100644
--- a/tests/integration_tests/output_system_guard.rs
+++ b/tests/integration_tests/output_system_guard.rs
@@ -16,7 +16,8 @@
//! - `println!` / `print!` in files listed in `STDOUT_ALLOWED_PATHS`
//!
//! When adding stdout output:
-//! - Use `worktrunk::styling::println`. Where the consumer renders the escapes
+//! - Use `styling`'s `println` — `worktrunk::styling` from the binary's modules,
+//! `crate::styling` from the library's. Where the consumer renders the escapes
//! and is never a tty (the statusline, `--help-page`), declare that once at
//! the top of the command with `ColorChoice::Always.write_global()` — the
//! global anstream consults before tty detection — and print normally.
@@ -98,6 +99,16 @@ const ALLOWED_LINE_PATTERNS: &[&str] = &[
r#"println!("Hello, world!");"#,
];
+/// How to name the `styling` module, for a failure message a contributor pastes
+/// straight back into the file that tripped it.
+///
+/// `src/` holds both crates: `src/lib.rs` declares the library's modules (`git`,
+/// `config`, `shell_exec`, …) and `src/main.rs` the binary's (`cli`, `commands`,
+/// `display`, …). `worktrunk::` resolves only in the second, so a message naming
+/// it alone hands a library file code that cannot compile — and neither scan can
+/// catch that, since both accept any call prefixed with `styling::`.
+const STYLING_PATH_BY_CRATE: &str = "`worktrunk::styling` in the binary's modules (the ones `src/main.rs` declares), `crate::styling` in the library's (the ones `src/lib.rs` declares)";
+
/// No file under `src/` writes to stdout unless it is listed as a surface that
/// deliberately does. The scan covers the whole crate rather than just
/// `src/commands/`: `src/help.rs` carries the answer for `--help-page` and
@@ -120,7 +131,8 @@ fn check_no_unexpected_stdout_writes() {
panic!(
"Unexpected stdout writes:\n\n{}\n\n\
stdout is reserved for data output (JSON, tables).\n\
- Use worktrunk::styling::println for stdout, and its eprintln — not color_print's ceprintln! — for stderr.\n\
+ Use the `println` from `styling` for stdout, and its `eprintln` — not color_print's ceprintln! — for stderr.\n\
+ Spell the path for the crate the file belongs to: {STYLING_PATH_BY_CRATE}.\n\
Add file path to STDOUT_ALLOWED_PATHS if stdout is intentional.",
violations.join("\n")
);
@@ -215,8 +227,9 @@ fn check_file(path: &Path, tokens: &[&str], violations: &mut Vec<String>, scan_r
/// Paths (relative to `src/`) allowed to reach std's `eprint!`/`eprintln!`.
///
/// Every other file that writes to stderr must have the macro of that name in
-/// scope from `worktrunk::styling`, or qualify the call — see
-/// [`check_stderr_macros_come_from_styling`].
+/// scope from `styling`, or qualify the call — see
+/// [`check_stderr_macros_come_from_styling`], and [`STYLING_PATH_BY_CRATE`] for
+/// which path spells it from where.
///
/// An entry exempts the **whole file**, not the call its comment names, so an
/// entry added for one narrow site also covers whatever that file grows later.
@@ -292,9 +305,10 @@ fn check_stderr_macros_come_from_styling() {
"stderr writes that resolve to std's macro instead of anstream's:\n\n{}\n\n\
std's `eprint!`/`eprintln!` keep ANSI escapes when stderr is redirected, so a\n\
file mixing them with anstream's emits color on some lines of a log and not others.\n\
- Import the macro from `worktrunk::styling`, qualify the call as\n\
- `worktrunk::styling::eprintln!(…)`, or add the file to STD_STDERR_ALLOWED_PATHS\n\
- with a comment explaining why std's macro is the right one there.",
+ Import the macro from `styling`, or qualify the call as `styling::eprintln!(…)`.\n\
+ Spell the path for the crate the file belongs to: {STYLING_PATH_BY_CRATE}.\n\
+ Or add the file to STD_STDERR_ALLOWED_PATHS with a comment explaining why\n\
+ std's macro is the right one there.",
violations.join("\n")
);
}