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.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
36
    /**
37
     * Creates a new GitHub Annotations command.
38
     *
39
     * @param cliConfig       full parsed CLI configuration
40
     * @param discoveryConfig discovery configuration forwarded to providers
41
     * @param aiEngine        AI engine providing suggestions; {@code null} when
42
     *                        AI is disabled
43
     * @param override        human classification overrides
44
     * @param aiCache         AI result cache
45
     */
46
    public GitHubAnnotationsCommand(CliConfig cliConfig, TestDiscoveryConfig discoveryConfig,
47
            AiSuggestionEngine aiEngine, ClassificationOverride override,
48
            AiResultCache aiCache) {
49
        this.cliConfig = cliConfig;
50
        this.discoveryConfig = discoveryConfig;
51
        this.aiEngine = aiEngine;
52
        this.override = override;
53
        this.aiCache = aiCache;
54
    }
55
56
    /**
57
     * Scans all roots and emits GitHub Actions workflow commands.
58
     *
59
     * @param out writer that receives the workflow command lines
60
     * @return {@code 0} if all files were processed successfully, {@code 1} if
61
     *         any file produced a parse or processing error
62
     * @throws IOException if traversing a file tree fails
63
     */
64
    @Override
65
    public int execute(PrintWriter out) throws IOException {
66 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();
67
        String filePrefix = CommandSupport.computeFilePrefix(roots);
68
        GitHubAnnotationsEmitter emitter = new GitHubAnnotationsEmitter(out, filePrefix);
69 1 1. execute : replaced int return with 0 for org/egothor/methodatlas/command/GitHubAnnotationsCommand::execute → SURVIVED
        return CommandSupport.scan(roots, cliConfig, discoveryConfig, aiEngine, emitter, override, aiCache);
70
    }
71
}

Mutations

66

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

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

69

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