Skip to content

[#170] Presentation Layer Testing and Cleanup - #171

Merged
josecelano merged 20 commits into
mainfrom
170-presentation-layer-testing-and-cleanup
Nov 13, 2025
Merged

josecelano merged 20 commits into
mainfrom
170-presentation-layer-testing-and-cleanup

Conversation

@josecelano

@josecelano josecelano commented Nov 12, 2025 •

Copy link
Copy Markdown
Member

Summary

This PR addresses presentation layer testing improvements and cleanup tasks identified during Epic #154 work. The focus is on practical improvements to test organization, code coverage, and following established testing conventions.

Progress Status

✅ Completed Tasks

  • Task 1: Split test_support.rs - Successfully split into multiple focused modules
    • src/presentation/views/test_support/mod.rs - Module exports and documentation
    • src/presentation/views/test_support/test_writer.rs - TestWriter implementation
    • src/presentation/views/test_support/test_user_output.rs - TestUserOutput struct and basic methods
    • src/presentation/views/test_support/test_wrapper.rs - TestOutputWrapper and convenience methods
    • All imports updated across codebase
    • Module organization follows project conventions
    • All existing functionality preserved

🔄 Remaining Tasks

  • Task 2: Clean unused code in test support modules (unused public functions/methods)
  • Task 3: Fix test output - ensure clean output when run without --nocapture
  • Task 4: Reorganize tests in src/presentation/views/core.rs (better grouping of integration tests)
  • Task 5: Review naming conventions - ensure all tests follow it_should_ format from project conventions
  • Task 6: Increase code coverage across presentation layer modules

Related Issues

Testing

  • All existing tests pass
  • Module split preserves all functionality
  • No breaking changes to public APIs
  • Pre-commit checks pass (will verify before marking ready for review)

Documentation

  • Issue progress updated in docs/issues/170-presentation-layer-testing-and-cleanup.md
  • Implementation follows project conventions from docs/contributing/

Notes

This is a draft PR to track progress on issue #170. Will be marked ready for review once all tasks are completed and pre-commit checks pass.

Next steps: Proceeding with Task 2 (Clean Unused Code) to remove technical debt from test support modules.

- Split 438-line test_support.rs into 4 focused modules:
  - mod.rs: Module exports and documentation
  - test_writer.rs: TestWriter implementation for shared buffers
  - test_user_output.rs: Core TestUserOutput functionality
  - test_wrapper.rs: TestOutputWrapper convenience methods
- Renamed test_support → testing for consistency with src/testing
- Updated all references across 20+ files in codebase
- Maintained backward compatibility through re-exports
- All 1,178 tests pass with no regressions
- Follows project module organization conventions

Task 1 of issue #170 complete
- Remove 4 unused methods: wrapped(), wrapped_silent(), into_wrapped(), output_pair(), clear()
- Keep actively used methods: new(), with_theme(), stdout(), stderr(), into_reentrant_wrapped(), into_reentrant_test_wrapper()
- Reduce file size from 271 to 171 lines (~37% reduction)
- Maintain backward compatibility for all existing usage patterns
- All 1,178 tests pass and linters are clean

This completes Task 2 of issue #170 by removing dead code while preserving all functionality.
Removed 11 unused methods while preserving essential functionality:
- Removed convenience wrapper methods (progress, success, warn, error, etc.)
- Removed utility methods (clear, with_output, output_pair, etc.)
- Fixed write() method signature during cleanup
- Kept essential methods: new(), stdout(), stderr(), steps(), info_block()

All 1,178 tests pass and linters pass. Backward compatibility maintained.
…e TestUserOutput and TestOutputWrapper

- Remove into_reentrant_test_wrapper method from TestUserOutput
- Replace method calls with direct TestOutputWrapper constructor usage
- Make stdout_buffer and stderr_buffer fields public for direct access
- Update documentation and examples to reflect new usage pattern
- Maintain TestOutputWrapper decoupling for better separation of concerns
- Remove TestOutputWrapper from src/presentation/views/testing/test_wrapper.rs
- Replace usage in core.rs tests with direct TestUserOutput access
- Update testing module exports to only include TestUserOutput and TestWriter
- Simplify testing infrastructure by eliminating redundant wrapper pattern
- All 1178 tests continue to pass, functionality preserved
- Mark test_support.rs module split as completed in Success Criteria
- Update Definition of Done for Task 1 with all sub-tasks completed
- Update Timeline to show Task 1 as completed and struck through
- Ready to proceed with Task 2 (Clean Unused Code)
…pleted

- Mark clean test output without --nocapture flag as completed in Success Criteria
- Update Definition of Done for Task 3 with all sub-tasks completed
- Update Timeline to show Task 3 as completed and struck through
- Verified tests run cleanly without unwanted output when not using --nocapture
- 3 out of 6 tasks now completed (Tasks 1, 2, and 3)
…l_confusion test

- Remove test that falsely claimed to demonstrate compile-time safety
- The commented lines actually DO compile, proving no type safety exists
- Clean up unused imports (parking_lot::Mutex, std::sync::Arc)
- Part of Task 4: Test Organization - removing misleading tests
- Verified remaining test in type_safe_wrappers module still passes
…ernally test

- Remove test that duplicates functionality of it_should_route_message_to_correct_channel
- The parameterized test already covers progress→stderr and result→stdout routing
- Remove empty type_safe_wrappers module that had no remaining tests
- Parameterized test provides superior coverage (5 message types vs 2)
- Part of Task 4: Test Organization - eliminating redundant tests
- Add channel tests to all message types (ErrorMessage, SuccessMessage, WarningMessage, StepsMessage)
- Update all test names to follow project convention: it_should_{behavior}_when_{condition}
- Ensure each message type tests its own channel routing responsibility
- Maintain comprehensive test coverage for stdout vs stderr channel routing

All message types now have unit tests validating their channel() method returns
the correct Channel enum value, following the separation of concerns where
each message type is responsible for its own routing logic.
- Add unit tests for verbosity requirements across all message types
- Add unit tests for channel routing across all message types
- Follow project naming convention: it_should_{behavior}_when_{condition}
- Ensure each message type tests its own properties (separation of concerns)
- Maintain integration tests for UserOutput orchestration behavior
- Complete unit test coverage: 35 message tests + 68 core integration tests
- Support proper test architecture with non-redundant coverage levels
- Create src/presentation/views/messages/blank_line.rs with complete implementation
- Add comprehensive unit tests (6 tests) for BlankLineMessage
- Update mod.rs to export BlankLineMessage
- Simplify UserOutput::blank_line() method from 17 lines to 3 lines
- Improve code consistency by following established message type patterns

This refactoring moves BlankLineMessage from an inline struct definition
to a proper module, aligning with the architecture used by all other
message types (ErrorMessage, SuccessMessage, etc.).
Remove extensive parameterized and complex test suite that was created by AI models
and became difficult to maintain. The tests were overly complex for the core
UserOutput functionality and made the module harder to understand and modify.

This cleanup focuses on keeping the core implementation clean while tests
can be redesigned with better focus and maintainability in mind.
Rename src/presentation/views/core.rs to user_output.rs for better clarity
and descriptive naming. Update module imports in mod.rs accordingly.

This makes the module name more descriptive and clearly indicates
its purpose as containing the UserOutput struct and implementation.
…ability

- Reorganize tests into logical sections with clear headers
- Enhance test fixtures with builder-style constructors
- Improve helper functions with better names and error messages
- Eliminate redundant tests while maintaining coverage
- Add more descriptive assertions with helpful context
- Simplify parameterized tests by removing unused parameters
- Improve timestamp tests to be less flaky and more valuable
- Reduce test code by 9.5% (39 lines) while keeping 22 passing tests

Test quality improvements:
- Better separation of concerns (fixtures, helpers, tests)
- Focus on behavior rather than implementation details
- Clearer failure messages for faster debugging
- More maintainable with reusable components
…ntions

- Rename test from 'composite_sink_should_support_empty_sink_list' to 'it_should_create_composite_sink_when_given_empty_sink_list'
- Rename test from 'composite_sink_should_support_add_sink' to 'it_should_add_sink_to_composite_when_add_sink_is_called'
- Remove redundant comments as test names are now self-documenting
- Follow three-part structure (What-When-Then) as documented in docs/contributing/testing/unit-testing.md
…t testing conventions

Channel module (channel.rs):
- Split 'channel_enum_should_support_equality' into two focused tests
- Rename to 'it_should_compare_equal_when_channels_are_same'
- Add 'it_should_compare_not_equal_when_channels_are_different'

Theme module (theme.rs):
- Rename 'emoji_theme_should_use_emoji_symbols' to 'it_should_return_emoji_symbols_when_using_emoji_theme'
- Rename 'plain_theme_should_use_text_labels' to 'it_should_return_text_labels_when_using_plain_theme'
- Rename 'ascii_theme_should_use_ascii_symbols' to 'it_should_return_ascii_symbols_when_using_ascii_theme'
- Rename 'default_theme_should_be_emoji' to 'it_should_default_to_emoji_theme_when_using_default'

Verbosity module (verbosity.rs):
- Consolidate duplicate tests and improve naming clarity
- Rename all tests to follow What-When-Then pattern
- Split ordering and equality tests for better granularity
- Remove redundant test implementations

All changes follow three-part structure (What-When-Then) as documented in docs/contributing/testing/unit-testing.md
- Add 5 test submodules testing all write() method functionality:
  * verbosity: Tests message filtering by verbosity level
  * formatter: Tests JSON formatter override transformation
  * theme: Tests theme formatting with emoji/plain/ascii (rstest)
  * sink: Tests custom output sink redirection
  * channel_routing: Tests stdout/stderr separation (rstest)
- Use custom OutputMessage trait implementations for test isolation
- Apply rstest parametrization per project conventions
- Make UserOutput::with_theme() public for doctest examples
- Total: 8 test cases covering all critical write() behaviors
…n status

- Mark Task 6 (Code Coverage) as partially completed
- Document completed UserOutput.write() testing work (Commit 1768cde)
- Add detailed breakdown of 5 test submodules with 8 test cases
- Specify remaining work: command handler error paths, CLI validation, edge cases
- Update timeline priority to reflect partial completion
@josecelano
josecelano marked this pull request as ready for review November 13, 2025 17:17
@josecelano josecelano self-assigned this Nov 13, 2025
@josecelano

Copy link
Copy Markdown
Member Author

ACK 8c4b719

@josecelano
josecelano merged commit 625e9f9 into main Nov 13, 2025
@josecelano
josecelano deleted the 170-presentation-layer-testing-and-cleanup branch April 15, 2026 16:38
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.

Presentation Layer Testing and Cleanup

1 participant