Implement CommandRunner pattern for unified testable package manager operations
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Không có đường dẫn tệp hoặc bài kiểm thử nào được nêu. Trước tiên, hãy đọc phần triển khai CommandRunner hiện có và các quá trình di chuyển YUM và APT đã hoàn tất, sau đó sử dụng các sub-issue #28 và #29 làm phạm vi đang thực hiện cho Snap và Flatpak. Công việc được xem là hoàn tất khi các quá trình di chuyển đó, các bài kiểm thử của chúng và những tiêu chí nghiệm thu còn lại đều hoàn tất.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem Statement
Currently, package managers use inconsistent command execution patterns, creating architectural and testing issues:
Current State Analysis
- YUM: ✅ Uses CommandRunner (recently migrated, fully tested)
- APT:
Uses CommandBuilder✅ MIGRATED (Issue #27 - PR #26) - Snap: Uses direct
exec.Commandcalls (Issue #28) - Flatpak: Uses direct
exec.Commandcalls (Issue #29)
Issues with Mixed Approaches
- Architectural inconsistency - Different patterns across package managers
- Complex testing - CommandBuilder requires shell script mocking vs simple map-based mocking
- Manual LC_ALL=C setup - Repetitive environment configuration in APT/Snap/Flatpak
- Inconsistent interactive mode - Manual stdin/stdout/stderr handling
- New developer complexity - CommandBuilder requires deep
exec.Cmdknowledge
Decision: Standardize on CommandRunner
Based on comprehensive analysis, CommandRunner is superior to CommandBuilder for this project:
Why CommandRunner Wins
1. Automatic LC_ALL=C Handling
CommandRunner automatically prepends LC_ALL=C for consistent English output across all package managers, with user override capability:
// CommandRunner: Automatic
output, err := runner.RunContext(ctx, "yum", []string{"info", "vim"})
// CommandBuilder: Manual setup required everywhere
cmd := builder.CommandContext(ctx, "yum", "info", "vim")
cmd.Env = append(os.Environ(), "LC_ALL=C", "DEBIAN_FRONTEND=noninteractive")
2. Simplified Testing
// CommandRunner: Simple map-based mocking
mock.AddCommand("yum", []string{"info", "vim"}, []byte("output"), nil)
// CommandBuilder: Complex shell script generation
mock.AddMockResult("yum", []string{"info", "vim"}, &MockResult{
Stdout: []byte("output"), ExitCode: 0,
})
3. Built-in Interactive Support
CommandRunner has dedicated RunInteractive() method that properly handles stdin/stdout/stderr without LC_ALL=C interference.
4. Consistency with Project Goals
From CLAUDE.md: "Use KISS (Keep It Simple and Stupid) and DRY (Don't Repeat Yourself)"
CommandRunner eliminates repetitive LC_ALL=C setup and interactive mode handling across all package managers.
5. Proven Success
YUM's recent migration to CommandRunner shows:
- 100% test coverage maintained
- Cleaner, more readable code
- Robust environment variable handling
- Successful interactive mode support
Solution: Migrate All Package Managers to CommandRunner
CommandRunner Interface
type CommandRunner interface {
// Run executes a command with LC_ALL=C for consistent English output
Run(name string, args ...string) ([]byte, error)
// RunContext executes with context support and LC_ALL=C, plus optional extra env
RunContext(ctx context.Context, name string, args []string, env ...string) ([]byte, error)
// RunInteractive executes in interactive mode with stdin/stdout/stderr passthrough
RunInteractive(ctx context.Context, name string, args []string, env ...string) error
}
Implementation Plan - UPDATED
Migration Progress:
- APT ✅ COMPLETED (Issue #27 - PR #26) - Replace CommandBuilder with CommandRunner
- Snap 🔄 IN PROGRESS (Issue #28) - Replace direct exec.Command with CommandRunner
- Flatpak ⏳ PLANNED (Issue #29) - Replace direct exec.Command with CommandRunner
Benefits
Testing Benefits
- ✅ Simple mocking - Map-based command mocking vs complex shell scripts
- ✅ Environment testing - Built-in environment variable tracking
- ✅ Interactive testing - Dedicated test methods for interactive mode
- ✅ 100% test coverage - All commands can be easily mocked
Architecture Benefits
- ✅ Consistent interface - Same pattern across all package managers
- ✅ Automatic LC_ALL=C - No manual environment setup needed
- ✅ Built-in interactive support - Proper stdin/stdout/stderr handling
- ✅ Simple for new developers - Easy to understand and implement
Code Quality Benefits
- ✅ DRY principle - Eliminates repetitive environment setup
- ✅ KISS principle - Simple interface vs complex CommandBuilder
- ✅ Maintainability - Consistent patterns across codebase
Acceptance Criteria - UPDATED
- APT migrated from CommandBuilder to CommandRunner ✅ (Issue #27 - PR #26)
- Snap migrated from direct exec.Command to CommandRunner (Issue #28)
- Flatpak migrated from direct exec.Command to CommandRunner (Issue #29)
- LC_ALL=C automatically handled across all package managers ✅ (APT+YUM complete)
- Interactive mode works consistently across all package managers ✅ (APT+YUM complete)
- Comprehensive test coverage maintained for all migrations ✅ (APT complete)
- All existing functionality preserved ✅ (APT verified)
- Documentation updated to reflect architectural consistency ✅ (Updated for APT)
Completion Status: ✅ 1/3 package managers completed (APT ✅, Snap ⏳, Flatpak ⏳)
Priority
High Priority - This achieves architectural consistency and leverages the proven CommandRunner interface that's already successful with YUM.
Related Work
- ✅ CommandRunner interface implemented and proven with YUM
- ✅ YUM migration completed successfully (100% test coverage)
- ✅ APT migration completed successfully (Issue #27 - PR #26)
- ✅ MockCommandRunner supports environment variable tracking
- ✅ Interactive mode support built-in and tested
Sub-Issues
This large architectural change has been broken down into manageable sub-issues:
- Issue #27: ✅ APT CommandRunner Migration (COMPLETED by PR #26)
- Issue #28: 🔄 Snap CommandRunner Migration (In Progress)
- Issue #29: ⏳ Flatpak CommandRunner Migration (Planned)
Progress: 1/3 package managers completed. APT migration successful with full test coverage and architectural improvements.
- Ngôn ngữ chính
- Go
- Star
- 17
- Fork
- 8
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bluet/syspkg
-
Dependency DashboardĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 15/100
-
apt-fast manager support.Có thể đã có người làm @bluet đã nhận 351 ngày trước. Đang mở
-
testing
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
Issue tương tự
-
Chained slog With calls discard previously bound attributesCó thể đã có người làm @yuefdev đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[scanner] TestAgentNowLineStates hard-fails instead of degrading when node is off PATHCó thể đã có người làm @arteeh đã nhận hôm nay. Đang mởagent/scanner ci help wanted kind/test
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
hivecommons/hive#12924 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Gentleman-Programming/engram#1940 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cloudflare/terraform-provider-cloudflare#7423 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
devices
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
evcc-io/evcc#35007 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày