test: add 34 device exclusion and defseq preservation tests#541
Conversation
Cover KanataDefchordsParser unit tests (parsing, edge cases, inline comments, timeout tokens, single-line groups, key sets), chord group references in mappings, KanataDefseqParser edge cases (single/multi format, comments, deduplication, hyphens), device exclusion parsing (empty/non-matching/VirtualHID/physical/sorted), ChordGroupConfig and ParsedSequence model tests (Codable, Equatable), config generation with preserved chord groups and sequences, empty preservation omission, and round-trip tests verifying both defchords and defseq survive config regeneration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Code Review: PR #541 — 34 device exclusion and defseq preservation tests
OverviewAdds a single 428-line test file covering Issues1. Test overlap with existing
|
| New test | Already covered by existing test |
|---|---|
testParseExcludedDevices_OnlyNonMatchingLines |
testParseExcludedMacOSDeviceNamesDeduplicatesAndIgnoresNonMatchingLines |
testParseExcludedDevices_VirtualHIDDetected |
testParseExcludedMacOSDeviceNamesExtractsHashAndProductKey |
testParseExcludedDevices_PhysicalDeviceExcluded |
testParseExcludedMacOSDeviceNamesExtractsHashAndProductKey |
testParseExcludedDevices_ResultIsSorted |
testParseExcludedMacOSDeviceNamesExtractsHashAndProductKey |
Only testParseExcludedDevices_EmptyInput is genuinely new. The granular single-assertion style has value, but the duplication adds maintenance surface without coverage gain. Future tests in this area should check the existing file first.
2. Deduplication test doesn't verify which entry wins
func testDefseqParser_DuplicateSequencesDeduped() {
let config = """
(defseq hello (a b c))
(defseq hello (a b c))
"""
let sequences = KanataDefseqParser.parseSequences(from: config)
XCTAssertEqual(sequences.count, 1)
}Both duplicates are identical, so the test can't catch a bug where the second entry silently overwrites the first with different keys. A stronger version would use (defseq hello (x y z)) for the second occurrence and assert which keys are preserved.
3. Class name doesn't match scope
DeviceExclusionDefseqPreservationTests covers six distinct areas (defchords parser, defseq parser, device exclusion, models, config generation, round-trips). Either split into per-feature files (matching the existing KanataMacOSDeviceExclusionParserTests, ChordGroupsIntegrationTests pattern) or choose a broader name like KanataParserPreservationTests. The current name makes tests hard to discover via file-based navigation.
4. Weak contains() assertions in config generation tests
XCTAssertTrue(config.contains("defchords"), "Config should include chord groups")
XCTAssertTrue(config.contains("nav"), "Config should include chord group name")"nav" as a substring will pass even if it appears in a comment or unrelated block. Consider checking for something more structural like "(defchords nav" to make the assertion meaningful.
5. Missing malformed-input coverage
Parser tests cover empty input and missing blocks, but not malformed input: unbalanced parentheses, missing timeout token, chord group with zero chords, defseq with empty key list (defseq empty ()). Parsers that silently return partial results on malformed input are a source of confusing runtime behavior.
Positives
- Round-trip tests are excellent.
testDefchordsRoundTrip_ParsedGroupsSurviveRegenerationandtestDefseqRoundTrip_ParsedSequencesSurviveRegenerationcatch the class of bug where serialization changes the shape of data. These are the highest-value tests in the file. #if os(macOS)gating is correct for device exclusion tests.- Naming convention (
testXxx_Condition) is consistent with the rest of the test suite. - MARK sections make the file easy to scan.
- Sub-1-second runtime is verified per the PR description, satisfying the project's
<5s totalconstraint. testParseGroups_KeySetComputedtestingkeySetas aSet<String>rather than an ordered array is appropriately robust.
Suggestions for follow-up
- Remove the 4 overlapping device exclusion tests (or consolidate into
KanataMacOSDeviceExclusionParserTests) — they add noise without coverage. - Strengthen
testDefseqParser_DuplicateSequencesDedupedwith differing key sequences. - Add at least one malformed-input test per parser to document and lock in graceful-degradation behavior.
Summary
Closes #533
Test plan