Skip to content

Simplify Test Infrastructure for UserOutput #123

Closed

Description

@josecelano

Overview

Simplify the test infrastructure for UserOutput by replacing complex Arc<Mutex<Vec<u8>>> and custom SharedWriter with a simpler, more maintainable TestUserOutput wrapper. This makes test code easier to understand and reduces cognitive load for contributors.

Specification

See detailed specification: docs/issues/123-simplify-test-infrastructure.md

🏗️ Architecture Requirements

DDD Layer: Presentation (Test Support Module)
Module Path: src/presentation/user_output.rs (test module)
Pattern: Test Helper Struct

Module Structure Requirements

  • Keep test infrastructure in #[cfg(test)] module within user_output.rs
  • Create TestUserOutput helper struct for test scenarios
  • Maintain separation between production code and test helpers
  • Follow module organization conventions (see docs/contributing/module-organization.md)

Architectural Constraints

  • Test-only code: All changes confined to #[cfg(test)] modules
  • No breaking changes: Production UserOutput API unchanged
  • Standard library preference: Use Vec<u8> and standard types over complex wrappers
  • Simplicity over cleverness: Favor readable code over minimal boilerplate

Anti-Patterns to Avoid

  • ❌ Over-engineering test infrastructure - Don't add unnecessary abstractions
  • ❌ Leaking test code to production - Keep test helpers in test modules only
  • ❌ Complex synchronization primitives - Avoid Arc<Mutex<>> unless truly needed

Implementation Plan

Phase 1: Create New Test Infrastructure (1-2 hours)

  • Create test_support module in #[cfg(test)] section
  • Implement TestUserOutput struct with accessor methods
  • Implement TestWriter with Write trait
  • Add documentation for test infrastructure

Phase 2: Update Existing Tests (2-3 hours)

  • Identify all tests using create_test_user_output()
  • Update tests to use TestUserOutput::new()
  • Simplify test code with new cleaner API
  • Verify all tests pass

Phase 3: Remove Old Infrastructure (30 minutes)

  • Remove SharedWriter struct
  • Remove create_test_user_output() function
  • Run linter and fix warnings

Phase 4: Documentation and Verification (30 minutes)

  • Add module documentation
  • Run full test suite
  • Run pre-commit checks: ./scripts/pre-commit.sh

Acceptance Criteria

Note for Contributors: These criteria define what the PR reviewer will check. Use this as your pre-review checklist before submitting the PR to minimize back-and-forth iterations.

Quality Checks:

  • Pre-commit checks pass: ./scripts/pre-commit.sh

Infrastructure Checks:

  • TestUserOutput struct exists in test module
  • All accessor methods implemented: stdout(), stderr(), output(), clear()
  • Old SharedWriter and create_test_user_output() removed

Test Migration Checks:

  • All tests updated to new infrastructure
  • No remaining references to old helpers
  • All tests pass
  • Test code is simpler and more readable

Code Quality Checks:

  • Test infrastructure well-documented
  • Usage examples provided
  • Standard library types used (Rc<RefCell<>> instead of Arc<Mutex<>>)

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions