Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Port output system check to Rust
Maximilian Roos2b484083da62
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex 77a265f2e..ed1b609ad 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -38,13 +38,6 @@ repos:language: pygreptypes: ["rust"]entry: "dbg!"- - id: check-output-system- name: check-output-system- description: Commands using --internal must use crate::output::* functions- language: script- entry: scripts/check-output-system.sh- pass_filenames: false- files: "^src/commands/(worktree|merge)\\.rs$"ci:# Currently network access isn't supported in the CI product.diff --git a/CLAUDE.md b/CLAUDE.mdindex 064fbb8b0..1b4aad4f2 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -636,7 +636,7 @@ This maintains "one canonical path": commands have ONE code path that works forUsing direct prints bypasses the output system and causes directive leaks - directives become visible to users.-**Restricted files** (see `scripts/check-output-system.sh`):+**Restricted files** (enforced by `tests/output_system_guard.rs`):- `src/commands/worktree.rs` (switch, remove)- `src/commands/merge.rs`@@ -649,7 +649,7 @@ println!("π Starting operation...");crate::output::progress("π Starting operation...")?;```-**Enforcement:** Run `./scripts/check-output-system.sh` to verify compliance. Integration tests catch directive leaks via `tests/integration_tests/shell_wrapper.rs`.+**Enforcement:** The `check_output_system_usage` test (`cargo test check_output_system_usage`) verifies compliance. Integration tests catch directive leaks via `tests/integration_tests/shell_wrapper.rs`.## Command Execution Principlesdiff --git a/scripts/check-output-system.sh b/scripts/check-output-system.shdeleted file mode 100755index a3a900425..000000000--- a/scripts/check-output-system.sh+++ /dev/null@@ -1,55 +0,0 @@-#!/usr/bin/env bash-# Check that commands using --internal mode don't bypass the output system-#-# Commands that support --internal (switch, remove, merge) must use the output-# system (crate::output::*) rather than direct println!/eprintln! calls.-# This prevents directive leaks in shell wrapper integration.--set -euo pipefail--# Files that must use output system (support --internal mode)-RESTRICTED_FILES=(- "src/commands/worktree.rs"- "src/commands/merge.rs"-)--# Allowed exceptions (test code, etc.)-ALLOWED_PATTERNS=(- "spacing_test\.rs"- "command_approval\.rs"-)--exit_code=0--for file in "${RESTRICTED_FILES[@]}"; do- if [[ ! -f "$file" ]]; then- continue- fi-- # Check for direct print!/println!/eprint!/eprintln! usage- while IFS= read -r line; do- # Skip if it matches any allowed pattern- skip=false- for pattern in "${ALLOWED_PATTERNS[@]}"; do- if echo "$line" | grep -q "$pattern"; then- skip=true- break- fi- done-- if [[ "$skip" == "true" ]]; then- continue- fi-- echo "β Direct output in $line"- echo " Commands using --internal must use crate::output::* functions"- echo " Replace print!/println! with output::progress() or output::success()"- exit_code=1- done < <(grep -n "print!\|println!\|eprint!\|eprintln!" "$file" | grep -v "//.*print" || true)-done--if [[ $exit_code -eq 0 ]]; then- echo "β Output system check passed"-fi--exit $exit_codediff --git a/tests/output_system_guard.rs b/tests/output_system_guard.rsnew file mode 100644index 000000000..53869d97f--- /dev/null+++ b/tests/output_system_guard.rs@@ -0,0 +1,53 @@+use std::fs;+use std::path::Path;++#[test]+fn check_output_system_usage() {+ let project_root = env!("CARGO_MANIFEST_DIR");+ let restricted_files = ["src/commands/worktree.rs", "src/commands/merge.rs"];+ let forbidden_tokens = ["print!", "println!", "eprint!", "eprintln!"];+ let allowed_substrings = ["spacing_test.rs", "command_approval.rs"];++ let mut violations = Vec::new();++ for relative_path in restricted_files {+ let full_path = Path::new(project_root).join(relative_path);+ if !full_path.exists() {+ continue;+ }++ let contents = fs::read_to_string(&full_path)+ .unwrap_or_else(|err| panic!("failed to read {}: {err}", relative_path));++ 'line: for (idx, line) in contents.lines().enumerate() {+ for token in forbidden_tokens {+ if let Some(pos) = line.find(token) {+ if allowed_substrings+ .iter()+ .any(|pattern| line.contains(pattern))+ {+ continue 'line;+ }++ if line+ .find("//")+ .map(|comment_pos| comment_pos <= pos)+ .unwrap_or(false)+ {+ continue 'line;+ }++ violations.push(format!("{}:{}: {}", relative_path, idx + 1, line.trim()));+ continue 'line;+ }+ }+ }+ }++ if !violations.is_empty() {+ panic!(+ "Direct output macros found in commands using --internal:\n{}",+ violations.join("\n")+ );+ }+}