Skip to content

feat(cfl): improve init and config test UX#56

Merged
rianjs merged 1 commit intomainfrom
feat/54-cfl-init-config-ux
Feb 2, 2026
Merged

feat(cfl): improve init and config test UX#56
rianjs merged 1 commit intomainfrom
feat/54-cfl-init-config-ux

Conversation

@rianjs
Copy link
Copy Markdown
Contributor

@rianjs rianjs commented Feb 2, 2026

Summary

Improves cfl's init command to reuse existing values and enhances config test output to match jtk's more informative style.

Changes

  • init command: Pre-populate form with existing config values when re-running init, so users can selectively update fields
  • config test: Show authenticated user details on success (display name, email, account ID) instead of just "success!"
  • API client: Add GetCurrentUser() method using legacy /rest/api/user/current endpoint
  • Types: Add User type with AccountID, DisplayName, Email fields

Test plan

  • make build-cfl succeeds
  • make test in tools/cfl passes
  • make lint in tools/cfl passes
  • Manual test: cfl init pre-populates existing values
  • Manual test: cfl config test shows user details

Closes #54

- Pre-populate init form with existing config values when re-running init
- Show authenticated user details in config test output (display name, email, account ID)
- Add GetCurrentUser method to API client using legacy /rest/api/user/current endpoint
- Add User type to api/types.go

Closes #54
@rianjs
Copy link
Copy Markdown
Contributor Author

rianjs commented Feb 2, 2026

Test Coverage Assessment for PR #56

Summary

This PR adds two features: (1) enhanced config test output showing user details, and (2) pre-populating form fields from existing config during cfl init. Overall, the test coverage is adequate for the changes, though there are some areas that could benefit from additional tests.


What's Covered

configcmd/test.go - User Display Logic

  • The existing TestRunTest_Success test was updated to mock the /user/current endpoint and verify no errors occur when user data is returned. This covers the happy path.
  • The graceful degradation path (when GetCurrentUser fails but connection works) is implicitly tested by the auth failure tests, though not directly.

api/client.go - GetCurrentUser()

  • Indirectly tested via the test_test.go mock server that returns user JSON.
  • The JSON unmarshaling and error wrapping work correctly in the success case.

Coverage Gaps to Consider

1. GetCurrentUser() - Missing Direct Unit Tests (Medium priority)

The new GetCurrentUser() method in api/client.go lacks direct unit tests. The method contains URL manipulation logic (strings.TrimSuffix(c.BaseURL, "/wiki")) that should be explicitly tested for edge cases:

  • Base URL with /wiki suffix (e.g., https://example.atlassian.net/wiki)
  • Base URL without /wiki suffix (e.g., https://example.atlassian.net)
  • API error handling (e.g., 401, 404 responses)
  • Malformed JSON response

While the happy path is covered indirectly, a direct test in client_test.go would improve confidence.

2. runTest() - Display Logic Branches (Low priority)

The display logic in test.go has several branches that aren't explicitly tested:

  • DisplayName empty, fallback to PublicName
  • Email present vs. absent
  • AccountID empty

These are presentation-only changes with low risk, so the lack of explicit tests is acceptable.

3. init.go - Pre-population Logic (Medium priority)

The new pre-population logic in runInit() is not tested. The existing tests in init_test.go test connection verification and command flags, but not the config pre-population behavior. Specifically untested:

  • Priority ordering: CLI flag > existing config > empty
  • All four fields are pre-populated: URL, Email, APIToken, DefaultSpace
  • Edge case: existing config load fails (silent fallback to empty config)

This logic is straightforward but involves file I/O and has clear priority semantics that would benefit from explicit unit tests.


Recommendation

The PR is acceptable to merge as-is. The changes are relatively low-risk (display improvements and form pre-population), and the critical paths (API connectivity, authentication) remain well-tested.

For a future follow-up, consider adding:

  1. A direct unit test for GetCurrentUser() in api/client_test.go covering URL construction and error cases
  2. A test for the config pre-population priority logic in init_test.go

Automated review by Claude

@rianjs rianjs merged commit 45e7b2b into main Feb 2, 2026
7 checks passed
@rianjs rianjs deleted the feat/54-cfl-init-config-ux branch February 2, 2026 11:42
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.

[cfl] Improve init and config test UX

1 participant