Compare commits

...
Author SHA1 Message Date
Patrick szymkowiak c3416eb45f fix: preserve first line of commit body in git log output
Closes #467

git log now includes %b (body) in the format string and extracts the
first meaningful line (skipping Signed-off-by/Co-authored-by trailers),
displayed indented under the header. This preserves BREAKING CHANGE
notices, Closes references, and design context for LLM agents.

Also fixes resolved_command assertion in test and missing truncate
import in cargo_cmd.rs (both from PR #269 rebase).

Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
2026-03-12 20:26:50 +01:00
patrick szymkowiak 26f5473717 fix: test-all.sh aborts when gt not installed (#500) (#544)
Call skip_test instead of nonexistent skip function, consistent
with all other conditional sections (Python, Go, tree, etc.).

Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
2026-03-12 18:57:52 +01:00
patrick szymkowiak 6e61c2447c fix: remove version check from validate-docs CI (#476) (#543)
Release-please bumps Cargo.toml but not docs, causing the version
grep to fail after every release. The check adds no value since docs
don't need to track the exact patch version.

Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
2026-03-12 18:54:34 +01:00
5 changed files with 72 additions and 41 deletions

No files matched your search

-1
View File
@@ -4,7 +4,6 @@ on:
pull_request:
paths:
- 'src/**/*.rs'
- 'Cargo.toml'
- '**.md'
- '.claude/hooks/*.sh'
push:
+1 -1
View File
@@ -434,7 +434,7 @@ if command -v gt &>/dev/null; then
assert_help "rtk gt" rtk gt --help
assert_ok "rtk gt log short" rtk gt log short
else
skip "gt not installed"
skip_test "rtk gt" "gt not installed"
fi
# ── 30. Global flags ────────────────────────────────
+1 -17
View File
@@ -3,23 +3,7 @@ set -e
echo "🔍 Validating RTK documentation consistency..."
# 1. Version Cargo.toml == tous les fichiers doc
CARGO_VERSION=$(grep '^version = ' Cargo.toml | cut -d'"' -f2)
echo "📦 Cargo.toml version: $CARGO_VERSION"
for file in README.md CLAUDE.md ARCHITECTURE.md; do
if [ ! -f "$file" ]; then
echo "⚠️ $file not found, skipping"
continue
fi
if ! grep -q "$CARGO_VERSION" "$file"; then
echo "❌ $file ne mentionne pas version $CARGO_VERSION"
exit 1
fi
done
echo "✅ Version consistency: all docs mention $CARGO_VERSION"
# 2. Nombre de modules cohérent
# 1. Nombre de modules cohérent
MAIN_MODULES=$(grep -c '^mod ' src/main.rs)
echo "📊 Module count in main.rs: $MAIN_MODULES"
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::tracking;
use crate::utils::resolved_command;
use crate::utils::{resolved_command, truncate};
use anyhow::{Context, Result};
use std::collections::HashMap;
use std::ffi::OsString;
+69 -21
View File
@@ -1,5 +1,5 @@
use crate::tracking;
use crate::utils::{resolved_command, truncate};
use crate::utils::resolved_command;
use anyhow::{Context, Result};
use std::ffi::OsString;
use std::process::Command;
@@ -361,8 +361,10 @@ fn run_log(
});
// Apply RTK defaults only if user didn't specify them
// Use %b (body) to preserve first line of commit body for agent context
// (BREAKING CHANGE, Closes #xxx, design notes)
if !has_format_flag {
cmd.args(["--pretty=format:%h %s (%ar) <%an>"]);
cmd.args(["--pretty=format:%h %s (%ar) <%an>%n%b%n---END---"]);
}
// Determine limit: respect user's explicit -N flag, use sensible defaults otherwise
@@ -468,23 +470,39 @@ fn parse_user_limit(args: &[String]) -> Option<usize> {
/// wider truncation threshold (120 chars) to preserve commit context that LLMs
/// need for rebase/squash operations.
fn filter_log_output(output: &str, limit: usize, user_set_limit: bool) -> String {
let lines: Vec<&str> = output.lines().collect();
let truncate_width = if user_set_limit { 120 } else { 80 };
let iter = lines.iter();
let capped: Vec<String> = if user_set_limit {
// User chose the limit → git already returned the right number of commits
iter.map(|line| truncate_line(line, truncate_width))
.collect()
} else {
// RTK default → cap output lines
iter.take(limit)
.map(|line| truncate_line(line, truncate_width))
.collect()
};
// Split output into commit blocks separated by ---END---
let commits: Vec<&str> = output.split("---END---").collect();
let max_commits = if user_set_limit { commits.len() } else { limit };
capped.join("\n").trim().to_string()
let mut result = Vec::new();
for block in commits.iter().take(max_commits) {
let block = block.trim();
if block.is_empty() {
continue;
}
let mut lines = block.lines();
// First line is the header: hash subject (date) <author>
let header = match lines.next() {
Some(h) => truncate_line(h.trim(), truncate_width),
None => continue,
};
// Remaining lines are the body — keep first non-empty line only
let body_line = lines.map(|l| l.trim()).find(|l| {
!l.is_empty() && !l.starts_with("Signed-off-by:") && !l.starts_with("Co-authored-by:")
});
match body_line {
Some(body) => {
let truncated_body = truncate_line(body, truncate_width);
result.push(format!("{}\n {}", header, truncated_body));
}
None => result.push(header),
}
}
result.join("\n").trim().to_string()
}
/// Truncate a single line to `width` characters, appending "..." if needed
@@ -1451,8 +1469,13 @@ mod tests {
#[test]
fn test_git_cmd_no_global_args() {
let cmd = git_cmd(&[]);
let program = cmd.get_program();
assert_eq!(program, "git");
let program = cmd.get_program().to_string_lossy().to_string();
// resolved_command may return absolute path (e.g. /usr/bin/git)
assert!(
program == "git" || program.ends_with("/git"),
"Expected program to be 'git', got '{}'",
program
);
let args: Vec<_> = cmd.get_args().collect();
assert!(args.is_empty());
}
@@ -1676,13 +1699,38 @@ M file7.rs
#[test]
fn test_filter_log_output() {
let output = "abc1234 This is a commit message (2 days ago) <author>\ndef5678 Another commit (1 week ago) <other>\n";
let output = "abc1234 This is a commit message (2 days ago) <author>\n\n---END---\ndef5678 Another commit (1 week ago) <other>\n\n---END---\n";
let result = filter_log_output(output, 10, false);
assert!(result.contains("abc1234"));
assert!(result.contains("def5678"));
assert_eq!(result.lines().count(), 2);
}
#[test]
fn test_filter_log_output_with_body() {
// Commit with body: first non-trailer body line should appear indented
let output = "abc1234 feat: add feature (2 days ago) <author>\nBREAKING CHANGE: removed old API\nSigned-off-by: Author <a@b.com>\n---END---\ndef5678 fix: typo (1 day ago) <other>\n\n---END---\n";
let result = filter_log_output(output, 10, false);
assert!(result.contains("abc1234"));
assert!(result.contains("BREAKING CHANGE: removed old API"));
assert!(!result.contains("Signed-off-by:"));
// def5678 has no body — just header
assert!(result.contains("def5678"));
// 3 lines: header1, body1 indented, header2
assert_eq!(result.lines().count(), 3);
}
#[test]
fn test_filter_log_output_skips_trailers() {
// Body with only trailers should not produce a body line
let output = "abc1234 chore: bump (1 day ago) <bot>\nSigned-off-by: Bot <bot@ci>\nCo-authored-by: Human <h@b>\n---END---\n";
let result = filter_log_output(output, 10, false);
assert!(result.contains("abc1234"));
assert!(!result.contains("Signed-off-by:"));
assert!(!result.contains("Co-authored-by:"));
assert_eq!(result.lines().count(), 1);
}
#[test]
fn test_filter_log_output_truncate_long() {
let long_line = "abc1234 ".to_string() + &"x".repeat(100) + " (2 days ago) <author>";
@@ -1695,7 +1743,7 @@ M file7.rs
#[test]
fn test_filter_log_output_cap_lines() {
let output = (0..20)
.map(|i| format!("hash{} message {} (1 day ago) <author>", i, i))
.map(|i| format!("hash{} message {} (1 day ago) <author>\n\n---END---", i, i))
.collect::<Vec<_>>()
.join("\n");
let result = filter_log_output(&output, 5, false);
@@ -1706,7 +1754,7 @@ M file7.rs
fn test_filter_log_output_user_limit_no_cap() {
// When user explicitly passes -N, all N lines should be returned (no re-truncation)
let output = (0..20)
.map(|i| format!("hash{} message {} (1 day ago) <author>", i, i))
.map(|i| format!("hash{} message {} (1 day ago) <author>\n\n---END---", i, i))
.collect::<Vec<_>>()
.join("\n");
let result = filter_log_output(&output, 20, true);