Skip to content

Commit 2c3cf81

Browse files
committed
feat(LCHIB-693): Enhance verify command to display organization and workspace names from API response
1 parent c229fd7 commit 2c3cf81

9 files changed

Lines changed: 523 additions & 15 deletions

launchable/test_runners/maven.py

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import glob
22
import os
33
import re
4+
import xml.etree.ElementTree as ET
45
from typing import Dict, List, Optional, Tuple
56

67
import click
@@ -46,6 +47,33 @@ def is_file(f: str) -> bool:
4647
return False
4748

4849

50+
def parse_surefire_reports() -> List[Dict[str, str]]:
51+
"""Parse Maven Surefire XML reports from target/surefire-reports/."""
52+
test_paths = []
53+
report_pattern = '**/target/surefire-reports/TEST-*.xml'
54+
report_files = glob.glob(report_pattern, recursive=True)
55+
56+
if not report_files:
57+
return []
58+
59+
click.echo(f"Found {len(report_files)} surefire report(s)", err=True)
60+
61+
for report_file in report_files:
62+
try:
63+
tree = ET.parse(report_file)
64+
root = tree.getroot()
65+
classname = root.get('name')
66+
67+
if classname:
68+
test_paths.append({"type": "class", "name": classname})
69+
70+
except ET.ParseError as e:
71+
click.secho(f"Warning: Could not parse {report_file}: {e}", fg='yellow', err=True)
72+
73+
click.echo(f"Total tests discovered: {len(test_paths)}", err=True)
74+
return test_paths
75+
76+
4977
@click.option(
5078
'--test-compile-created-file',
5179
'test_compile_created_file',
@@ -61,6 +89,12 @@ def is_file(f: str) -> bool:
6189
is_flag=True,
6290
help="Scan testCompile/default-testCompile/createdFiles.lst for *.lst files generated by `mvn compile` and use them as test inputs.", # noqa: E501
6391
)
92+
@click.option(
93+
'--scan-dryrun-results',
94+
'is_scan_dryrun_results',
95+
is_flag=True,
96+
help="Scan surefire reports generated by mvn test -DdryRun=true",
97+
)
6498
@click.option(
6599
'--exclude',
66100
'exclude_rules',
@@ -70,7 +104,14 @@ def is_file(f: str) -> bool:
70104
)
71105
@click.argument('source_roots', required=False, nargs=-1)
72106
@launchable.subset
73-
def subset(client, source_roots, test_compile_created_file, is_scan_test_compile_lst, exclude_rules: Tuple[str, ...]):
107+
def subset(
108+
client,
109+
source_roots,
110+
test_compile_created_file,
111+
is_scan_test_compile_lst,
112+
is_scan_dryrun_results,
113+
exclude_rules: Tuple[str, ...]
114+
):
74115

75116
# Compile exclude rules
76117
compiled_exclude_rules = []
@@ -100,23 +141,45 @@ def file2test(f: str) -> Optional[List]:
100141
else:
101142
return None
102143

103-
files_to_read = list(test_compile_created_file)
104-
if is_scan_test_compile_lst:
105-
if len(test_compile_created_file) > 0:
106-
click.echo(click.style(
107-
"Warning: --test-compile-created-file is overridden by --scan-test-compile-lst", fg="yellow"),
108-
err=True)
144+
if is_scan_dryrun_results:
145+
click.echo("Scanning Maven dry-run results...", err=True)
146+
tests = parse_surefire_reports()
147+
148+
if not tests:
149+
click.secho(
150+
"Warning: No surefire reports found. Did you run 'mvn test -DdryRun=true'?",
151+
fg='yellow',
152+
err=True
153+
)
154+
click.secho(
155+
"Please run: mvn test -DdryRun=true",
156+
fg='cyan',
157+
err=True
158+
)
159+
return
160+
161+
# Add tests to client (each test path must be a list)
162+
for test in tests:
163+
client.test_paths.append([test])
109164

110-
pattern = os.path.join('**', 'createdFiles.lst')
111-
files_to_read = glob.glob(pattern, recursive=True)
165+
elif is_scan_test_compile_lst or test_compile_created_file:
166+
if is_scan_test_compile_lst:
167+
if len(test_compile_created_file) > 0:
168+
click.echo(click.style(
169+
"Warning: --test-compile-created-file is overridden by --scan-test-compile-lst", fg="yellow"),
170+
err=True)
112171

113-
if not files_to_read:
114-
click.echo(click.style(
115-
"Warning: No .lst files. Please run after executing `mvn test-compile`", fg="yellow"),
116-
err=True)
117-
return
172+
pattern = os.path.join('**', 'createdFiles.lst')
173+
files_to_read = glob.glob(pattern, recursive=True)
174+
175+
if not files_to_read:
176+
click.echo(click.style(
177+
"Warning: No .lst files. Please run after executing `mvn test-compile`", fg="yellow"),
178+
err=True)
179+
return
180+
elif test_compile_created_file:
181+
files_to_read = list(test_compile_created_file)
118182

119-
if files_to_read:
120183
for file in files_to_read:
121184
with open(file, 'r') as f:
122185
lines = f.readlines()
@@ -132,6 +195,7 @@ def file2test(f: str) -> Optional[List]:
132195
path = file2test(l)
133196
if path:
134197
client.test_paths.append(path)
198+
135199
else:
136200
for root in source_roots:
137201
client.scan(root, '**/*', file2test)

tests/data/maven/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Maven Test Data
2+
3+
This directory contains test fixtures for the Maven test runner, including sample Maven Surefire reports used to test the `--scan-dryrun-results` feature.
4+
5+
## Directory Structure
6+
7+
- `dryrun-test/` - Test data for the `--scan-dryrun-results` feature
8+
- `target/surefire-reports/` - Sample Maven Surefire reports (XML and TXT formats)
9+
- `reports/` - Sample test result XML files for various test scenarios
10+
11+
## How to Test Manually with Your Own Project
12+
13+
To manually test the `--scan-dryrun-results` feature with your own Maven project:
14+
15+
```bash
16+
# 1. Navigate to your Maven project
17+
cd /path/to/your/maven-project
18+
19+
# 2. Run Maven dry-run to generate reports
20+
mvn test -DdryRun=true
21+
22+
# 3. Verify reports were created
23+
ls -la target/surefire-reports/TEST-*.xml
24+
25+
# 4. Set up environment (if not already set)
26+
export LAUNCHABLE_TOKEN='v1:your-org/your-workspace:your-actual-token'
27+
28+
# 5. Record build
29+
launchable record build --name 'test-build-name'
30+
31+
# 6. Create a session
32+
launchable record session --build 'test-build-name'
33+
# Copy the session ID from output, e.g., builds/test-build-name/test_sessions/123
34+
35+
# 7. Run subset with --scan-dryrun-results
36+
launchable subset maven \
37+
--scan-dryrun-results \
38+
--session builds/test-build-name/test_sessions/123 \
39+
--target 10%
40+
```
41+
42+
## Creating Test Files for `--scan-dryrun-results`
43+
44+
The test files in `dryrun-test/target/surefire-reports/` are fixtures that simulate Maven Surefire reports generated by running tests with Maven's dry-run mode.
45+
46+
### How to Create/Update These Files
47+
48+
To create or update test fixture files, run Maven tests from within the `dryrun-test` directory:
49+
50+
```bash
51+
cd tests/data/maven/dryrun-test
52+
53+
# Run Maven dry-run to generate Surefire reports
54+
mvn test -DdryRun=true
55+
56+
# The reports will be automatically generated in target/surefire-reports/
57+
# - XML files: TEST-*.xml (detailed test execution results)
58+
# - TXT files: *.txt (summary information for each test class)
59+
```
60+
61+
The generated reports in `target/surefire-reports/` are used directly as test fixtures.
62+
63+
### Purpose
64+
65+
These fixtures are used to test:
66+
- Parsing of Maven Surefire XML reports
67+
- The `--scan-dryrun-results` flag functionality
68+
- Integration with Launchable's subset API
69+
- Handling of filtered/excluded tests

0 commit comments

Comments
 (0)