Skip to content

feat(cfl): add space key display to page view and search#46

Merged
rianjs merged 1 commit intomainfrom
feat/42-cfl-space-key-in-page-view-search
Jan 31, 2026
Merged

feat(cfl): add space key display to page view and search#46
rianjs merged 1 commit intomainfrom
feat/42-cfl-space-key-in-page-view-search

Conversation

@rianjs
Copy link
Copy Markdown
Contributor

@rianjs rianjs commented Jan 31, 2026

Summary

  • page view: Display space key alongside space ID (e.g., Space: DEV (ID: 9999))
  • page view -o json: Enrich JSON output with spaceKey field via secondary GetSpace API call
  • search: Add SPACE KEY column extracted from resultGlobalContainer.displayUrl
  • Graceful fallback: if space lookup fails, show just the space ID

Changes

  • internal/cmd/page/view.go: Add space lookup and enriched JSON output
  • internal/cmd/search/search.go: Add extractSpaceKey() helper and update column header

Test plan

  • Unit tests for page view with space key lookup
  • Unit tests for graceful fallback when space lookup fails
  • Unit tests for enrichPageWithSpaceKey helper
  • Table-driven tests for extractSpaceKey with various URL patterns
  • All existing tests pass
  • Lint passes

Closes #42

- page view: Show space key alongside space ID (e.g., "Space: DEV (ID: 9999)")
- page view JSON: Enrich output with spaceKey field via GetSpace API call
- search: Extract space key from displayUrl and show in SPACE KEY column
- Graceful fallback if space lookup fails

Closes #42
@rianjs
Copy link
Copy Markdown
Contributor Author

rianjs commented Jan 31, 2026

Test Coverage Assessment

Summary

Overall: Tests are adequate for this PR. The changes are well-covered with tests that address the critical paths and edge cases.


Changes Analyzed

1. page view - Space key lookup and display

  • Added secondary GetSpace API call to fetch space key
  • Graceful fallback if space lookup fails
  • Enhanced JSON output with spaceKey field

2. search - Space key extraction from URL

  • Added extractSpaceKey() helper using regex
  • Changed column header from "SPACE" to "SPACE KEY"
  • Changed output source from resultGlobalContainer.Title to parsed displayUrl

Test Coverage Analysis

page/view.go changes (33 additions):

Code Path Covered Test(s)
Space key lookup succeeds Yes TestRunView_WithSpaceKey
Space lookup fails gracefully Yes TestRunView_SpaceLookupFails_Graceful
enrichPageWithSpaceKey helper Yes TestEnrichPageWithSpaceKey
JSON output with spaceKey Partial Relies on existing TestRunView_JSONOutput + new tests
No spaceId on page No (edge case, but gracefully handles via empty check)

search/search.go changes (18 additions):

Code Path Covered Test(s)
extractSpaceKey regex parsing Yes TestExtractSpaceKey (7 cases)
Empty URL fallback Yes TestExtractSpaceKey/empty_URL
No /spaces/ in URL Yes TestExtractSpaceKey/no_spaces_in_URL
Integration with search results Yes TestRunSearch_DisplaysSpaceKey
Various URL formats Yes Standard, wiki-prefixed, full domain, with numbers, blogpost

Observations

Strengths:

  1. The extractSpaceKey function has excellent table-driven test coverage with 7 distinct URL patterns
  2. Graceful degradation is tested (space lookup failure)
  3. Both API call sequencing is verified (GetPage then GetSpace)
  4. Tests follow the project's established patterns (httptest servers, testify assertions)

Minor gaps (acceptable for this PR):

  1. TestRunView_WithSpaceKey doesn't explicitly verify the output contains "Space: DEV (ID: 98765)" - it only checks the API calls were made. The output is implicitly trusted via the view renderer.
  2. TestRunSearch_DisplaysSpaceKey has a comment stating output should contain "DEV" but doesn't assert on stdout content. This is a minor documentation/assertion gap.
  3. No test for page with empty spaceId (though the code handles it correctly with the if page.SpaceID != "" guard).

These gaps are acceptable because:

  • The output formatting is handled by the trusted view package
  • The logic paths are covered; it's just the final string output that isn't asserted
  • Empty spaceId case is implicitly covered by existing tests that don't set it

Verdict

The test coverage is pragmatic and appropriate for this feature. The critical paths are covered:

  • API call sequencing
  • Error handling/graceful fallback
  • URL parsing edge cases
  • Helper function behavior

No obvious gaps that a reviewer would flag. The tests demonstrate the code works correctly without being overly pedantic about asserting every output string.

@rianjs rianjs merged commit fc75af0 into main Jan 31, 2026
7 checks passed
@rianjs rianjs deleted the feat/42-cfl-space-key-in-page-view-search branch January 31, 2026 10:50
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.

feat(cfl): port space key in page view/search

1 participant