GeezerVison is showing github.com — feat: show build environment in all relevant screens (#82) · testlens-app/cli@c95d842
File treeExpand file treeCollapse file tree Open diff view settings main/java/app/testlens/cli test/java/app/testlens/cli
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/FlakesCommand.java +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 19 | 19 | import app.testlens.cli.tui.FlakesTui; | 20 | 20 | import app.testlens.cli.tui.controller.FlakesController; | 21 | 21 | import app.testlens.cli.tui.model.TestInfo; | | 22 | +import app.testlens.cli.util.Console; | 22 | 23 | import java.io.PrintWriter; | 23 | 24 | import java.util.ArrayList; | 24 | 25 | import java.util.List; | @@ -188,6 +189,12 @@ static void printFlakes( | 188 | 189 | .stream() | 189 | 190 | .sorted(comparing(TestExecutionResponse::getStartTime)) | 190 | 191 | .toList(); | | 192 | + var environment = executions.isEmpty() | | 193 | + ? null | | 194 | + : Console.environment(executions.getFirst().getBuildEnvironment()); | | 195 | + if (environment != null) { | | 196 | + out.println(" " + styled(ansi, environment, Style.faint)); | | 197 | + } | 191 | 198 | for (int j = 0; j < executions.size(); j++) { | 192 | 199 | TestCommand.printExecution(out, ansi, " ", j + 1, executions.get(j), false); | 193 | 200 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/PrCommand.java +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 20 | 20 | import app.testlens.cli.client.model.PullRequestResponse; | 21 | 21 | import app.testlens.cli.client.model.PullRequestTestsResponse; | 22 | 22 | import app.testlens.cli.tui.PrTui; | | 23 | +import app.testlens.cli.util.Console; | 23 | 24 | import app.testlens.cli.util.TextDiff; | 24 | 25 | import app.testlens.cli.util.TimeFormat; | 25 | 26 | import java.io.PrintWriter; | @@ -190,6 +191,10 @@ private static void printTests(PrintWriter out, Ansi ansi, PullRequestTestsRespo | 190 | 191 | + TimeFormat.formatTime(execution.getStartTime(), execution.getDurationMillis()) + ", see " | 191 | 192 | + jobLink + ")" | 192 | 193 | ); | | 194 | + var environment = Console.environment(execution.getBuildEnvironment()); | | 195 | + if (environment != null) { | | 196 | + out.println(" " + styled(ansi, environment, Style.faint)); | | 197 | + } | 193 | 198 | TextDiff.diff(execution.getComparisonFailure()) | 194 | 199 | .ifPresent(diff -> diff.forEach(line -> out.println(" " + diffLine(ansi, line)))); | 195 | 200 | var stackTrace = execution.getStackTrace(); | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/TestCommand.java +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 | import app.testlens.cli.client.model.TestResponse; | 19 | 19 | import app.testlens.cli.tui.TestExecutionsTui; | 20 | 20 | import app.testlens.cli.tui.model.TestInfo; | | 21 | +import app.testlens.cli.util.Console; | 21 | 22 | import app.testlens.cli.util.TextDiff; | 22 | 23 | import app.testlens.cli.util.TimeFormat; | 23 | 24 | import java.util.List; | @@ -282,6 +283,10 @@ static void printExecution( | 282 | 283 | Style.faint | 283 | 284 | ) | 284 | 285 | ); | | 286 | + var environment = Console.environment(execution.getBuildEnvironment()); | | 287 | + if (environment != null) { | | 288 | + out.println(detailIndent + styled(ansi, environment, Style.faint)); | | 289 | + } | 285 | 290 | } | 286 | 291 | TextDiff.diff(execution.getComparisonFailure()) | 287 | 292 | .ifPresent(diff -> diff.forEach(line -> out.println(detailIndent + diffLine(ansi, line)))); | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/tui/controller/FlakesController.java +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -72,7 +72,8 @@ private static Execution toExecution(TestExecutionResponse execution) { | 72 | 72 | .durationMillis(execution.getDurationMillis()) | 73 | 73 | .htmlUrl(Objects.requireNonNullElse(execution.getHtmlUrl(), "")) | 74 | 74 | .stackTrace(execution.getStackTrace()) | 75 | | - .comparisonFailure(execution.getComparisonFailure()); | | 75 | + .comparisonFailure(execution.getComparisonFailure()) | | 76 | + .buildEnvironment(execution.getBuildEnvironment()); | 76 | 77 | } | 77 | 78 |
| 78 | 79 | public static String abbreviatedSha(String sha) { | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/tui/view/ExecutionsView.java +20-3Lines changed: 20 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 20 | 20 | import app.testlens.cli.tui.ScreenRouter; | 21 | 21 | import app.testlens.cli.tui.controller.ExecutionsController; | 22 | 22 | import app.testlens.cli.tui.model.ExecutionsModel; | | 23 | +import app.testlens.cli.util.Console; | 23 | 24 | import app.testlens.cli.util.TimeFormat; | 24 | 25 | import dev.tamboui.layout.Constraint; | 25 | 26 | import dev.tamboui.layout.Rect; | @@ -307,7 +308,7 @@ private void sync() { | 307 | 308 | private Element details() { | 308 | 309 | return panel( | 309 | 310 | widthAware( | 310 | | - Constraint.length(DETAILS_HEADER_HEIGHT), | | 311 | + Constraint.length(detailsHeaderHeight()), | 311 | 312 | width -> richText(detailsHeader(width)).ellipsis() | 312 | 313 | ), | 313 | 314 | detailsArea.fill() | @@ -317,12 +318,24 @@ private Element details() { | 317 | 318 | .fill(); | 318 | 319 | } | 319 | 320 |
| | 321 | + // one line per detail, plus the optional environment line | | 322 | + private int detailsHeaderHeight() { | | 323 | + var execution = selectedExecution(); | | 324 | + return DETAILS_HEADER_HEIGHT | | 325 | + + (execution != null && Console.environment(execution.getBuildEnvironment()) != null ? 1 : 0); | | 326 | + } | | 327 | + | | 328 | + private @Nullable TestExecutionResponse selectedExecution() { | | 329 | + var snapshot = model.snapshot(); | | 330 | + return snapshot.executions().isEmpty() ? null : snapshot.executions().get(snapshot.executionIndex()); | | 331 | + } | | 332 | + | 320 | 333 | private Text detailsHeader(int width) { | 321 | | - if (model.executions().isEmpty()) { | | 334 | + var execution = selectedExecution(); | | 335 | + if (execution == null) { | 322 | 336 | return Text.from(List.of(Line.from(""))); | 323 | 337 | } | 324 | 338 | var snapshot = model.snapshot(); | 325 | | - var execution = snapshot.executions().get(snapshot.executionIndex()); | 326 | 339 | var valueWidth = Math.max(width - DETAILS_LABEL_WIDTH, 0); | 327 | 340 | var lines = new ArrayList<Line>(); | 328 | 341 | lines.add( | @@ -352,6 +365,10 @@ private Text detailsHeader(int width) { | 352 | 365 | ) | 353 | 366 | ); | 354 | 367 | } | | 368 | + var environment = Console.environment(execution.getBuildEnvironment()); | | 369 | + if (environment != null) { | | 370 | + lines.add(valueLine("Env: ", environment, valueWidth)); | | 371 | + } | 355 | 372 | return Text.from(lines); | 356 | 373 | } | 357 | 374 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/tui/view/FlakeDetailsView.java +28-16Lines changed: 28 additions & 16 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | import app.testlens.cli.client.model.Execution; | 7 | 7 | import app.testlens.cli.tui.controller.PrDetailsController; | 8 | 8 | import app.testlens.cli.tui.model.PrTuiModel; | | 9 | +import app.testlens.cli.util.Console; | 9 | 10 | import app.testlens.cli.util.TimeFormat; | 10 | 11 | import dev.tamboui.style.Style; | 11 | 12 | import dev.tamboui.text.Line; | 12 | 13 | import dev.tamboui.text.Span; | 13 | 14 | import dev.tamboui.text.Text; | 14 | 15 | import dev.tamboui.toolkit.element.Element; | 15 | | -import java.util.List; | | 16 | +import java.util.ArrayList; | | 17 | +import org.jspecify.annotations.Nullable; | 16 | 18 |
| 17 | 19 | /** | 18 | 20 | * The details pane of the flakes screen: the shared execution tabs, in chronological order, with time and job only. | @@ -29,30 +31,40 @@ public FlakeDetailsView(PrDetailsController controller, PrTuiModel model) { | 29 | 31 | this.pane = new ExecutionTabsPane( | 30 | 32 | controller, | 31 | 33 | model, | 32 | | - (test, execution) -> richText(detailsHeader(execution)).ellipsis().length(DETAILS_HEADER_HEIGHT) | | 34 | + (test, execution) -> { | | 35 | + var environment = Console.environment(execution.getBuildEnvironment()); | | 36 | + return richText(detailsHeader(execution, environment)) | | 37 | + .ellipsis() | | 38 | + .length(DETAILS_HEADER_HEIGHT + (environment == null ? 0 : 1)); | | 39 | + } | 33 | 40 | ); | 34 | 41 | } | 35 | 42 |
| 36 | 43 | public Element render() { | 37 | 44 | return pane.render(); | 38 | 45 | } | 39 | 46 |
| 40 | | - private static Text detailsHeader(Execution execution) { | | 47 | + private static Text detailsHeader(Execution execution, @Nullable String environment) { | 41 | 48 | var htmlUrl = execution.getHtmlUrl(); | 42 | | - return Text.from( | 43 | | - List.of( | 44 | | - Line.from( | 45 | | - Span.raw("Time: "), | 46 | | - Span.raw(TimeFormat.formatTime(execution.getStartTime(), execution.getDurationMillis())) | 47 | | - ), | 48 | | - Line.from( | 49 | | - Span.raw("Job: "), | 50 | | - // a missing job URL is mapped to an empty one | 51 | | - htmlUrl.isEmpty() | 52 | | - ? Span.raw("-") | 53 | | - : Span.styled(htmlUrl, Style.EMPTY.underlined().hyperlink(htmlUrl)) | 54 | | - ) | | 49 | + var lines = new ArrayList<Line>(); | | 50 | + lines.add( | | 51 | + Line.from( | | 52 | + Span.raw("Time: "), | | 53 | + Span.raw(TimeFormat.formatTime(execution.getStartTime(), execution.getDurationMillis())) | 55 | 54 | ) | 56 | 55 | ); | | 56 | + lines.add( | | 57 | + Line.from( | | 58 | + Span.raw("Job: "), | | 59 | + // a missing job URL is mapped to an empty one | | 60 | + htmlUrl.isEmpty() | | 61 | + ? Span.raw("-") | | 62 | + : Span.styled(htmlUrl, Style.EMPTY.underlined().hyperlink(htmlUrl)) | | 63 | + ) | | 64 | + ); | | 65 | + if (environment != null) { | | 66 | + lines.add(Line.from(Span.raw("Env: "), Span.raw(environment))); | | 67 | + } | | 68 | + return Text.from(lines); | 57 | 69 | } | 58 | 70 | } |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/tui/view/PrDetailsView.java +33-21Lines changed: 33 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | import app.testlens.cli.client.model.Execution; | 9 | 9 | import app.testlens.cli.tui.controller.PrDetailsController; | 10 | 10 | import app.testlens.cli.tui.model.PrTuiModel; | | 11 | +import app.testlens.cli.util.Console; | 11 | 12 | import app.testlens.cli.util.TimeFormat; | 12 | 13 | import dev.tamboui.layout.Constraint; | 13 | 14 | import dev.tamboui.layout.Rect; | | 20 | 21 | import dev.tamboui.toolkit.element.Element; | 21 | 22 | import dev.tamboui.toolkit.element.RenderContext; | 22 | 23 | import dev.tamboui.toolkit.element.Size; | 23 | | -import java.util.List; | | 24 | +import java.util.ArrayList; | 24 | 25 | import java.util.function.IntFunction; | | 26 | +import org.jspecify.annotations.Nullable; | 25 | 27 |
| 26 | 28 | /** The details pane of the PR screen: the shared execution tabs with the test, its location, time and job. */ | 27 | 29 | public final class PrDetailsView { | @@ -35,10 +37,13 @@ public PrDetailsView(PrDetailsController controller, PrTuiModel model) { | 35 | 37 | this.pane = new ExecutionTabsPane( | 36 | 38 | controller, | 37 | 39 | model, | 38 | | - (test, execution) -> widthAware( | 39 | | - Constraint.length(DETAILS_HEADER_HEIGHT), | 40 | | - width -> richText(detailsHeader(test, execution, width)).ellipsis() | 41 | | - ) | | 40 | + (test, execution) -> { | | 41 | + var environment = Console.environment(execution.getBuildEnvironment()); | | 42 | + return widthAware( | | 43 | + Constraint.length(DETAILS_HEADER_HEIGHT + (environment == null ? 0 : 1)), | | 44 | + width -> richText(detailsHeader(test, execution, environment, width)).ellipsis() | | 45 | + ); | | 46 | + } | 42 | 47 | ); | 43 | 48 | } | 44 | 49 |
| @@ -50,24 +55,31 @@ public Element render() { | 50 | 55 | return pane.render(); | 51 | 56 | } | 52 | 57 |
| 53 | | - private static Text detailsHeader(ExecutedTest test, Execution execution, int width) { | 54 | | - return Text.from( | 55 | | - List.of( | 56 | | - Line.from( | 57 | | - Span.raw("Test: "), | 58 | | - Span.raw(abbreviatedTestName(test.getDisplayNames(), width - DETAILS_LABEL_WIDTH)) | 59 | | - ), | 60 | | - Line.from(Span.raw("Where: "), Span.raw(test.getJob() + " > " + test.getWorkUnit())), | 61 | | - Line.from( | 62 | | - Span.raw("Time: "), | 63 | | - Span.raw(TimeFormat.formatTime(execution.getStartTime(), execution.getDurationMillis())) | 64 | | - ), | 65 | | - Line.from( | 66 | | - Span.raw("Job: "), | 67 | | - Span.styled(execution.getHtmlUrl(), Style.EMPTY.underlined().hyperlink(execution.getHtmlUrl())) | 68 | | - ) | | 58 | + private static Text detailsHeader(ExecutedTest test, Execution execution, @Nullable String environment, int width) { | | 59 | + var lines = new ArrayList<Line>(); | | 60 | + lines.add( | | 61 | + Line.from( | | 62 | + Span.raw("Test: "), | | 63 | + Span.raw(abbreviatedTestName(test.getDisplayNames(), width - DETAILS_LABEL_WIDTH)) | | 64 | + ) | | 65 | + ); | | 66 | + lines.add(Line.from(Span.raw("Where: "), Span.raw(test.getJob() + " > " + test.getWorkUnit()))); | | 67 | + lines.add( | | 68 | + Line.from( | | 69 | + Span.raw("Time: "), | | 70 | + Span.raw(TimeFormat.formatTime(execution.getStartTime(), execution.getDurationMillis())) | | 71 | + ) | | 72 | + ); | | 73 | + lines.add( | | 74 | + Line.from( | | 75 | + Span.raw("Job: "), | | 76 | + Span.styled(execution.getHtmlUrl(), Style.EMPTY.underlined().hyperlink(execution.getHtmlUrl())) | 69 | 77 | ) | 70 | 78 | ); | | 79 | + if (environment != null) { | | 80 | + lines.add(Line.from(Span.raw("Env: "), Span.raw(environment))); | | 81 | + } | | 82 | + return Text.from(lines); | 71 | 83 | } | 72 | 84 |
| 73 | 85 | private static Element widthAware(Constraint constraint, IntFunction<Element> factory) { | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/app/testlens/cli/util/Console.java +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | // SPDX-License-Identifier: Apache-2.0 | 2 | 2 | package app.testlens.cli.util; | 3 | 3 |
| | 4 | +import app.testlens.cli.client.model.BuildEnvironment; | 4 | 5 | import app.testlens.cli.util.TextDiff.DiffLine; | 5 | 6 | import java.io.PrintWriter; | | 7 | +import java.util.Objects; | | 8 | +import java.util.stream.Collectors; | | 9 | +import java.util.stream.Stream; | | 10 | +import org.jspecify.annotations.Nullable; | 6 | 11 | import picocli.CommandLine.Help.Ansi; | 7 | 12 | import picocli.CommandLine.Help.Ansi.IStyle; | 8 | 13 |
| @@ -11,6 +16,28 @@ public final class Console { | 11 | 16 |
| 12 | 17 | private Console() {} | 13 | 18 |
| | 19 | + /** | | 20 | + * Human-readable build environment, e.g. {@code "Linux 6.8.0-45-generic · amd64 · Java 21.0.5"}; {@code null} | | 21 | + * without any data, so callers can omit the environment instead of printing placeholders. | | 22 | + */ | | 23 | + public static @Nullable String environment(@Nullable BuildEnvironment environment) { | | 24 | + if (environment == null) { | | 25 | + return null; | | 26 | + } | | 27 | + var os = Stream.of(environment.getOsName(), environment.getOsVersion()) | | 28 | + .filter(Objects::nonNull) | | 29 | + .collect(Collectors.joining(" ")); | | 30 | + var parts = Stream | | 31 | + .of( | | 32 | + os.isEmpty() ? null : os, | | 33 | + environment.getOsArch(), | | 34 | + environment.getJavaVersion() == null ? null : "Java " + environment.getJavaVersion() | | 35 | + ) | | 36 | + .filter(Objects::nonNull) | | 37 | + .toList(); | | 38 | + return parts.isEmpty() ? null : String.join(" · ", parts); | | 39 | + } | | 40 | + | 14 | 41 | public static String styled(Ansi ansi, String text, IStyle... styles) { | 15 | 42 | return ansi.enabled() ? Ansi.Style.on(styles) + text + Ansi.Style.reset.on() : text; | 16 | 43 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/test/java/app/testlens/cli/FlakesCommandTest.java +37Lines changed: 37 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | import static org.assertj.core.api.Assertions.assertThat; | 12 | 12 |
| 13 | 13 | import app.testlens.cli.client.ApiClient; | | 14 | +import app.testlens.cli.client.model.BuildEnvironment; | 14 | 15 | import app.testlens.cli.client.model.FlakeResponse; | 15 | 16 | import app.testlens.cli.client.model.Link; | 16 | 17 | import app.testlens.cli.client.model.TestExecutionResponse; | @@ -35,6 +36,12 @@ class FlakesCommandTest { | 35 | 36 |
| 36 | 37 | private static final ObjectMapper OBJECT_MAPPER = ApiClient.createDefaultObjectMapper(); | 37 | 38 |
| | 39 | + private static final BuildEnvironment ENVIRONMENT = new BuildEnvironment() | | 40 | + .osName("Linux") | | 41 | + .osVersion("6.8.0-45-generic") | | 42 | + .osArch("amd64") | | 43 | + .javaVersion("21.0.5"); | | 44 | + | 38 | 45 | @RegisterExtension | 39 | 46 | static WireMockExtension wireMock = WireMockExtension.newInstance() | 40 | 47 | .options(wireMockConfig().dynamicPort()) | @@ -80,6 +87,36 @@ void prints_flakes_with_executions_in_chronological_order() { | 80 | 87 | ); | 81 | 88 | } | 82 | 89 |
| | 90 | + @Test | | 91 | + void prints_the_build_environment_of_each_flake() { | | 92 | + stubTest(); | | 93 | + var flake = flake("0123456789", ":core:test").job("CI / build"); | | 94 | + flake.executions( | | 95 | + flake | | 96 | + .getExecutions() | | 97 | + .stream() | | 98 | + .map(execution -> execution.buildEnvironment(ENVIRONMENT)) | | 99 | + .toList() | | 100 | + ); | | 101 | + wireMock.stubFor(get(urlPathEqualTo(FLAKES_PATH)).willReturn(json(List.of(flake)))); | | 102 | + | | 103 | + var result = | | 104 | + run("flakes", "1729", "--repo", REPO, "--token", "good", "--mode=cli", "--base-url", wireMock.baseUrl()); | | 105 | + | | 106 | + assertThat(result.exitCode()).isZero(); | | 107 | + assertThat(result.stdout().lines()).containsExactly( | | 108 | + "NetworkTests > connects() (test 1729)", | | 109 | + " [engine:junit-jupiter]/[class:NetworkTests]/[method:connects()]", | | 110 | + " newest flake first, executions in chronological order", | | 111 | + "", | | 112 | + " 1. 0123456 @ main · :core:test · CI / build", | | 113 | + " Linux 6.8.0-45-generic · amd64 · Java 21.0.5", | | 114 | + " 1. FAILED (2026-01-02 03:04:05Z - 03:04:07Z (2s), see " + JOB_URL + ")", | | 115 | + " java.lang.AssertionError: boom", | | 116 | + " 2. SUCCESSFUL (2026-01-02 04:04:05Z - 04:04:07Z (2s))" | | 117 | + ); | | 118 | + } | | 119 | + | 83 | 120 | @Test | 84 | 121 | void follows_pagination() { | 85 | 122 | stubTest(); | |
|