Skip to content

test: add CI-safe unit coverage across LockIMEKit#10

Merged
BlackHole1 merged 1 commit into
mainfrom
add-test
Jun 12, 2026
Merged

test: add CI-safe unit coverage across LockIMEKit#10
BlackHole1 merged 1 commit into
mainfrom
add-test

Conversation

@BlackHole1

Copy link
Copy Markdown
Member

What

Raises unit-test coverage of Sources/LockIMEKit so every non-off-limits file reaches ≥90% line coverage on a non-exempt basis. All new tests are CI-safe (no hardware/system access) and were written red-first.

Per-file coverage (xccov, before → after)

File before after (raw) non-exempt
Rules/LockConfiguration.swift 82.86% 100% 100%
Localization/SupportedLanguage.swift 75.86% 100% 100%
Updates/UpdateChannel.swift 90.00% 100% 100%
LockEngine/LockEngine.swift 75.23% 88.99% 95.10% (97/102)
Logging/LogStore.swift 75.00% 84.62% 91.67% (44/48)
LockEngine/InputSourceChangeObserver.swift 65.00% 80.00% 92.31% (48/52)
LoginItem/LoginItemController.swift 38.46% 51.52% 94.44% (17/18)

Overall non-exempt coverage across non-off-limits files: 547/567 = 96.5%.

How

  • Mock-driven via the existing seams (MockInputSourceProvider, MockFrontmostMonitor, MockBrowserURLProvider). No Carbon/TIS, NSWorkspace, Accessibility, SMAppService, or wall-clock access — passes on headless CI, never mutates machine state.
  • Red-first: every test was seen failing before passing (value mutations for existing behavior; a pre-extraction compile error for the new logic). All mutations reverted.
  • The only source change extracts the pure register/unregister decision out of LoginItemController.setEnabled into a testable action(desiredEnabled:current:). The switch maps 1:1 to the previous if/elselaunch-at-login behavior is unchanged, and the new symbols are internal (invisible to the app module).

System-call exemptions (remaining uncovered lines)

Each is genuinely unexercisable CI-safe; verified by an adversarial audit pass:

  • LoginItemController 38/40/53-65 — SMAppService.mainApp status/register/unregister.
  • LockEngine 86-93 — private handlers wired only to the internally-constructed (non-injected) InputSourceChangeObservers, fired only by CFNotificationCenter.
  • InputSourceChangeObserver 47-54 — the C callback body; only real distributed-notification delivery invokes it.
  • LogStore 22-23 (real applicationSupportDirectory write) and 43/57 (SwiftData save/delete error catch — can't force a throw on a valid container).

The 5 off-limits shims (TISInputSourceProvider, FocusNudge, AppActivationMonitor, InstalledAppsScanner, AccessibilityBrowserURLReader) were not touched.

Verification

make test green — 133 tests, 0 failures, incl. LocalizationGuardTests.

Raise unit-test coverage of Sources/LockIMEKit so every non-system
file reaches at least 90% line coverage on a non-exempt basis. The
new tests are mock-driven — no Carbon/TIS, NSWorkspace, Accessibility,
SMAppService, or wall-clock access — so they pass on headless CI, and
each was seen failing before passing.

The single source change extracts the pure register/unregister
decision out of LoginItemController.setEnabled into a testable
`action(desiredEnabled:current:)`, so its branches can be covered
without registering a real login item. The switch maps one-to-one to
the previous if/else, so the launch-at-login behavior is unchanged.

Signed-off-by: Kevin Cui <bh@bugs.cc>
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 33fd8a8b-08ff-4b3d-86b3-624c05a48223

📥 Commits

Reviewing files that changed from the base of the PR and between b4895c4 and c43b5d9.

📒 Files selected for processing (8)
  • Sources/LockIMEKit/LoginItem/LoginItemController.swift
  • Tests/LockIMEKitTests/InputSourceChangeObserverTests.swift
  • Tests/LockIMEKitTests/LockConfigurationTests.swift
  • Tests/LockIMEKitTests/LockEngineTests.swift
  • Tests/LockIMEKitTests/LogStoreTests.swift
  • Tests/LockIMEKitTests/LoginItemControllerTests.swift
  • Tests/LockIMEKitTests/SupportedLanguageTests.swift
  • Tests/LockIMEKitTests/UpdateChannelTests.swift

Summary by CodeRabbit

  • Refactor

    • Improved internal login-item registration logic with clearer decision handling.
  • Tests

    • Expanded test coverage for input source observation, configuration management, engine lifecycle, logging, language support, and update channels.

Walkthrough

This PR adds a pure decision-logic helper to LoginItemController by extracting the enable/disable determination into a reusable action(desiredEnabled:current:) function that returns a LoginItemAction enum, allowing setEnabled(_:) to delegate its conditional registration logic. The change is accompanied by six new test suites validating identity invariants and public-facing behaviors across core components: InputSourceChangeObserver notification mappings, LockConfiguration rule lookup and Codable behavior, LockEngine lifecycle and accessor delegation, LogStore fallback resilience, SupportedLanguage locale identity and endonyms, and UpdateChannel id consistency.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'test: add CI-safe unit coverage across LockIMEKit' follows the required format with type and subject, clearly describing the main change (adding unit test coverage).
Description check ✅ Passed The PR description comprehensively explains the changes, coverage improvements, testing approach, and verification, directly relating to the changeset of new test files and a small refactoring.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch add-test

Comment @coderabbitai help to get the list of available commands and usage tips.

@BlackHole1 BlackHole1 merged commit 44b2954 into main Jun 12, 2026
3 checks passed
@BlackHole1 BlackHole1 deleted the add-test branch June 12, 2026 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant