Skip to content

refactor(assistant): inject TimeProvider and IdGenerator seams#32

Merged
netqo merged 1 commit into
devfrom
refactor/time-id-seams
Jun 11, 2026
Merged

refactor(assistant): inject TimeProvider and IdGenerator seams#32
netqo merged 1 commit into
devfrom
refactor/time-id-seams

Conversation

@netqo

@netqo netqo commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

AssistantViewModel built chat message timestamps and ids by calling Date() and UUID.randomUUID() directly. Those are hidden dependencies on the wall clock and the RNG that left the timestampLabel and id fields untestable. This PR introduces two small seams, TimeProvider and IdGenerator (each a fun interface with a default production implementation), provides them as singletons from AppModule, and injects them into the ViewModel.

Rationale

The seams follow the dependency-injection style already used across the app (Hilt) and keep the ViewModel deterministic under test without changing production behavior: SystemTimeProvider still returns Date() and UuidIdGenerator still returns a random UUID. java.time.Clock was deliberately avoided because minSdk is 24 and it would require core-library desugaring.

AssistantViewModelTest now constructs the ViewModel with deterministic fakes (a fixed instant and sequential ids) instead of leaning on the system clock and random UUIDs.

Verification

  • ./gradlew ktlintCheck detekt testDebugUnitTest -> BUILD SUCCESSFUL
  • ./gradlew assembleDebug -> BUILD SUCCESSFUL

Test plan

  • ktlint + detekt clean
  • AssistantViewModelTest green with injected fakes
  • Debug APK assembles

Checklist

  • Commit messages follow Conventional Commits (see CONTRIBUTING.md).
  • Branch name follows the naming convention (refactor/).
  • The change is scoped: no unrelated edits sneaked into this PR.
  • If user-visible behavior changed, CHANGELOG.md has been updated under [Unreleased]. (No user-visible change.)
  • If a new dependency was added, it is justified in the PR description. (No new dependency.)

AssistantViewModel built chat message timestamps and ids by calling
`Date()` and `UUID.randomUUID()` directly, hidden dependencies on the
wall clock and the RNG that made those fields untestable. Introduce two
small seams (`TimeProvider`, `IdGenerator`) with default production
implementations, provide them as singletons from AppModule, and inject
them into the ViewModel.

Production behavior is unchanged. AssistantViewModelTest now passes
deterministic fakes instead of leaning on the system clock and random
UUIDs.
@netqo netqo merged commit 3c11694 into dev Jun 11, 2026
3 checks passed
@netqo netqo deleted the refactor/time-id-seams branch June 11, 2026 04:16
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