Compare commits

...
Author SHA1 Message Date
Patrick szymkowiak 33b027bce2 chore: add call-site analysis rule to code-reviewer agent
After the git log --oneline regression (PR #546), add a mandatory
review step: trace all callers of modified functions and verify every
input variant has a test. This prevents regressions where a function
is changed but only one code path is tested.

Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
2026-03-16 10:54:40 +01:00
Patrick szymkowiak a81e43d98e fix: git log --oneline regression drops commits
When user passes --oneline, --pretty, or --format, RTK correctly skips
injecting its custom format with ---END--- markers. However,
filter_log_output() still tried to split on ---END---, treating the
entire output as a single block and only preserving 2 lines.

Add user_format parameter to filter_log_output: when true, use simple
line-based truncation instead of ---END--- block splitting.

Fixes regression introduced in PR #546 (commit c3416eb).

Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
2026-03-16 10:51:48 +01:00
2 changed files with 96 additions and 18 deletions

No files matched your search

+29 -4
View File
@@ -32,10 +32,11 @@ main.rs (Commands enum + routing)
## Review Process
1. **Context**: Identify which module changed, what command it affects, token savings claim
2. **Static patterns**: Check for RTK anti-patterns (unwrap, non-lazy regex, async)
3. **Token savings**: Verify savings claim is tested with real fixture
4. **Cross-platform**: Shell escaping, path separators, ANSI codes
5. **Structured feedback**: 🔴 Critical → 🟡 Important → 🟢 Suggestions
2. **Call-site analysis**: Trace ALL callers of modified functions, list every input variant, verify each has a test
3. **Static patterns**: Check for RTK anti-patterns (unwrap, non-lazy regex, async)
4. **Token savings**: Verify savings claim is tested with real fixture
5. **Cross-platform**: Shell escaping, path separators, ANSI codes
6. **Structured feedback**: 🔴 Critical → 🟡 Important → 🟢 Suggestions
## RTK-Specific Red Flags
@@ -198,6 +199,29 @@ fix_here
| 🔴 | file.rs | 45 | lazy_static! |
```
## Call-Site Analysis (🔴 MANDATORY)
When reviewing a function change, **always trace upstream to every call site** and verify that all input variants are tested.
**Why this rule exists:** PR #546 modified `filter_log_output()` to split on `---END---` markers, but only tested the code path where RTK injects those markers. The other path (`--oneline`, `--pretty`, `--format`) never has `---END---` markers — the entire output became a single block, dropping all but 2 commits. This shipped to develop and was only caught during release review.
**Process:**
1. For every modified function, grep all call sites: `Grep pattern="function_name(" type="rust"`
2. For each call site, identify the `if/else` or `match` branch that leads to it
3. List every distinct input shape the function can receive
4. Verify a test exists for EACH input shape — not just the happy path
5. If a test is missing, flag it as 🔴 Critical
**Example (git log):**
```
run_log() has 2 paths:
- has_format_flag=false → injects ---END--- → filter_log_output sees blocks
- has_format_flag=true → no ---END--- → filter_log_output sees raw lines
Both paths MUST have tests.
```
**Rule of thumb:** If a function's caller has an `if/else` that changes the data flowing in, each branch needs its own test in the callee.
## Adversarial Questions for RTK
1. **Savings**: If I run `count_tokens(input)` vs `count_tokens(output)` — is savings ≥60%?
@@ -207,6 +231,7 @@ fix_here
5. **Cross-platform**: Will this regex work on Windows CRLF output?
6. **ANSI**: Does the filter handle ANSI escape codes in input?
7. **Fixture**: Is the test using real output from the actual command?
8. **Call sites**: Have ALL callers been traced? Does each input variant have a test?
## The New Dev Test (RTK variant)
+67 -14
View File
@@ -411,7 +411,7 @@ fn run_log(
}
// Post-process: truncate long messages, cap lines only if RTK set the default
let filtered = filter_log_output(&stdout, limit, user_set_limit);
let filtered = filter_log_output(&stdout, limit, user_set_limit, has_format_flag);
println!("{}", filtered);
timer.track(
@@ -469,10 +469,28 @@ fn parse_user_limit(args: &[String]) -> Option<usize> {
/// so we skip line capping (git already returns exactly N commits) and use a
/// 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 {
fn filter_log_output(
output: &str,
limit: usize,
user_set_limit: bool,
user_format: bool,
) -> String {
let truncate_width = if user_set_limit { 120 } else { 80 };
// Split output into commit blocks separated by ---END---
// When user specified their own format (--oneline, --pretty, --format),
// RTK did not inject ---END--- markers. Use simple line-based truncation.
if user_format {
let lines: Vec<&str> = output.lines().collect();
let max_lines = if user_set_limit { lines.len() } else { limit };
return lines
.iter()
.take(max_lines)
.map(|l| truncate_line(l, truncate_width))
.collect::<Vec<_>>()
.join("\n");
}
// RTK injected format: 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 };
@@ -1701,7 +1719,7 @@ M file7.rs
#[test]
fn test_filter_log_output() {
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);
let result = filter_log_output(output, 10, false, false);
assert!(result.contains("abc1234"));
assert!(result.contains("def5678"));
assert_eq!(result.lines().count(), 2);
@@ -1711,7 +1729,7 @@ M file7.rs
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);
let result = filter_log_output(output, 10, false, false);
assert!(result.contains("abc1234"));
assert!(result.contains("BREAKING CHANGE: removed old API"));
assert!(!result.contains("Signed-off-by:"));
@@ -1725,7 +1743,7 @@ M file7.rs
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);
let result = filter_log_output(output, 10, false, false);
assert!(result.contains("abc1234"));
assert!(!result.contains("Signed-off-by:"));
assert!(!result.contains("Co-authored-by:"));
@@ -1735,7 +1753,7 @@ M file7.rs
#[test]
fn test_filter_log_output_truncate_long() {
let long_line = "abc1234 ".to_string() + &"x".repeat(100) + " (2 days ago) <author>";
let result = filter_log_output(&long_line, 10, false);
let result = filter_log_output(&long_line, 10, false, false);
assert!(result.chars().count() < long_line.chars().count());
assert!(result.contains("..."));
assert!(result.chars().count() <= 80);
@@ -1747,7 +1765,7 @@ M file7.rs
.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);
let result = filter_log_output(&output, 5, false, false);
assert_eq!(result.lines().count(), 5);
}
@@ -1758,7 +1776,7 @@ M file7.rs
.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);
let result = filter_log_output(&output, 20, true, false);
assert_eq!(
result.lines().count(),
20,
@@ -1773,8 +1791,8 @@ M file7.rs
assert!(line_90_chars.chars().count() > 80);
assert!(line_90_chars.chars().count() < 120);
let result_default = filter_log_output(&line_90_chars, 10, false);
let result_user = filter_log_output(&line_90_chars, 10, true);
let result_default = filter_log_output(&line_90_chars, 10, false, false);
let result_user = filter_log_output(&line_90_chars, 10, true, false);
// Default truncates at 80 chars
assert!(
@@ -1833,7 +1851,7 @@ M file7.rs
})
.collect::<Vec<_>>()
.join("\n");
let output = filter_log_output(&input, 10, false);
let output = filter_log_output(&input, 10, false, false);
let savings = 100.0 - (count_tokens(&output) as f64 / count_tokens(&input) as f64 * 100.0);
assert!(
savings >= 60.0,
@@ -1875,7 +1893,7 @@ no changes added to commit (use "git add" and/or "git commit -a")
fn test_filter_log_output_multibyte() {
// Thai characters: each is 3 bytes. A line with >80 bytes but few chars
let thai_msg = format!("abc1234 {} (2 days ago) <author>", "ก".repeat(30));
let result = filter_log_output(&thai_msg, 10, false);
let result = filter_log_output(&thai_msg, 10, false, false);
// Should not panic
assert!(result.contains("abc1234"));
// The line has 30 Thai chars + other text, so > 80 chars total
@@ -1887,7 +1905,7 @@ no changes added to commit (use "git add" and/or "git commit -a")
#[test]
fn test_filter_log_output_emoji() {
let emoji_msg = "abc1234 🎉🎊🎈🎁🎂🎄🎃🎆🎇✨🎉🎊🎈🎁🎂🎄🎃🎆🎇✨ (1 day ago) <user>";
let result = filter_log_output(emoji_msg, 10, false);
let result = filter_log_output(emoji_msg, 10, false, false);
// Should not panic
// 20 emoji + ~30 other chars = ~50 chars < 80, no truncation needed
assert!(result.contains("abc1234"));
@@ -1910,6 +1928,41 @@ no changes added to commit (use "git add" and/or "git commit -a")
assert!(result.contains("📌 main"));
}
/// Regression test: --oneline and other user format flags must preserve all commits.
/// Before fix, filter_log_output split on ---END--- which doesn't exist when
/// the user specifies their own format, resulting in only 2 commits surviving.
#[test]
fn test_filter_log_output_user_format_oneline() {
let oneline_output = "abc1234 feat: add feature\n\
def5678 fix: typo\n\
ghi9012 chore: bump deps\n\
jkl3456 docs: update readme\n\
mno7890 test: add tests\n";
let result = filter_log_output(oneline_output, 10, false, true);
// All 5 lines must survive — no ---END--- splitting
assert_eq!(result.lines().count(), 5);
assert!(result.contains("abc1234"));
assert!(result.contains("mno7890"));
}
#[test]
fn test_filter_log_output_user_format_with_limit() {
let oneline_output = "abc1234 feat: add feature\n\
def5678 fix: typo\n\
ghi9012 chore: bump deps\n\
jkl3456 docs: update readme\n\
mno7890 test: add tests\n";
// user_set_limit=true means respect all lines (no cap)
let result = filter_log_output(oneline_output, 3, true, true);
assert_eq!(result.lines().count(), 5);
// user_set_limit=false means cap at limit
let result = filter_log_output(oneline_output, 3, false, true);
assert_eq!(result.lines().count(), 3);
}
/// Regression test: `git branch <name>` must create, not list.
/// Before fix, positional args fell into list mode which added `-a`,
/// turning creation into a pattern-filtered listing (silent no-op).