Issue: T-002 — init: idempotent + --force / --out
Implement an init command for the AutoRepro CLI that creates a default devcontainer.json file with idempotent behavior, force overwrite capability, and custom output path support.
- Primary: Create a working
initcommand that generates standardized devcontainer configurations - Secondary: Establish CLI command extension patterns for future MVP commands (
scan,plan) - Quality: Maintain test coverage and code quality standards
autorepro/cli.py: Add subparser forinitcommand and implementationtests/test_cli.py: Add comprehensive test coverage forinitcommand
- None (keeping minimal - embedded devcontainer template)
autorepro init [OPTIONS]--force: Overwrite existing devcontainer.json (default: False)--out PATH: Custom output path (default: .devcontainer/devcontainer.json)
- Default: Creates
.devcontainer/devcontainer.jsonin current directory - Idempotent: Refuses to overwrite existing files without
--force - Path Creation: Creates parent directories as needed
- Validation: Checks write permissions and path validity
0: Success (file created or already exists with same content)1: File exists and no--forceflag provided2: Invalid arguments or path issues3: Permission denied or filesystem errors
- Happy Path:
autorepro initcreates.devcontainer/devcontainer.jsonwith default template - Idempotent: Running twice without
--forcereturns exit code 1 with helpful message - Force Overwrite:
autorepro init --forceoverwrites existing file - Custom Path:
autorepro init --out custom/path.jsoncreates file at specified location - Directory Creation: Creates parent directories if they don't exist
- Error Handling: Clear error messages for permission issues, invalid paths
- Content Validation: Generated devcontainer contains Python 3.11, Node 20, Go 1.22
class TestInitCommand:
def test_init_creates_default_devcontainer(self, tmp_path)
def test_init_idempotent_behavior_without_force(self, tmp_path)
def test_init_force_flag_overwrites_existing(self, tmp_path)
def test_init_custom_output_path(self, tmp_path)
def test_init_creates_parent_directories(self, tmp_path)
def test_init_permission_denied_error(self, tmp_path)
def test_init_invalid_path_error(self, tmp_path)
def test_init_devcontainer_content_validation(self, tmp_path)class TestInitIntegration:
def test_init_cli_success_via_subprocess(self, tmp_path)
def test_init_cli_force_flag_via_subprocess(self, tmp_path)
def test_init_cli_custom_out_via_subprocess(self, tmp_path)
def test_init_cli_error_handling_via_subprocess(self, tmp_path)tmp_path: Pytest built-in for isolated filesystem testingexpected_devcontainer_content: JSON template validation
- Add subparsers to
create_parser()incli.py - Add
initsubcommand with--forceand--outarguments - Create
handle_init()function with basic file creation logic - Update
main()to route to init handler
- Embed JSON template directly in code (minimal approach)
- Template includes:
- Python 3.11 feature
- Node 20 feature
- Go 1.22 feature
- Post-creation command for venv setup
- Appropriate metadata (name: "autorepro-dev")
- File existence checking with appropriate exit codes
- Parent directory creation with error handling
- Permission validation
- Path normalization and validation
- Unit tests with mocked filesystem operations
- Integration tests with real file operations in tmp_path
- Error condition testing
- Content validation tests
- Path Handling: Cross-platform path handling (Windows vs Unix)
- Permissions: Complex permission scenarios in CI environments
- Template Maintenance: Keeping devcontainer features current
- Template Location: Embed in code vs external file?
- Decision: Embed in code for minimal surface area
- Default Path:
.devcontainer/devcontainer.jsonvsdevcontainer.json?- Decision:
.devcontainer/devcontainer.json(standard convention)
- Decision:
- Content Updates: How to handle template changes over time?
- Decision: Version in code, address in future issues
- Use
pathlib.Pathfor cross-platform compatibility - Comprehensive error handling with clear user messages
- Test on both Unix and Windows in CI (future enhancement)
None identified - the implementation requires core command structure changes that should be done atomically.
- Implementation: Follow the 4-phase implementation strategy
- Testing: Ensure 100% test coverage for new functionality
- Documentation: Update CLI help text and README (future task)
- CI Validation: Verify tests pass in GitHub Actions environment
- Development: 2-3 hours
- Testing: 1-2 hours
- Integration & Validation: 30 minutes
- Total: ~4-6 hours
This plan prioritizes minimal surface area, reversibility, and maintainability while delivering the full requirements specified in Issue #4.