GitHubAnnotationsCommand.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.emit.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.GitHubAnnotationsEmitter;
15
16
/**
17
 * CLI command handler for the {@code -github-annotations} output mode.
18
 *
19
 * <p>
20
 * Scans one or more source roots and emits GitHub Actions {@code ::notice} and
21
 * {@code ::warning} workflow commands for security-relevant test methods.
22
 * </p>
23
 *
24
 * @see org.egothor.methodatlas.emit.GitHubAnnotationsEmitter
25
 * @see SarifCommand
26
 * @see ScanCommand
27
 */
28
public final class GitHubAnnotationsCommand implements Command {
29
30
    private final CliConfig cliConfig;
31
    private final TestDiscoveryConfig discoveryConfig;
32
    private final AiSuggestionEngine aiEngine;
33
    private final ClassificationOverride override;
34
    private final AiResultCache aiCache;
35
    private final ScanOrchestrator scanOrchestrator;
36
37
    /**
38
     * Creates a new GitHub Annotations 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}
43
     *                          when AI is disabled
44
     * @param override          human classification overrides
45
     * @param aiCache           AI result cache
46
     * @param scanOrchestrator  scan-and-emit orchestrator used to process all
47
     *                          configured roots
48
     */
49
    public GitHubAnnotationsCommand(CliConfig cliConfig, TestDiscoveryConfig discoveryConfig,
50
            AiSuggestionEngine aiEngine, ClassificationOverride override,
51
            AiResultCache aiCache, ScanOrchestrator scanOrchestrator) {
52
        this.cliConfig = cliConfig;
53
        this.discoveryConfig = discoveryConfig;
54
        this.aiEngine = aiEngine;
55
        this.override = override;
56
        this.aiCache = aiCache;
57
        this.scanOrchestrator = scanOrchestrator;
58
    }
59
60
    /**
61
     * Scans all roots and emits GitHub Actions workflow commands.
62
     *
63
     * @param out writer that receives the workflow command lines
64
     * @return {@code 0} if all files were processed successfully, {@code 1} if
65
     *         any file produced a parse or processing error
66
     * @throws IOException if traversing a file tree fails
67
     */
68
    @Override
69
    public int execute(PrintWriter out) throws IOException {
70
        boolean confidenceEnabled = cliConfig.aiOptions().confidence();
71 2 1. execute : removed conditional - replaced equality check with false → SURVIVED
2. execute : removed conditional - replaced equality check with true → TIMED_OUT
        List<Path> roots = cliConfig.paths().isEmpty() ? List.of(Paths.get(".")) : cliConfig.paths();
72
        String filePrefix = ContentHasher.filePrefix(roots);
73
        GitHubAnnotationsEmitter emitter = new GitHubAnnotationsEmitter(out, filePrefix);
74 1 1. execute : replaced int return with 0 for org/egothor/methodatlas/command/GitHubAnnotationsCommand::execute → SURVIVED
        return scanOrchestrator.scan(roots, cliConfig, discoveryConfig, aiEngine,
75
                scanOrchestrator.filterSink(emitter, false, cliConfig.minConfidence(), confidenceEnabled),
76
                override, aiCache);
77
    }
78
}

Mutations

71

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 → TIMED_OUT

74

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

Active mutators

Tests examined


Report generated by PIT 1.22.1