Skip to content

Commit 73e2c6a

Browse files
fix(gradle): address PR review — state machine bugs, snapshot tests, 60% threshold
- Fix `* Try:` block leak: skip all lines starting with `>` or `* ` inside block - Fix `in_failed_test` dead reset: remove unreachable empty-line check, reset on `> Task`, `BUILD`, or test summary lines instead - Fix dep tree duplicate BUILD line: check BUILD before pushing as tree node - Raise dependency tree savings threshold from 40% to 60% (project minimum) - Add 6 insta snapshot tests for all filter scenarios - Add `insta` dev-dependency - Remove accidentally committed app.log Signed-off-by: Sebastian Barrozo <sebastian.barrozo@etendo.software> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: sebastianbarrozo <sebastian.barrozo@etendo.software>
1 parent a59fb0a commit 73e2c6a

10 files changed

+189
-16
lines changed

Cargo.lock

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ which = "8"
3838
toml = "0.8"
3939

4040
[dev-dependencies]
41+
insta = "1"
4142

4243
[profile.release]
4344
opt-level = 3

app.log

Whitespace-only changes.

src/gradle_cmd.rs

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,17 @@ pub fn filter_gradle_output(output: &str) -> String {
154154
continue;
155155
}
156156

157-
// === * Try: block ===
157+
// === * Try: block — skip all suggestion lines ===
158158
if trimmed == "* Try:" {
159159
in_try_block = true;
160160
continue;
161161
}
162162
if in_try_block {
163-
if trimmed.starts_with("> Run with") || trimmed.starts_with("> Get more help") {
163+
if trimmed.starts_with('>') || trimmed.starts_with("* ") {
164164
continue;
165165
}
166166
in_try_block = false;
167-
// fall through
167+
// fall through — non-suggestion line ends the block
168168
}
169169

170170
// === TASK LINES ===
@@ -210,9 +210,12 @@ pub fn filter_gradle_output(output: &str) -> String {
210210
}
211211
continue;
212212
}
213-
if trimmed.is_empty() || trimmed.starts_with("> Task") {
213+
if trimmed.starts_with("> Task")
214+
|| trimmed.starts_with("BUILD")
215+
|| trimmed.contains("tests completed")
216+
{
214217
in_failed_test = false;
215-
// fall through
218+
// fall through to process this line
216219
} else {
217220
result.push(line.to_string());
218221
continue;
@@ -263,17 +266,16 @@ pub fn filter_gradle_output(output: &str) -> String {
263266
continue;
264267
}
265268
if in_dep_tree {
266-
// Count tree depth by pipe/space prefix
267-
let depth = count_dep_depth(trimmed);
268-
if depth <= dep_depth_limit {
269-
// Collapse (*) duplicates
270-
let clean = trimmed.replace(" (*)", "");
271-
result.push(clean);
272-
}
273-
if trimmed.is_empty() || trimmed.starts_with("BUILD") {
269+
if trimmed.starts_with("BUILD") {
274270
in_dep_tree = false;
275-
// fall through
271+
// fall through to BUILD summary handler
276272
} else {
273+
// Count tree depth by pipe/space prefix
274+
let depth = count_dep_depth(trimmed);
275+
if depth <= dep_depth_limit {
276+
let clean = trimmed.replace(" (*)", "");
277+
result.push(clean);
278+
}
277279
continue;
278280
}
279281
}
@@ -384,6 +386,7 @@ fn count_dep_depth(line: &str) -> usize {
384386
#[cfg(test)]
385387
mod tests {
386388
use super::*;
389+
use insta::assert_snapshot;
387390

388391
fn count_tokens(text: &str) -> usize {
389392
text.split_whitespace().count()
@@ -841,8 +844,8 @@ BUILD SUCCESSFUL in 45s
841844
let output_tokens = count_tokens(&filtered);
842845
let savings = 100.0 - (output_tokens as f64 / input_tokens as f64 * 100.0);
843846
assert!(
844-
savings >= 40.0,
845-
"Dependency tree should have >=40% savings, got {:.1}%",
847+
savings >= 60.0,
848+
"Dependency tree should have >=60% savings, got {:.1}%",
846849
savings
847850
);
848851
// Should keep top-level deps
@@ -969,4 +972,36 @@ BUILD SUCCESSFUL in 45s
969972
let bin = detect_gradle_binary();
970973
assert_eq!(bin, "gradle");
971974
}
975+
976+
// --- Snapshot tests ---
977+
978+
#[test]
979+
fn test_snapshot_build_success() {
980+
assert_snapshot!(filter_gradle_output(BUILD_SUCCESS));
981+
}
982+
983+
#[test]
984+
fn test_snapshot_build_failed() {
985+
assert_snapshot!(filter_gradle_output(BUILD_FAILED));
986+
}
987+
988+
#[test]
989+
fn test_snapshot_test_failures() {
990+
assert_snapshot!(filter_gradle_output(TEST_FAILURES));
991+
}
992+
993+
#[test]
994+
fn test_snapshot_info_verbose() {
995+
assert_snapshot!(filter_gradle_output(INFO_VERBOSE));
996+
}
997+
998+
#[test]
999+
fn test_snapshot_dependency_tree() {
1000+
assert_snapshot!(filter_gradle_output(DEPENDENCY_TREE));
1001+
}
1002+
1003+
#[test]
1004+
fn test_snapshot_etendo_smartbuild() {
1005+
assert_snapshot!(filter_gradle_output(ETENDO_SMARTBUILD));
1006+
}
9721007
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
source: src/gradle_cmd.rs
3+
expression: filter_gradle_output(BUILD_FAILED)
4+
---
5+
> Task :compileTestJava FAILED
6+
/src/test/java/com/example/UserServiceTest.java:15: error: cannot find symbol
7+
UserService service = new UserService();
8+
^
9+
symbol: class UserService
10+
location: class UserServiceTest
11+
/src/test/java/com/example/UserServiceTest.java:22: error: method create in class UserService cannot be applied to given types;
12+
service.create(user);
13+
^
14+
required: String,String
15+
found: User
16+
1 error
17+
18+
FAILURE: Build failed with an exception.
19+
20+
* What went wrong:
21+
Execution failed for task ':compileTestJava'.
22+
> Compilation failed; see the compiler error output for details.
23+
24+
25+
BUILD FAILED in 5s
26+
3 actionable tasks: 3 executed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: src/gradle_cmd.rs
3+
expression: filter_gradle_output(BUILD_SUCCESS)
4+
---
5+
BUILD SUCCESSFUL in 2s
6+
7 actionable tasks: 7 up-to-date
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: src/gradle_cmd.rs
3+
expression: filter_gradle_output(DEPENDENCY_TREE)
4+
---
5+
compileClasspath - Compile classpath for source set 'main'.
6+
+--- org.springframework.boot:spring-boot-starter-web:3.2.0
7+
| +--- org.springframework.boot:spring-boot-starter:3.2.0
8+
| +--- org.springframework.boot:spring-boot-starter-json:3.2.0
9+
| +--- org.springframework:spring-web:6.1.1
10+
| \--- org.springframework.boot:spring-boot-starter-tomcat:3.2.0
11+
| +--- jakarta.annotation:jakarta.annotation-api:2.1.1
12+
| +--- org.apache.tomcat.embed:tomcat-embed-core:10.1.16
13+
| \--- org.apache.tomcat.embed:tomcat-embed-websocket:10.1.16
14+
+--- org.projectlombok:lombok:1.18.30
15+
\--- com.google.guava:guava:32.1.3-jre
16+
17+
BUILD SUCCESSFUL in 1s
18+
1 actionable task: 1 executed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
source: src/gradle_cmd.rs
3+
expression: filter_gradle_output(ETENDO_SMARTBUILD)
4+
---
5+
[ant:smartbuild] Smartbuild started
6+
[ant:smartbuild] Compiling module com.etendo.mymodule
7+
[ant:smartbuild] Generating entities for module com.etendo.mymodule
8+
[ant:smartbuild] Updating database for module com.etendo.mymodule
9+
[ant:smartbuild] Database updated successfully
10+
[ant:smartbuild] Deploying to tomcat
11+
[ant:smartbuild] Tomcat deployment complete
12+
[ant:smartbuild] Smartbuild completed successfully
13+
14+
BUILD SUCCESSFUL in 45s
15+
12 actionable tasks: 4 executed, 8 up-to-date
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: src/gradle_cmd.rs
3+
expression: filter_gradle_output(INFO_VERBOSE)
4+
---
5+
BUILD SUCCESSFUL in 1s
6+
7 actionable tasks: 7 up-to-date
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
source: src/gradle_cmd.rs
3+
expression: filter_gradle_output(TEST_FAILURES)
4+
---
5+
> Task :test FAILED
6+
7+
com.example.UserServiceTest > testCreate FAILED
8+
java.lang.AssertionError: expected:<200> but was:<404>
9+
at org.junit.Assert.fail(Assert.java:89)
10+
at org.junit.Assert.failNotEquals(Assert.java:835)
11+
at org.junit.Assert.assertEquals(Assert.java:120)
12+
at com.example.UserServiceTest.testCreate(UserServiceTest.java:25)
13+
14+
com.example.OrderTest > testCancel FAILED
15+
java.lang.NullPointerException
16+
at com.example.OrderTest.testCancel(OrderTest.java:42)
17+
18+
19+
4 tests completed, 2 failed
20+
21+
FAILURE: Build failed with an exception.
22+
23+
* What went wrong:
24+
Execution failed for task ':test'.
25+
> There were failing tests. See the report at: file:///build/reports/tests/test/index.html
26+
27+
28+
BUILD FAILED in 8s
29+
5 actionable tasks: 1 executed, 4 up-to-date

0 commit comments

Comments
 (0)