Skip to content

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

Merged
max-sixty merged 1 commit into
mainfrom
fix/styling-guard-crate-path
Aug 25, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/styling-guard-crate-path

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

check_stderr_macros_come_from_styling tells a contributor to write worktrunk::styling::eprintln!(…). That path resolves in the binary's modules and nowhere else, so pasted into a library module it produces code that cannot compile — and the guard can't catch that, because its scan only checks the call is prefixed with styling::, which both forms satisfy. The compiler is what fails, one CI round later.

The messages now name both paths, from one STYLING_PATH_BY_CRATE const the stdout guard shares. check_no_unexpected_stdout_writes carried the same single-path instruction and gets the same treatment; the module docstring and the STD_STDERR_ALLOWED_PATHS doc follow. The writing-user-outputs skill is the other place the guidance lives, and it also named only worktrunk::styling — one paragraph there now states the split and that the guards accept either form, so the compiler is the only thing that tells you the path is wrong for the file.

This came out of #3884, where the guard fired on src/git/repository/mod.rs, the fix was applied literally, and test (linux) and test (macos) both went red on it.

Verification

src/lib.rs declares cache, command_log, config, copy, docs, git, path, priority, progress, remove_dir, shell, shell_exec, signal_forwarder, styling, sync, trace, utils, testing. src/main.rs declares cli, commands, completion, diagnostic, display, help, invocation, llm, log_files, logging, md_help, output, pager, summary. Both trees are under src/, and both guards scan all of it.

Each message was read by tripping its guard from a library module (a temporary eprintln!/println! in src/priority.rs, reverted):

stderr writes that resolve to std's macro instead of anstream's:

src/priority.rs:250: eprintln!("probe");

std's `eprint!`/`eprintln!` keep ANSI escapes when stderr is redirected, so a
file mixing them with anstream's emits color on some lines of a log and not others.
Import the macro from `styling`, or qualify the call as `styling::eprintln!(…)`.
Spell the path for the crate the file belongs to: `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).
Or add the file to STD_STDERR_ALLOWED_PATHS with a comment explaining why
std's macro is the right one there.

cargo test --test integration -- output_system_guard 5 passed, cargo fmt --check and cargo clippy --tests --features shell-integration-tests clean.

#3878 also touches tests/integration_tests/output_system_guard.rs and is green and merge-ready, so this went to its own branch rather than folding in — the two edit different hunks and whichever merges second may want a trivial rebase.

…violation

The stderr guard's failure message says to write `worktrunk::styling::eprintln!(…)`.
That path resolves only in the binary's modules. Pasted into a library module it
produces code that cannot compile, and neither guard can tell: both accept any
call prefixed with `styling::`, so the scan passes and the compiler is what
fails, one CI round later.
@max-sixty
max-sixty merged commit 617dd0d into main Aug 25, 2026
36 checks passed
@max-sixty
max-sixty deleted the fix/styling-guard-crate-path branch August 25, 2026 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants