CredentialTriageContext.java

1
package org.egothor.methodatlas.command;
2
3
import java.util.List;
4
import java.util.Map;
5
import java.util.concurrent.ConcurrentHashMap;
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 discovery loop as
18
 * each class is classified. {@link #candidatesFor(String)} is safe to call from
19
 * multiple threads (read-only on an immutable map); {@link #recordVerdicts(String, List)}
20
 * uses a {@link ConcurrentHashMap} and is likewise safe for concurrent calls.
21
 * </p>
22
 *
23
 * @since 4.1.0
24
 */
25
final class CredentialTriageContext {
26
27
    private final Map<String, List<PromptBuilder.CredentialCandidateRef>> candidatesByFqcn;
28
    private final Map<String, List<CredentialTriageVerdict>> verdictsByFqcn = new ConcurrentHashMap<>();
29
30
    /**
31
     * Creates a context for the supplied candidates.
32
     *
33
     * @param candidatesByFqcn candidate spans per class, in finding order; never {@code null}
34
     */
35
    /* default */ CredentialTriageContext(Map<String, List<PromptBuilder.CredentialCandidateRef>> candidatesByFqcn) {
36
        this.candidatesByFqcn = Map.copyOf(candidatesByFqcn);
37
    }
38
39
    /**
40
     * Returns the candidates for a class, or an empty list when none were detected.
41
     *
42
     * @param fqcn fully qualified class name
43
     * @return candidate spans for the class; never {@code null}
44
     */
45
    /* default */ List<PromptBuilder.CredentialCandidateRef> candidatesFor(String fqcn) {
46 1 1. candidatesFor : replaced return value with Collections.emptyList for org/egothor/methodatlas/command/CredentialTriageContext::candidatesFor → KILLED
        return candidatesByFqcn.getOrDefault(fqcn, List.of());
47
    }
48
49
    /**
50
     * Records the triage verdicts returned for a class.
51
     *
52
     * @param fqcn     fully qualified class name
53
     * @param verdicts verdicts from the folded AI call; ignored when {@code null}/empty
54
     */
55
    /* default */ void recordVerdicts(String fqcn, List<CredentialTriageVerdict> verdicts) {
56 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()) {
57
            verdictsByFqcn.put(fqcn, verdicts);
58
        }
59
    }
60
61
    /**
62
     * Returns the collected verdicts keyed by class.
63
     *
64
     * @return verdicts per class; never {@code null}
65
     */
66
    /* default */ Map<String, List<CredentialTriageVerdict>> verdictsByFqcn() {
67 1 1. verdictsByFqcn : replaced return value with Collections.emptyMap for org/egothor/methodatlas/command/CredentialTriageContext::verdictsByFqcn → KILLED
        return verdictsByFqcn;
68
    }
69
}

Mutations

46

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

56

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

67

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.30.1 support