Skip to content

Add 60 unit tests for modules with least coverage#3

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1783099674-add-unit-test-coverage
Open

Add 60 unit tests for modules with least coverage#3
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1783099674-add-unit-test-coverage

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

The existing test suite had 8 tests covering sanitizeState, computeAuthSignature, extractEmailFromIdToken, a mocked primeAccount, ensureCurrentCodexLinked matching, and one resolveUsageUrl case. Several core modules had zero or near-zero test coverage.

This PR adds 60 new unit tests (8 → 68 total, 149 expect() calls) targeting the least-covered areas:

SessionService (21 new tests)

  • extractAuthTokens — ChatGPT tokens, API key path, missing token throw, optional field defaults, API key precedence over tokens block
  • validateChatGptAuth — valid chatgpt/api_key/null modes pass; empty token and unexpected mode throw
  • resolveCodexExecutable — env var resolution (KEYFLOW_CODEX_PATH, KFL_CODEX_PATH), PATH search, fallback to "codex"
  • extractEmailFromIdToken (extended) — preferred_username fallback, no-email payload, non-email value, base64url padding
  • pruneBackups — keeps 10 newest, no-op for ≤10, no-throw on missing dir

UsageService (12 new tests)

  • buildEmptyUsageSnapshot — all fields are null/'never'
  • resolveUsageUrl — no config default, chat.openai.com/backend-api, custom non-ChatGPT base → /api/codex/usage, trailing slash stripping, pre-existing /backend-api
  • scanLogFile — valid log parsing (source/plan/windows/timestamps), email filtering, empty-file null, missing-file null, last-entry-wins, percentage clamping

ProfileService (22 new tests)

  • buildEmptyState, getActiveAccount (null/match/fallback), resolveAccountByIdentifier (by id/label/unknown/duplicate), formatStateSummary (active flags, empty state)
  • sanitizeState edge cases — non-object input, generated id, default label, percentage clamping, remainingPercent derivation, activeAccountId fallback/auto-set, invalid status default, source handling
  • computeAuthSignature edge cases — different auth modes produce different sigs, no stable identity falls back to accessToken seed

kfl-bridge (5 new tests)

  • buildBridgeStatusPayload — empty state, isActive/canSwitch/needsAttention flags, isBlocked for deactivated accounts, displayName email-vs-label fallback

Link to Devin session: https://app.devin.ai/sessions/72c3dfb1736048ad8b92da2b8a550854
Requested by: @hbui290

Cover previously untested functions across all core modules:

- SessionService: extractAuthTokens (5), validateChatGptAuth (5),
  resolveCodexExecutable (4), extractEmailFromIdToken extended (4),
  pruneBackups (3)
- UsageService: buildEmptyUsageSnapshot (1), resolveUsageUrl (5),
  scanLogFile (6)
- ProfileService: buildEmptyState (1), getActiveAccount (3),
  resolveAccountByIdentifier (4), formatStateSummary (2),
  sanitizeState edge cases (10), computeAuthSignature edge cases (2)
- kfl-bridge: buildBridgeStatusPayload (5)

Total: 8 existing + 60 new = 68 tests, 149 expect() calls.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@hbui290 hbui290 self-assigned this Jul 3, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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