Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Add coverage script and column/table tests
Maximilian Roos1d534ed6b5a2
diff --git a/CLAUDE.md b/CLAUDE.mdindex e41785220..61ef357fd 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -179,6 +179,12 @@ assert!(!marker_file.exists(), "Command should NOT have run");Use `--force` to skip interactive prompts in tests. Don't pipe input to stdin.+## Coverage++- Install once: `cargo install cargo-llvm-cov`.+- Run: `./dev/coverage.sh` — runs tests once, then generates HTML (`target/llvm-cov/html/index.html`) and LCOV (`target/llvm-cov/lcov.info`). Set `COVERAGE_OPEN=0` to skip opening the HTML report.+- Pass extra args to the test run (for example to filter tests): `./dev/coverage.sh -- --test test_name`.+## BenchmarksFor detailed benchmark documentation, see `benches/CLAUDE.md`.diff --git a/dev/coverage.sh b/dev/coverage.shnew file mode 100755index 000000000..5562ba96f--- /dev/null+++ b/dev/coverage.sh@@ -0,0 +1,41 @@+#!/usr/bin/env bash+set -euo pipefail++if ! command -v cargo-llvm-cov >/dev/null 2>&1; then+ echo "cargo-llvm-cov is required. Install with: cargo install cargo-llvm-cov" >&2+ exit 1+fi++# Always use the repo's pinned toolchain so llvm-tools are found even if the+# default cargo is a Homebrew build.+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"+TOOLCHAIN="$(awk -F '\"' '/^channel/ {print $2; exit}' "${SCRIPT_DIR}/../rust-toolchain.toml")"+if command -v rustup >/dev/null 2>&1; then+ CARGO_BIN=(rustup run "${TOOLCHAIN}" cargo)+else+ CARGO_BIN=(cargo)+fi++# Ensure LLVM tools are available for coverage instrumentation.+if ! rustup component list --installed | grep -Eq '^llvm-tools(-preview)?'; then+ rustup component add llvm-tools-preview+fi++COVERAGE_DIR="target/llvm-cov"+LCOV_PATH="${COVERAGE_DIR}/lcov.info"+mkdir -p "${COVERAGE_DIR}"++# Run tests once with instrumentation, without generating a report yet.+"${CARGO_BIN[@]}" llvm-cov --locked --workspace --no-report "$@"++# Generate HTML (optionally open) and LCOV reports from the recorded data without rerunning tests.+OPEN_FLAG=()+if [ "${COVERAGE_OPEN:-1}" != "0" ]; then+ OPEN_FLAG=(--open)+fi++"${CARGO_BIN[@]}" llvm-cov report --html --output-dir "${COVERAGE_DIR}/html" "${OPEN_FLAG[@]}"+"${CARGO_BIN[@]}" llvm-cov report --lcov --output-path "${LCOV_PATH}"++echo "HTML report: ${COVERAGE_DIR}/html/index.html"+echo "LCOV report: ${LCOV_PATH}"diff --git a/src/commands/list/columns.rs b/src/commands/list/columns.rsindex f2dd4c066..b6a8060af 100644--- a/src/commands/list/columns.rs+++ b/src/commands/list/columns.rs@@ -107,3 +107,62 @@ pub const COLUMN_SPECS: &[ColumnSpec] = &[11,),];++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn columns_are_ordered_and_unique() {+ let kinds: Vec<ColumnKind> = COLUMN_SPECS.iter().map(|c| c.kind).collect();+ let expected = vec![+ ColumnKind::Gutter,+ ColumnKind::Branch,+ ColumnKind::Status,+ ColumnKind::WorkingDiff,+ ColumnKind::AheadBehind,+ ColumnKind::BranchDiff,+ ColumnKind::Path,+ ColumnKind::Upstream,+ ColumnKind::CiStatus,+ ColumnKind::Commit,+ ColumnKind::Time,+ ColumnKind::Message,+ ];+ assert_eq!(kinds, expected, "column order should match display layout");++ // display_index should match position to keep layout lookups O(1)+ for (idx, spec) in COLUMN_SPECS.iter().enumerate() {+ assert_eq!(+ spec.display_index as usize, idx,+ "display_index must be contiguous"+ );+ }+ }++ #[test]+ fn columns_gate_on_required_tasks() {+ let branch_diff = COLUMN_SPECS+ .iter()+ .find(|c| c.kind == ColumnKind::BranchDiff)+ .unwrap();+ assert_eq!(branch_diff.requires_task, Some(TaskKind::BranchDiff));++ let ci_status = COLUMN_SPECS+ .iter()+ .find(|c| c.kind == ColumnKind::CiStatus)+ .unwrap();+ assert_eq!(ci_status.requires_task, Some(TaskKind::CiStatus));++ // All other columns should not require a background task to render+ for spec in COLUMN_SPECS {+ if spec.kind != ColumnKind::BranchDiff && spec.kind != ColumnKind::CiStatus {+ assert!(+ spec.requires_task.is_none(),+ "{:?} unexpectedly requires a task",+ spec.kind+ );+ }+ }+ }+}diff --git a/src/commands/list/progressive_table.rs b/src/commands/list/progressive_table.rsindex 6a0533c30..d251d16c3 100644--- a/src/commands/list/progressive_table.rs+++ b/src/commands/list/progressive_table.rs@@ -206,3 +206,51 @@ impl ProgressiveTable {self.is_tty}}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn builds_and_updates_rows_without_tty_side_effects() {+ let header = "header".to_string();+ let skeletons = vec!["row0".to_string(), "row1".to_string()];+ let footer = "loading".to_string();++ let mut table =+ ProgressiveTable::new(header.clone(), skeletons.clone(), footer.clone(), 80)+ .expect("table should build");++ // Force non-TTY behavior to avoid cursor control in tests+ table.is_tty = false;++ // header + 2 rows + spacer + footer+ assert_eq!(table.lines.len(), 5);+ assert_eq!(table.lines[0], header);+ assert_eq!(table.lines[1], skeletons[0]);+ assert_eq!(table.lines[2], skeletons[1]);+ assert!(table.lines[3].is_empty(), "spacer should be blank");+ assert_eq!(table.lines[4], footer);++ // No-op when index out of bounds+ table.update_row(5, "ignored".into()).unwrap();++ // Update row content and verify it changed+ table.update_row(1, "row1-updated".into()).unwrap();+ assert_eq!(table.lines[2], "row1-updated");++ // Updating with identical content should be a no-op+ let before = table.lines[2].clone();+ table.update_row(1, before.clone()).unwrap();+ assert_eq!(table.lines[2], before);++ // Footer update+ table.update_footer("done".into()).unwrap();+ assert_eq!(table.lines.last().unwrap(), "done");++ // Finalize non-tty path should just print without panicking+ table+ .finalize_non_tty(vec!["final header".into(), "final row".into()])+ .unwrap();+ }+}