CredentialTriageContext.java

1
package org.egothor.methodatlas.command;
2
3
import java.util.HashMap;
4
import java.util.List;
5
import java.util.Map;
6
7
import org.egothor.methodatlas.ai.PromptBuilder;
8
import org.egothor.methodatlas.ai.CredentialTriageVerdict;
9
10
/**
11
 * Carries the per-class credential candidates into the scan loop and collects the
12
 * triage verdicts the AI returns, so classification and credential triage share a
13
 * single per-class provider call — the class source is transmitted only once.
14
 *
15
 * <p>
16
 * Populated up-front by the credential-detection pass (candidates keyed by fully
17
 * qualified class name, in finding order) and mutated during the single-threaded
18
 * discovery loop as each class is classified. Not thread-safe; the scan loop is
19
 * single-threaded.
20
 * </p>
21
 *
22
 * @since 4.1.0
23
 */
24
final class CredentialTriageContext {
25
26
    private final Map<String, List<PromptBuilder.CredentialCandidateRef>> candidatesByFqcn;
27
    private final Map<String, List<CredentialTriageVerdict>> verdictsByFqcn = new HashMap<>();
28
29
    /**
30
     * Creates a context for the supplied candidates.
31
     *
32
     * @param candidatesByFqcn candidate spans per class, in finding order; never {@code null}
33
     */
34
    /* default */ CredentialTriageContext(Map<String, List<PromptBuilder.CredentialCandidateRef>> candidatesByFqcn) {
35
        this.candidatesByFqcn = Map.copyOf(candidatesByFqcn);
36
    }
37
38
    /**
39
     * Returns the candidates for a class, or an empty list when none were detected.
40
     *
41
     * @param fqcn fully qualified class name
42
     * @return candidate spans for the class; never {@code null}
43
     */
44
    /* default */ List<PromptBuilder.CredentialCandidateRef> candidatesFor(String fqcn) {
45 1 1. candidatesFor : replaced return value with Collections.emptyList for org/egothor/methodatlas/command/CredentialTriageContext::candidatesFor → KILLED
        return candidatesByFqcn.getOrDefault(fqcn, List.of());
46
    }
47
48
    /**
49
     * Records the triage verdicts returned for a class.
50
     *
51
     * @param fqcn     fully qualified class name
52
     * @param verdicts verdicts from the folded AI call; ignored when {@code null}/empty
53
     */
54
    /* default */ void recordVerdicts(String fqcn, List<CredentialTriageVerdict> verdicts) {
55 4 1. recordVerdicts : removed conditional - replaced equality check with true → SURVIVED
2. recordVerdicts : removed conditional - replaced equality check with true → SURVIVED
3. recordVerdicts : removed conditional - replaced equality check with false → KILLED
4. recordVerdicts : removed conditional - replaced equality check with false → KILLED
        if (verdicts != null && !verdicts.isEmpty()) {
56
            verdictsByFqcn.put(fqcn, verdicts);
57
        }
58
    }
59
60
    /**
61
     * Returns the collected verdicts keyed by class.
62
     *
63
     * @return verdicts per class; never {@code null}
64
     */
65
    /* default */ Map<String, List<CredentialTriageVerdict>> verdictsByFqcn() {
66 1 1. verdictsByFqcn : replaced return value with Collections.emptyMap for org/egothor/methodatlas/command/CredentialTriageContext::verdictsByFqcn → KILLED
        return verdictsByFqcn;
67
    }
68
}

Mutations

45

1.1
Location : candidatesFor
Killed by : org.egothor.methodatlas.command.ScanOrchestratorCacheTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.command.ScanOrchestratorCacheTest]/[method:cacheMiss_runsCombinedClassificationAndRecordsVerdicts(java.nio.file.Path)]
replaced return value with Collections.emptyList for org/egothor/methodatlas/command/CredentialTriageContext::candidatesFor → KILLED

55

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

2.2
Location : recordVerdicts
Killed by : org.egothor.methodatlas.command.ScanOrchestratorCacheTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.command.ScanOrchestratorCacheTest]/[method:cacheMiss_runsCombinedClassificationAndRecordsVerdicts(java.nio.file.Path)]
removed conditional - replaced equality check with false → KILLED

3.3
Location : recordVerdicts
Killed by : org.egothor.methodatlas.command.ScanOrchestratorCacheTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.command.ScanOrchestratorCacheTest]/[method:cacheMiss_runsCombinedClassificationAndRecordsVerdicts(java.nio.file.Path)]
removed conditional - replaced equality check with false → KILLED

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

66

1.1
Location : verdictsByFqcn
Killed by : org.egothor.methodatlas.command.ScanOrchestratorCacheTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.command.ScanOrchestratorCacheTest]/[method:cacheMiss_runsCombinedClassificationAndRecordsVerdicts(java.nio.file.Path)]
replaced return value with Collections.emptyMap for org/egothor/methodatlas/command/CredentialTriageContext::verdictsByFqcn → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1