diff --git a/CLAUDE.md b/CLAUDE.md index 50070e6..9e6f567 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,6 +6,246 @@ > 3. `docs/jobs.md` - Filesystem state layout > 4. `docs/config.md` - Configuration options +--- + +## Ticket Implementation Process (MANDATORY) + +When assigned a GitHub issue/ticket, follow this **exact process**. Do NOT skip steps. + +### Phase 1: READ (Do Not Write Any Code Yet) + +``` +┌─────────────────────────────────────────────────────────────┐ +│ STOP! Read everything before writing a single line of code │ +└─────────────────────────────────────────────────────────────┘ +``` + +**Step 1.1: Fetch and Read the Ticket** +```bash +gh issue view +``` + +Read the ENTIRE ticket including: +- Overview and Context +- Requirements (every numbered item) +- Acceptance Criteria (every checkbox) +- Implementation Notes +- Tests Required + +**Step 1.2: Check Dependencies** +```bash +# List dependency issues +gh issue view --json body | grep -o '#[0-9]*' + +# Check if dependencies are closed +gh issue view --json state +``` + +If dependencies are NOT closed: **STOP**. Work on dependencies first or inform the user. + +**Step 1.3: Read Referenced Documentation** + +The ticket's "Context" section lists docs to read. Read ALL of them: +```bash +# Example: if ticket says "Read first: docs/jobs.md" +cat docs/jobs.md +``` + +**Step 1.4: Read Related Existing Code** + +If the ticket depends on other issues, read the code they produced: +```bash +# Find relevant files +find src -name "*.java" | xargs grep -l "RelatedClass" +``` + +### Phase 2: PLAN (Still No Implementation Code) + +**Step 2.1: List All Deliverables** + +Extract from the ticket: +- [ ] Classes/files to create +- [ ] Methods to implement +- [ ] Tests to write +- [ ] Acceptance criteria to satisfy + +**Step 2.2: Identify Test Cases** + +From the "Tests Required" section, list every test: +``` +Example: +- JobManagerTest.java + - createJob_withValidCommand_shouldReturnJobWithUniqueId + - createJob_withNullCommand_shouldThrowNullPointerException + - findJob_withExistingId_shouldReturnJob + - findJob_withMissingId_shouldReturnEmpty +``` + +### Phase 3: TEST (Write Tests FIRST) + +``` +┌─────────────────────────────────────────────────────────┐ +│ Write ALL tests before writing ANY implementation code │ +└─────────────────────────────────────────────────────────┘ +``` + +**Step 3.1: Create Test File** +```java +// src/test/java/com/samsonmedia/barn//Test.java +class JobManagerTest { + @Test + void methodName_condition_expectedResult() { + // Arrange + // Act + // Assert - use AssertJ + } +} +``` + +**Step 3.2: Write ALL Test Cases** + +Write tests for: +1. Happy path (normal success) +2. Edge cases (empty, boundary values) +3. Error cases (null, invalid state) +4. Every acceptance criterion + +**Step 3.3: Run Tests (Must FAIL)** +```bash +mvn test -Dtest= +# Expected: FAILURE (code not implemented yet) +``` + +If tests pass before implementation, the tests are wrong. + +### Phase 4: IMPLEMENT (Now Write Code) + +**Step 4.1: Implement Minimum Code** + +Write the minimum code to make ONE test pass at a time: +```bash +# After each small change +mvn test -Dtest=# +``` + +**Step 4.2: Follow Coding Standards** + +Every file must: +- Have no wildcard imports +- Use `Optional` not null returns +- Use `Objects.requireNonNull()` for parameters +- Use `final` for immutable fields +- Have proper Javadoc on public methods + +**Step 4.3: Iterate Until All Tests Pass** +```bash +mvn test -Dtest= +# Expected: SUCCESS for all tests +``` + +### Phase 5: VERIFY (Full Quality Check) + +**Step 5.1: Run Full Verification** +```bash +mvn verify +``` + +This MUST pass: +- ✓ Checkstyle (formatting) +- ✓ Compilation (no warnings) +- ✓ All unit tests +- ✓ SpotBugs (no bugs) +- ✓ PMD (no violations) +- ✓ JaCoCo (80%+ coverage) + +**Step 5.2: Check Acceptance Criteria** + +Go through EVERY checkbox in the ticket: +``` +- [ ] Criterion 1 → Verify manually or with test +- [ ] Criterion 2 → Verify manually or with test +... +``` + +**Step 5.3: Fix Any Issues** + +If `mvn verify` fails: +1. Read the error message +2. Fix the issue +3. Run `mvn verify` again +4. Repeat until clean + +### Phase 6: COMPLETE (Commit and Close) + +**Step 6.1: Commit with Conventional Message** +```bash +git add . +git commit -m "feat(): + +Implements # + +- Added +- Implemented +- Tests for + +Co-Authored-By: Claude " +``` + +**Step 6.2: Verify Commit** +```bash +# Ensure nothing is missed +git status +mvn verify # Run one final time +``` + +**Step 6.3: Close the Ticket** +```bash +gh issue close --comment "Implemented in commit " +``` + +--- + +## Ticket Process Checklist + +Copy this checklist for each ticket: + +```markdown +## Ticket #XX: + +### Phase 1: READ +- [ ] Fetched ticket with `gh issue view` +- [ ] Read entire ticket description +- [ ] Checked all dependencies are closed +- [ ] Read all referenced documentation +- [ ] Read related existing code + +### Phase 2: PLAN +- [ ] Listed all classes/files to create +- [ ] Listed all methods to implement +- [ ] Listed all test cases from ticket + +### Phase 3: TEST +- [ ] Created test file(s) +- [ ] Wrote all test cases +- [ ] Tests fail (code not implemented) + +### Phase 4: IMPLEMENT +- [ ] Implemented code to pass tests +- [ ] All tests pass +- [ ] Followed coding standards + +### Phase 5: VERIFY +- [ ] `mvn verify` passes +- [ ] All acceptance criteria checked +- [ ] No TODO/FIXME without issue + +### Phase 6: COMPLETE +- [ ] Committed with conventional message +- [ ] Closed ticket with `gh issue close` +``` + +--- + ## Critical Requirements ### 1. ALWAYS Write Tests First @@ -378,3 +618,144 @@ mvn compile spotbugs:gui 4. Will this survive a crash/restart? 5. Can the state be manually inspected in the filesystem? 6. Does `mvn verify` pass? + +--- + +## Working with GitHub Issues + +### Viewing the Backlog + +```bash +# List all open issues +gh issue list + +# List issues by milestone +gh issue list --milestone "M1: Foundation" + +# List issues by label +gh issue list --label "foundation" + +# View specific issue +gh issue view 1 +``` + +### Dependency Graph + +Issues must be completed in dependency order. The milestones define the general order: + +``` +M1: Foundation (#1, #2, #3, #4, #22) + ↓ +M2: Job Execution (#5, #6, #7, #20) + ↓ +M3: CLI Commands (#8, #9, #10, #11, #12, #13, #21) + ↓ +M4: Service Infrastructure (#14, #15, #16) + ↓ +M5: Platform Integration (#17, #18, #19) +``` + +**Recommended order within M1:** +``` +#1 (project structure) + → #22 (logging) + → #2 (configuration) + → #3 (filesystem state) + → #4 (job model) +``` + +### Starting a New Ticket + +```bash +# 1. Check what's ready to work on (no open dependencies) +gh issue list --milestone "M1: Foundation" --state open + +# 2. Pick the next ticket with closed dependencies +gh issue view 1 + +# 3. Follow the Ticket Implementation Process above +``` + +### Progress Tracking + +After completing a ticket: +```bash +# Close with comment +gh issue close <number> --comment "Implemented in commit abc123" + +# Verify milestone progress +gh issue list --milestone "M1: Foundation" +``` + +--- + +## Emergency Procedures + +### If `mvn verify` Fails + +1. **Read the error** - Don't guess, read the actual message +2. **Identify the phase** - Checkstyle? Compile? Test? SpotBugs? PMD? JaCoCo? +3. **Fix incrementally** - Run just that check until it passes: + ```bash + mvn checkstyle:check # Formatting issues + mvn compile # Compilation errors + mvn test # Test failures + mvn spotbugs:check # Bug detection + mvn pmd:check # Static analysis + mvn jacoco:check # Coverage issues + ``` +4. **Run full verify again** - `mvn verify` + +### If Tests Won't Pass + +1. **Check the test is correct** - Is the expected behavior right? +2. **Check dependencies** - Is required code from other tickets present? +3. **Check test isolation** - Does the test depend on external state? +4. **Run single test** - `mvn test -Dtest=ClassName#methodName` + +### If Stuck on a Ticket + +1. **Re-read the ticket** - Often the answer is in the description +2. **Check Implementation Notes** - Specific guidance is provided +3. **Check referenced docs** - Context section lists what to read +4. **Look at similar code** - How did other tickets solve similar problems? + +--- + +## Ticket Template Reference + +Every ticket follows this structure: + +```markdown +## Overview +Brief description of what to implement. + +## Context +- **Read first**: docs to read before starting +- **Depends on**: prerequisite tickets + +## Requirements +### 1. Component Name +Detailed requirements with code examples. + +### 2. Another Component +More requirements... + +## Tests Required +- TestClass1.java: description +- TestClass2.java: description + +## Acceptance Criteria +- [ ] Criterion 1 +- [ ] Criterion 2 +- [ ] `mvn verify` passes +- [ ] Tests have 80%+ coverage + +## Implementation Notes +Specific guidance, code patterns, edge cases. + +## Definition of Done +Summary of completion requirements. +``` + +Use this structure to know exactly what's expected.