Skip to content

Commit 77aa917

Browse files
PaulDuvallclaude
andcommitted
docs: add OIDC TDD implementation plan and update requirements spec
📋 Change summary: * Add comprehensive TDD implementation plan (docs/plans/oidc-tdd-implementation-plan.md) * Update OIDC requirements spec - remove experimental xoidc references * Structure 7-phase implementation approach with Red-Green-Refactor workflow * Define testing strategies and success criteria for each phase 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent e6ff00c commit 77aa917

File tree

2 files changed

+440
-68
lines changed

2 files changed

+440
-68
lines changed
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
# OIDC TDD Implementation Plan
2+
3+
## Overview
4+
5+
This document outlines a Test-Driven Development (TDD) approach for implementing the claude-dev-toolkit OIDC command as specified in `specs/claude-dev-toolkit-oidc-requirements.md`. The plan follows a bottom-up approach, building foundational infrastructure first, then layering on features using the Red-Green-Refactor cycle.
6+
7+
## Implementation Philosophy
8+
9+
- **One requirement at a time**: Implement and fully test each requirement before moving to the next
10+
- **Red-Green-Refactor**: Write failing tests first, implement minimal code to pass, then refactor
11+
- **Integration checkpoints**: Test actual command functionality after each phase
12+
- **Dependency-driven ordering**: Build prerequisites before dependent features
13+
14+
## Recommended Implementation Order
15+
16+
### Phase 1: Foundation Infrastructure
17+
**Goal**: Establish basic command structure and error handling
18+
19+
1. **REQ-CLI-001**: Toolkit Command Structure
20+
- Register command in command-selector.js
21+
- Extend base-command.js pattern
22+
- Implement help text system
23+
24+
2. **REQ-DEP-001**: Tool Availability Checks
25+
- Validate AWS CLI installation and version
26+
- Validate GitHub CLI installation and auth
27+
- Check Git repository with GitHub remote
28+
- Verify Node.js compatibility
29+
30+
3. **REQ-ERR-001**: Toolkit Error Framework Integration
31+
- Use lib/error-handler-utils.js
32+
- Implement structured error objects
33+
- Add contextual error messages
34+
- Include recovery suggestions
35+
36+
4. **REQ-CLI-002**: Argument Processing (Basic)
37+
- Implement core argument parsing
38+
- Add validation through validation-utils.js
39+
- Support essential flags: --help, --dry-run, --verbose
40+
41+
**Phase 1 Rationale**: Without these foundations, you cannot test any OIDC functionality. Command structure enables testing, dependency validation prevents runtime failures, error handling provides debugging capability.
42+
43+
### Phase 2: Core Detection System
44+
**Goal**: Enable auto-detection of project context
45+
46+
5. **REQ-DETECT-001**: Git Repository Detection
47+
- Auto-detect GitHub org/repo from git remote
48+
- Support SSH and HTTPS git remotes
49+
- Handle multiple remotes (prefer 'origin')
50+
- Clear errors for missing Git/GitHub setup
51+
52+
6. **REQ-DETECT-002**: AWS Configuration Detection
53+
- Read from AWS CLI config files
54+
- Check AWS_DEFAULT_REGION environment variable
55+
- Default to us-east-1 when no config found
56+
- Validate region exists
57+
58+
7. **REQ-CLI-003**: Zero Configuration Mode
59+
- Combine git detection + AWS detection
60+
- Use standard policy template by default
61+
- Auto-generate role names
62+
- Enable `claude-dev-toolkit oidc` with no args
63+
64+
**Phase 2 Rationale**: Auto-detection enables the zero-config experience that makes the tool user-friendly. All subsequent features depend on being able to detect the project context.
65+
66+
### Phase 3: Basic OIDC Implementation
67+
**Goal**: Core OIDC provider and IAM role creation
68+
69+
8. **REQ-POLICY-001**: Built-in Policy Templates
70+
- Embed minimal, standard, and full templates
71+
- Add JSON validation for all templates
72+
- Implement template selection logic
73+
74+
9. **REQ-CMD-001**: OIDC Command Execution (Basic Flow)
75+
- Create GitHub OIDC provider in AWS
76+
- Generate IAM role with trust policy
77+
- Attach permission policies
78+
- Basic success/failure handling
79+
80+
10. **REQ-OUT-003**: Dry-run Mode Output
81+
- Display all operations without executing
82+
- Show AWS CLI commands that would run
83+
- Display generated IAM policies
84+
- Provide operation summary
85+
86+
**Phase 3 Rationale**: Now you have a working OIDC setup with safety (dry-run) testing. This core functionality can be thoroughly tested before adding complexity.
87+
88+
### Phase 4: Advanced Policy Management
89+
**Goal**: Flexible policy customization
90+
91+
11. **REQ-POLICY-002**: Policy File Support
92+
- Read custom IAM policy from JSON file
93+
- Validate JSON syntax and IAM structure
94+
- Handle file existence and readability
95+
- Provide clear error messages
96+
97+
12. **REQ-POLICY-005**: Policy Directory Support
98+
- Load multiple JSON files from directory
99+
- Merge policies into comprehensive policy
100+
- Exclude example files (-example.json)
101+
- Validate each file independently
102+
103+
13. **REQ-POLICY-006**: Trust Policy Scoping
104+
- Support --branch and --tag flags
105+
- Generate StringEquals conditions
106+
- Validate branch/tag name formats
107+
- Default to repository-wide access
108+
109+
**Phase 4 Rationale**: Build advanced policy features on top of working basic system. Each feature is independent and can be tested separately.
110+
111+
### Phase 5: GitHub Integration
112+
**Goal**: Complete the GitHub-AWS connection
113+
114+
14. **REQ-CMD-002**: Repository Variable Configuration
115+
- Set AWS_DEPLOYMENT_ROLE and AWS_REGION variables
116+
- Use `gh variable set` command
117+
- Handle GitHub API failures gracefully
118+
119+
15. **REQ-DETECT-003**: Existing Resource Detection
120+
- Check for existing GitHub OIDC provider
121+
- Detect existing IAM roles with same name
122+
- Update rather than recreate resources
123+
- Report existing resource status
124+
125+
16. **REQ-ERR-002**: Partial Failure Recovery
126+
- Handle AWS success + GitHub failure scenarios
127+
- Display role ARN for manual setup
128+
- Provide exact `gh` CLI commands
129+
- Offer retry options
130+
131+
**Phase 5 Rationale**: GitHub integration completes the OIDC setup. Error recovery is critical here since this involves multiple external services.
132+
133+
### Phase 6: Advanced Features
134+
**Goal**: Additional functionality and deployment options
135+
136+
17. **REQ-POLICY-003**: Policy URL Support
137+
- Fetch IAM policies from HTTPS URLs
138+
- Validate certificates and response size
139+
- JSON validation of fetched content
140+
- Security-focused URL handling
141+
142+
18. **REQ-POLICY-004**: Service Addition
143+
- Add AWS service permissions dynamically
144+
- Support common services (s3, lambda, rds)
145+
- Merge with base template
146+
- Handle repeated --add-service flags
147+
148+
19. **REQ-DEPLOY-001**: CloudFormation Deployment Option
149+
- Generate CloudFormation templates
150+
- Support stack lifecycle management
151+
- Use consistent naming conventions
152+
- Handle stack dependencies
153+
154+
### Phase 7: Production Polish
155+
**Goal**: Security, user experience, and operational features
156+
157+
20. **REQ-HOOK-001**: Pre-execution Security Validation
158+
- Trigger hooks/pre-write-security.sh
159+
- Validate overly permissive policies
160+
- Check GitHub token scopes
161+
- Abort on security failures
162+
163+
21. **REQ-OUT-001**: Progress Indication
164+
- Display emoji progress indicators
165+
- Support quiet and verbose modes
166+
- Show progress for long operations
167+
168+
22. **REQ-OUT-002**: Comprehensive Success Report
169+
- Display complete configuration summary
170+
- Provide copy-pasteable values
171+
- Include example GitHub Actions workflow
172+
- Link to documentation
173+
174+
23. **REQ-DEPLOY-002**: Rollback Capability
175+
- Track created resources via tags
176+
- Remove IAM roles, policies, OIDC providers
177+
- Remove GitHub repository variables
178+
- Graceful partial rollback handling
179+
180+
**Phase 7 Rationale**: These features enhance security, usability, and maintainability but aren't required for basic functionality.
181+
182+
## TDD Red-Green-Refactor Workflow
183+
184+
For each requirement, follow this strict cycle:
185+
186+
### Red Phase: Write Failing Test
187+
```bash
188+
# Example for REQ-CLI-001
189+
describe('REQ-CLI-001: Toolkit Command Structure', () => {
190+
it('should register oidc command in command selector', () => {
191+
// This test should FAIL initially
192+
expect(commandSelector.hasCommand('oidc')).toBe(true);
193+
});
194+
});
195+
196+
# Run test - should fail
197+
npm test -- --grep "REQ-CLI-001"
198+
```
199+
200+
### Green Phase: Minimal Implementation
201+
```bash
202+
# Write just enough code to make test pass
203+
# Focus on making it work, not making it perfect
204+
205+
# Run test - should pass
206+
npm test -- --grep "REQ-CLI-001"
207+
```
208+
209+
### Refactor Phase: Clean Up
210+
```bash
211+
# Improve code quality without changing functionality
212+
# Extract methods, improve naming, add comments
213+
214+
# Run ALL tests - should still pass
215+
npm test
216+
```
217+
218+
### Integration Check
219+
```bash
220+
# Test actual command functionality
221+
claude-dev-toolkit oidc --help
222+
claude-dev-toolkit oidc --dry-run
223+
```
224+
225+
## Testing Strategy by Phase
226+
227+
### Phase 1 Testing
228+
- **Mock Dependencies**: Mock toolkit framework, AWS CLI, GitHub CLI
229+
- **Error Scenarios**: Test missing tools, invalid configurations
230+
- **Integration**: Verify command registration and help text
231+
232+
### Phase 2 Testing
233+
- **Mock External Commands**: Mock `git remote`, AWS config file reads
234+
- **Edge Cases**: Various git remote formats, missing AWS config
235+
- **Auto-detection Logic**: Test different repository and AWS setups
236+
237+
### Phase 3 Testing
238+
- **Mock AWS API Calls**: Mock IAM operations, OIDC provider creation
239+
- **Policy Generation**: Test template selection and policy creation
240+
- **Dry-run Validation**: Verify output accuracy without side effects
241+
242+
### Phase 4 Testing
243+
- **File System Mocking**: Mock policy file reads, directory traversal
244+
- **Validation Logic**: Test JSON parsing, IAM policy structure validation
245+
- **Policy Merging**: Test combining multiple policies correctly
246+
247+
### Phase 5 Testing
248+
- **GitHub API Mocking**: Mock `gh` CLI commands and responses
249+
- **Failure Scenarios**: Test partial failures and recovery instructions
250+
- **State Management**: Test detection and update of existing resources
251+
252+
### Phase 6 Testing
253+
- **Network Mocking**: Mock HTTPS policy fetching
254+
- **CloudFormation**: Mock stack operations and template generation
255+
- **Service Integration**: Test dynamic permission addition
256+
257+
### Phase 7 Testing
258+
- **Security Hooks**: Test hook integration and failure handling
259+
- **User Experience**: Test progress indicators and output formatting
260+
- **Rollback Operations**: Test resource cleanup and state tracking
261+
262+
## Implementation Dependencies
263+
264+
### Prerequisites for Each Phase:
265+
- **Phase 2**: Requires Phase 1 (command structure for testing)
266+
- **Phase 3**: Requires Phase 1 & 2 (error handling + auto-detection)
267+
- **Phase 4**: Requires Phase 3 (basic policy system)
268+
- **Phase 5**: Requires Phase 3 (working AWS OIDC setup)
269+
- **Phase 6**: Requires Phase 4 (advanced policy features)
270+
- **Phase 7**: Requires Phase 5 (complete core functionality)
271+
272+
### Critical Path:
273+
CLI Structure → Detection → Basic OIDC → GitHub Integration → Advanced Features → Production Polish
274+
275+
## Key Implementation Questions
276+
277+
Before starting implementation, clarify:
278+
279+
1. **Testing Framework**: What testing framework does the toolkit use?
280+
2. **Mocking Strategy**: How are external CLI tools currently mocked?
281+
3. **Existing Patterns**: Which toolkit commands should be referenced for patterns?
282+
4. **Error Standards**: What's the expected error object structure?
283+
5. **CI Integration**: How should tests integrate with existing CI pipeline?
284+
285+
## Success Criteria
286+
287+
After each phase, these should work:
288+
- **Phase 1**: `claude-dev-toolkit oidc --help`
289+
- **Phase 2**: `claude-dev-toolkit oidc --dry-run` (with auto-detection)
290+
- **Phase 3**: Full dry-run with policy generation
291+
- **Phase 4**: Custom policy support in dry-run mode
292+
- **Phase 5**: Complete OIDC setup (real execution)
293+
- **Phase 6**: Advanced features functional
294+
- **Phase 7**: Production-ready with all polish features
295+
296+
## Implementation Notes
297+
298+
- **Test Coverage**: Aim for 100% test coverage on each requirement before proceeding
299+
- **Documentation**: Update command documentation as features are implemented
300+
- **Integration Testing**: After each phase, test with real repositories and AWS accounts
301+
- **Performance**: Monitor command performance and optimize as needed
302+
- **Security Review**: Conduct security review after Phase 5 and Phase 7
303+
304+
This plan ensures systematic, test-driven development that builds confidence at each step while maintaining the ability to debug and iterate quickly.

0 commit comments

Comments
 (0)