Commit 7486b25
committed
Merge #141: Add flush() method to UserOutput for explicit buffering control
b3f98c7 feat: [#138] add buffering control with flush() method (copilot-swe-agent[bot])
b537a8f Initial plan (copilot-swe-agent[bot])
Pull request description:
Adds explicit buffering control to `UserOutput` following Rust's `Write` trait pattern. While output is line-buffered by default, explicit flush ensures immediate visibility before long-running operations and improves test reliability.
## Changes
**Core API**
- Added `flush()` method that flushes both stdout and stderr writers
- Returns `std::io::Result<()>` for error propagation
- Safe to call multiple times (idempotent)
**Documentation**
- Module-level "Buffering Behavior" section explaining when to use `flush()`
- Rustdoc examples demonstrating usage patterns
**Tests**
- 5 tests covering success scenarios, idempotency, empty buffers, dual-channel flushing, and sequential patterns
- All existing tests pass (101 total in module)
## Usage
```rust
let mut output = UserOutput::new(VerbosityLevel::Normal);
output.progress("Starting long operation...");
output.flush()?; // Ensure message appears immediately
perform_long_operation();
```
## Implementation
Directly flushes the typed writer wrappers (`StdoutWriter` and `StderrWriter`) maintaining type safety through the newtype pattern:
```rust
pub fn flush(&mut self) -> std::io::Result<()> {
self.stdout.0.flush()?;
self.stderr.0.flush()?;
Ok(())
}
```
Backward compatible - purely additive change.
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Proposal 7: Add Buffering Control</issue_title>
> <issue_description>## Overview
>
> Add explicit buffering control to the `UserOutput` module by providing a `flush()` method. While writes are typically line-buffered by default, explicit flush control ensures output appears immediately when needed and provides better testing capabilities.
>
> ## Specification
>
> See detailed specification: [docs/issues/138-add-buffering-control.md](../docs/issues/138-add-buffering-control.md)
>
> ## Goals
>
> - [ ] Add `flush()` method to `UserOutput` for explicit buffer control
> - [ ] Document buffering behavior in module documentation
> - [ ] Add tests demonstrating flush behavior
> - [ ] Maintain backward compatibility with existing API
> - [ ] Follow Rust standard patterns from `Write` trait
>
> ## Implementation Plan
>
> ### Phase 1: Core Implementation (30 minutes)
> - [ ] Add `flush()` method to `UserOutput`
> - [ ] Implement flush for both `stdout` and `stderr` writers
> - [ ] Add rustdoc documentation for the method
>
> ### Phase 2: Documentation (20 minutes)
> - [ ] Update module-level documentation with buffering behavior section
> - [ ] Add usage examples showing when to use `flush()`
>
> ### Phase 3: Testing (30 minutes)
> - [ ] Add unit tests for successful flush
> - [ ] Add tests for multiple flush calls
> - [ ] Add tests for empty buffer flushing
>
> ### Phase 4: Quality Assurance (20 minutes)
> - [ ] Run `./scripts/pre-commit.sh` and fix any issues
> - [ ] Verify all linters pass
>
> **Total Estimated Time**: 2 hours
>
> ## Acceptance Criteria
>
> ### Functional Requirements
> - [ ] `UserOutput::flush()` method flushes both stdout and stderr
> - [ ] Flush can be called multiple times safely
> - [ ] Flush returns `std::io::Result<()>` for error handling
> - [ ] Existing functionality is not affected
>
> ### Testing Requirements
> - [ ] Unit tests cover successful flush scenarios
> - [ ] Tests verify idempotency (multiple flushes are safe)
> - [ ] All existing tests continue to pass
>
> ### Quality Requirements
> - [ ] Pre-commit checks pass: `./scripts/pre-commit.sh`
> - [ ] Code follows project conventions
>
> ## Related
>
> - **Parent Epic**: #102 - User Output Architecture Improvements
> - **Refactoring Plan**: [docs/refactors/plans/user-output-architecture-improvements.md](../docs/refactors/plans/user-output-architecture-improvements.md)
> - **Depends On**: #135 - Type-Safe Channel Routing
>
> ## Labels
>
> `enhancement`, `phase-2`, `user-output`, `P2`
>
> ## Priority
>
> P2 (Phase 2 - Polish & Extensions)
>
> ## Estimated Effort
>
> 2 hours
> </issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> <comment_new><author>@josecelano</author><body>
> **Parent Epic**: #102 - User Output Architecture Improvements
>
> This issue is part of Phase 2: Polish & Extensions of the User Output Architecture refactoring.</body></comment_new>
> </comments>
>
</details>
- Fixes #138
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
ACKs for top commit:
josecelano:
ACK b3f98c7
Tree-SHA512: 0fc84cdba38998b69432de679681c740f4f698f8ad66640fd8ba806c36c659851373097e5a2e1bdaa469cac45174c6d1702e34b9fd18abe6383c1675b16be17c1 file changed
Lines changed: 140 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
26 | 38 | | |
27 | 39 | | |
28 | 40 | | |
| |||
1083 | 1095 | | |
1084 | 1096 | | |
1085 | 1097 | | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
1086 | 1124 | | |
1087 | 1125 | | |
1088 | 1126 | | |
| |||
2744 | 2782 | | |
2745 | 2783 | | |
2746 | 2784 | | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
| 2835 | + | |
| 2836 | + | |
| 2837 | + | |
| 2838 | + | |
| 2839 | + | |
| 2840 | + | |
| 2841 | + | |
| 2842 | + | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
| 2848 | + | |
| 2849 | + | |
| 2850 | + | |
| 2851 | + | |
| 2852 | + | |
| 2853 | + | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
| 2857 | + | |
| 2858 | + | |
| 2859 | + | |
| 2860 | + | |
| 2861 | + | |
| 2862 | + | |
| 2863 | + | |
| 2864 | + | |
| 2865 | + | |
| 2866 | + | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
2747 | 2887 | | |
0 commit comments