Skip to content

Commit 178570d

Browse files
committed
fix: flatten component analysis CLI output to match JS client structure
1 parent 56897d6 commit 178570d

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

  • src
    • main/java/io/github/guacsec/trustifyda/cli
    • test/java/io/github/guacsec/trustifyda/cli

src/main/java/io/github/guacsec/trustifyda/cli/App.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,16 @@ private static CompletableFuture<String> executeComponentAnalysis(
224224
.thenApply(App::extractSummary)
225225
.thenApply(App::toJsonString);
226226
}
227-
return api.componentAnalysisWithLicense(filePath).thenApply(App::toJsonString);
227+
return api.componentAnalysisWithLicense(filePath)
228+
.thenApply(
229+
result -> {
230+
@SuppressWarnings("unchecked")
231+
Map<String, Object> flat = MAPPER.convertValue(result.report(), Map.class);
232+
if (result.licenseSummary() != null) {
233+
flat.put("licenseSummary", result.licenseSummary());
234+
}
235+
return toJsonString(flat);
236+
});
228237
}
229238

230239
private static CompletableFuture<String> executeLicenseCheck(Path manifestPath) {

src/test/java/io/github/guacsec/trustifyda/cli/AppTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,14 @@ void main_with_valid_existing_file_should_work_with_mocked_api() {
616616

617617
// Test with absolute path to pom.xml
618618
String absolutePomPath = System.getProperty("user.dir") + "/pom.xml";
619+
ComponentAnalysisResult mockResult = new ComponentAnalysisResult(mockReport, null);
619620
try (MockedStatic<AppUtils> mockedAppUtils = mockStatic(AppUtils.class);
620621
MockedConstruction<ExhortApi> mockedExhortApi =
621622
mockConstruction(
622623
ExhortApi.class,
623624
(mock, context) -> {
624-
when(mock.componentAnalysis(any(String.class)))
625-
.thenReturn(CompletableFuture.completedFuture(mockReport));
625+
when(mock.componentAnalysisWithLicense(any(String.class)))
626+
.thenReturn(CompletableFuture.completedFuture(mockResult));
626627
})) {
627628

628629
App.main(new String[] {"component", absolutePomPath});
@@ -696,13 +697,14 @@ void main_with_default_json_format_should_work_with_mocked_api() {
696697
}
697698

698699
// Test default JSON format for component command (no format flag)
700+
ComponentAnalysisResult mockResult2 = new ComponentAnalysisResult(mockReport, null);
699701
try (MockedStatic<AppUtils> mockedAppUtils = mockStatic(AppUtils.class);
700702
MockedConstruction<ExhortApi> mockedExhortApi =
701703
mockConstruction(
702704
ExhortApi.class,
703705
(mock, context) -> {
704-
when(mock.componentAnalysis(any(String.class)))
705-
.thenReturn(CompletableFuture.completedFuture(mockReport));
706+
when(mock.componentAnalysisWithLicense(any(String.class)))
707+
.thenReturn(CompletableFuture.completedFuture(mockResult2));
706708
})) {
707709

708710
App.main(new String[] {"component", "pom.xml"});

0 commit comments

Comments
 (0)