SarifCommand.java

1
package org.egothor.methodatlas.command;
2
3
import java.io.IOException;
4
import java.io.PrintWriter;
5
import java.nio.file.Path;
6
import java.nio.file.Paths;
7
import java.util.List;
8
9
import org.egothor.methodatlas.AiResultCache;
10
import org.egothor.methodatlas.ClassificationOverride;
11
import org.egothor.methodatlas.CliConfig;
12
import org.egothor.methodatlas.ai.AiSuggestionEngine;
13
import org.egothor.methodatlas.api.TestDiscoveryConfig;
14
import org.egothor.methodatlas.emit.SarifEmitter;
15
16
/**
17
 * CLI command handler for the {@code -sarif} output mode.
18
 *
19
 * <p>
20
 * Scans one or more source roots, buffers all discovered test-method records,
21
 * and serializes the result as a single SARIF 2.1.0 JSON document once the
22
 * scan completes.
23
 * </p>
24
 *
25
 * @see org.egothor.methodatlas.emit.SarifEmitter
26
 * @see ScanCommand
27
 * @see GitHubAnnotationsCommand
28
 */
29
public final class SarifCommand implements Command {
30
31
    private final CliConfig cliConfig;
32
    private final TestDiscoveryConfig discoveryConfig;
33
    private final AiSuggestionEngine aiEngine;
34
    private final ClassificationOverride override;
35
    private final AiResultCache aiCache;
36
37
    /**
38
     * Creates a new SARIF command.
39
     *
40
     * @param cliConfig       full parsed CLI configuration
41
     * @param discoveryConfig discovery configuration forwarded to providers
42
     * @param aiEngine        AI engine providing suggestions; {@code null} when
43
     *                        AI is disabled
44
     * @param override        human classification overrides
45
     * @param aiCache         AI result cache
46
     */
47
    public SarifCommand(CliConfig cliConfig, TestDiscoveryConfig discoveryConfig,
48
            AiSuggestionEngine aiEngine, ClassificationOverride override,
49
            AiResultCache aiCache) {
50
        this.cliConfig = cliConfig;
51
        this.discoveryConfig = discoveryConfig;
52
        this.aiEngine = aiEngine;
53
        this.override = override;
54
        this.aiCache = aiCache;
55
    }
56
57
    /**
58
     * Scans all roots and emits the buffered result as SARIF JSON.
59
     *
60
     * @param out writer that receives the serialized SARIF document
61
     * @return {@code 0} if all files were processed successfully, {@code 1} if
62
     *         any file produced a parse or processing error
63
     * @throws IOException if traversing a file tree fails
64
     */
65
    @Override
66
    public int execute(PrintWriter out) throws IOException {
67 2 1. execute : removed conditional - replaced equality check with true → SURVIVED
2. execute : removed conditional - replaced equality check with false → SURVIVED
        boolean aiEnabled = aiEngine != null;
68 4 1. execute : removed conditional - replaced equality check with false → NO_COVERAGE
2. execute : removed conditional - replaced equality check with true → NO_COVERAGE
3. execute : removed conditional - replaced equality check with false → SURVIVED
4. execute : removed conditional - replaced equality check with true → SURVIVED
        boolean confidenceEnabled = aiEnabled && cliConfig.aiOptions().confidence();
69 2 1. execute : removed conditional - replaced equality check with false → SURVIVED
2. execute : removed conditional - replaced equality check with true → KILLED
        List<Path> roots = cliConfig.paths().isEmpty() ? List.of(Paths.get(".")) : cliConfig.paths();
70
71
        String filePrefix = CommandSupport.computeFilePrefix(roots);
72 2 1. execute : removed conditional - replaced equality check with false → SURVIVED
2. execute : removed conditional - replaced equality check with true → SURVIVED
        boolean scoresInMessage = !cliConfig.sarifOmitScores();
73
        SarifEmitter sarifEmitter = new SarifEmitter(aiEnabled, confidenceEnabled, filePrefix, scoresInMessage);
74
75
        int result = CommandSupport.scan(roots, cliConfig, discoveryConfig, aiEngine,
76
                CommandSupport.filterSink(sarifEmitter, cliConfig.securityOnly()), override, aiCache);
77 1 1. execute : removed call to org/egothor/methodatlas/emit/SarifEmitter::flush → KILLED
        sarifEmitter.flush(out);
78 1 1. execute : replaced int return with 0 for org/egothor/methodatlas/command/SarifCommand::execute → SURVIVED
        return result;
79
    }
80
}

Mutations

67

1.1
Location : execute
Killed by : none
removed conditional - replaced equality check with true → SURVIVED
Covering tests

2.2
Location : execute
Killed by : none
removed conditional - replaced equality check with false → SURVIVED Covering tests

68

1.1
Location : execute
Killed by : none
removed conditional - replaced equality check with false → NO_COVERAGE

2.2
Location : execute
Killed by : none
removed conditional - replaced equality check with true → NO_COVERAGE

3.3
Location : execute
Killed by : none
removed conditional - replaced equality check with false → SURVIVED
Covering tests

4.4
Location : execute
Killed by : none
removed conditional - replaced equality check with true → SURVIVED Covering tests

69

1.1
Location : execute
Killed by : org.egothor.methodatlas.MethodAtlasAppSarifTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.MethodAtlasAppSarifTest]/[method:sarifMode_resultHasPhysicalAndLogicalLocation(java.nio.file.Path)]
removed conditional - replaced equality check with true → KILLED

2.2
Location : execute
Killed by : none
removed conditional - replaced equality check with false → SURVIVED
Covering tests

72

1.1
Location : execute
Killed by : none
removed conditional - replaced equality check with false → SURVIVED
Covering tests

2.2
Location : execute
Killed by : none
removed conditional - replaced equality check with true → SURVIVED Covering tests

77

1.1
Location : execute
Killed by : org.egothor.methodatlas.MethodAtlasAppSarifTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.MethodAtlasAppSarifTest]/[method:sarifMode_outputIsNotCsvHeader(java.nio.file.Path)]
removed call to org/egothor/methodatlas/emit/SarifEmitter::flush → KILLED

78

1.1
Location : execute
Killed by : none
replaced int return with 0 for org/egothor/methodatlas/command/SarifCommand::execute → SURVIVED
Covering tests

Active mutators

Tests examined


Report generated by PIT 1.22.1