Skip to content

Commit 13c6f10

Browse files
Add telemetry AI command with full parameter support and tests
1 parent 04b7efb commit 13c6f10

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

src/main/java/com/checkmarx/ast/wrapper/CxConstants.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,13 @@ public final class CxConstants {
8282
static final String SUB_CMD_CONTAINERS_REALTIME = "containers-realtime";
8383
static final String SUB_CMD_MASK = "mask";
8484
static final String RESULT_FILE = "--result-file";
85+
static final String CMD_TELEMETRY = "telemetry";
86+
static final String SUB_CMD_TELEMETRY_AI = "ai";
87+
static final String AI_PROVIDER = "--ai-provider";
88+
static final String TYPE = "--type";
89+
static final String SUB_TYPE = "--sub-type";
90+
static final String PROBLEM_SEVERITY = "--problem-severity";
91+
static final String SCAN_TYPE_FLAG = "--scan-type";
92+
static final String STATUS = "--status";
93+
static final String TOTAL_COUNT = "--total-count";
8594
}

src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,54 @@ public MaskResult maskSecrets(@NonNull String filePath) throws CxException, IOEx
537537
return Execution.executeCommand(withConfigArguments(arguments), logger, MaskResult::fromLine);
538538
}
539539

540+
/**
541+
* Executes telemetry AI command to collect telemetry data for user interactions related to AI features.
542+
*
543+
* @param aiProvider AI provider name (e.g., "Cursor")
544+
* @param agent Agent name
545+
* @param eventType Event type (e.g., "click")
546+
* @param subType Event subtype (e.g., "ast-results.viewPackageDetails")
547+
* @param engine Engine type (e.g., "secrets")
548+
* @param problemSeverity Severity level (e.g., "high")
549+
* @param scanType Type of scan
550+
* @param status Status information
551+
* @param totalCount Number count
552+
* @return Command output as string
553+
* @throws IOException if I/O error occurs
554+
* @throws InterruptedException if command execution is interrupted
555+
* @throws CxException if CLI command fails
556+
*/
557+
public String telemetryAIEvent(String aiProvider, String agent, String eventType, String subType,
558+
String engine, String problemSeverity, String scanType, String status,
559+
Integer totalCount) throws IOException, InterruptedException, CxException {
560+
this.logger.info("Executing telemetry AI event with provider: {}, type: {}, subType: {}",
561+
aiProvider, eventType, subType);
562+
563+
List<String> arguments = new ArrayList<>();
564+
arguments.add(CxConstants.CMD_TELEMETRY);
565+
arguments.add(CxConstants.SUB_CMD_TELEMETRY_AI);
566+
arguments.add(CxConstants.AI_PROVIDER);
567+
arguments.add(aiProvider);
568+
arguments.add(CxConstants.AGENT);
569+
arguments.add(agent);
570+
arguments.add(CxConstants.TYPE);
571+
arguments.add(eventType);
572+
arguments.add(CxConstants.SUB_TYPE);
573+
arguments.add(subType);
574+
arguments.add(CxConstants.ENGINE);
575+
arguments.add(engine);
576+
arguments.add(CxConstants.PROBLEM_SEVERITY);
577+
arguments.add(problemSeverity);
578+
arguments.add(CxConstants.SCAN_TYPE_FLAG);
579+
arguments.add(scanType);
580+
arguments.add(CxConstants.STATUS);
581+
arguments.add(status);
582+
arguments.add(CxConstants.TOTAL_COUNT);
583+
arguments.add(totalCount.toString());
584+
585+
return Execution.executeCommand(withConfigArguments(arguments), logger, line -> line);
586+
}
587+
540588
private int getIndexOfBfLNode(List<Node> bflNodes, List<Node> resultNodes) {
541589

542590
int bflNodeNotFound = -1;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.checkmarx.ast;
2+
3+
import com.checkmarx.ast.wrapper.CxException;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.io.IOException;
8+
9+
/**
10+
* Telemetry AI event test cases covering various parameter scenarios.
11+
*/
12+
class TelemetryTest extends BaseTest {
13+
14+
@Test
15+
void testTelemetryAIEventSuccessfulCaseWithMinimalParametersAiLog() throws CxException, IOException, InterruptedException {
16+
// Test case: AI logging with specific parameters and some empty values
17+
Assertions.assertDoesNotThrow(() -> {
18+
String result = wrapper.telemetryAIEvent(
19+
"Cursor", // aiProvider
20+
"Cursos", // agent
21+
"click", // eventType
22+
"ast-results.viewPackageDetails", // subType
23+
"secrets", // engine
24+
"high", // problemSeverity
25+
"", // scanType (empty)
26+
"", // status (empty)
27+
0 // totalCount
28+
);
29+
}, "Telemetry AI event should execute successfully");
30+
}
31+
32+
@Test
33+
void testTelemetryAIEventSuccessfulCaseWithMinimalParametersDetectionLog() throws CxException, IOException, InterruptedException {
34+
// Test case: Detection logging with most parameters empty and specific scan data
35+
Assertions.assertDoesNotThrow(() -> {
36+
String result = wrapper.telemetryAIEvent(
37+
"", // aiProvider (empty)
38+
"", // agent (empty)
39+
"", // eventType (empty)
40+
"", // subType (empty)
41+
"", // engine (empty)
42+
"", // problemSeverity (empty)
43+
"asca", // scanType
44+
"Critical", // status
45+
10 // totalCount
46+
);
47+
}, "Telemetry AI event should execute successfully for detection log");
48+
}
49+
50+
@Test
51+
void testTelemetryAIEventSuccessfulCaseWithEdgeCaseParameters() throws CxException, IOException, InterruptedException {
52+
// Test case: Edge case with minimal required parameters
53+
Assertions.assertDoesNotThrow(() -> {
54+
String result = wrapper.telemetryAIEvent(
55+
"test-provider", // aiProvider (minimal value)
56+
"java-wrapper", // agent (minimal value)
57+
"", // eventType (empty)
58+
"", // subType (empty)
59+
"", // engine (empty)
60+
"", // problemSeverity (empty)
61+
"", // scanType (empty)
62+
"", // status (empty)
63+
0 // totalCount
64+
);
65+
}, "Telemetry AI event should execute successfully for edge case");
66+
}
67+
}

0 commit comments

Comments
 (0)