Skip to content

Commit d3e462c

Browse files
fix(intelligence): fix HashMap determinism in FileInventory + gitignore entries (RAN-154)
- countsByLanguage(): use TreeMap::new for deterministic alphabetical key ordering - toSummary() byLang: add thenComparing secondary sort to break ties alphabetically - toSummary() byCls: use LinkedHashMap::new to preserve TreeMap insertion order - .gitignore: add playwright-report/ and test-results/ frontend build artifacts Co-Authored-By: Paperclip <noreply@paperclip.ing>
1 parent 624fdd3 commit d3e462c

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ src/main/frontend/node_modules/
4343
src/main/frontend/node/
4444
src/main/frontend/dist/
4545
src/main/frontend/tsconfig.tsbuildinfo
46+
playwright-report/
47+
test-results/
4648
# Generated explorer CSS (rebuild via: cd src/main/frontend && npm run build:explorer-css)
4749
src/main/resources/static/css/explorer.css
4850

src/main/java/io/github/randomcodespace/iq/intelligence/FileInventory.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ public Map<FileClassification, Long> countsByClassification() {
3232
TreeMap::new, Collectors.counting()));
3333
}
3434

35-
/** Count of files per language. */
35+
/** Count of files per language, sorted alphabetically for determinism. */
3636
public Map<String, Long> countsByLanguage() {
3737
return entries.stream()
38-
.collect(Collectors.groupingBy(FileEntry::language, Collectors.counting()));
38+
.collect(Collectors.groupingBy(FileEntry::language,
39+
TreeMap::new, Collectors.counting()));
3940
}
4041

4142
/** Sum of all file sizes in bytes. */
@@ -51,10 +52,15 @@ public Map<String, Object> toSummary() {
5152
summary.put("total_files", totalFiles());
5253
summary.put("total_bytes", totalBytes());
5354
var byCls = countsByClassification().entrySet().stream()
54-
.collect(Collectors.toMap(e -> e.getKey().name().toLowerCase(), Map.Entry::getValue));
55+
.collect(Collectors.toMap(
56+
e -> e.getKey().name().toLowerCase(),
57+
Map.Entry::getValue,
58+
(a, b) -> a,
59+
java.util.LinkedHashMap::new)); // preserve TreeMap insertion order
5560
summary.put("by_classification", byCls);
5661
var byLang = countsByLanguage().entrySet().stream()
57-
.sorted(Map.Entry.<String, Long>comparingByValue().reversed())
62+
.sorted(Map.Entry.<String, Long>comparingByValue().reversed()
63+
.thenComparing(Map.Entry.comparingByKey()))
5864
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
5965
(a, b) -> a, java.util.LinkedHashMap::new));
6066
summary.put("by_language", byLang);

0 commit comments

Comments
 (0)