|
| 1 | +--- |
| 2 | +name: Test Generator for MicroShift Features (Detailed test cases & Robot framework code) |
| 3 | +argument-hint: JIRA-TICKET-ID |
| 4 | +description: Generate Test Cases for a given Jira OCPSTRAT ticket & automates them using RobotFramework |
| 5 | +allowed-tools: WebFetch, Bash, Read, Write, Glob, Grep |
| 6 | +interaction: Ask user for confirmation before creating git branch |
| 7 | +--- |
| 8 | + |
| 9 | +# Robot Framework Test Generator for MicroShift/OpenShift |
| 10 | + |
| 11 | +Generate comprehensive Robot Framework test coverage for MicroShift/OpenShift features based on Jira OCPSTRAT tickets. |
| 12 | + |
| 13 | +## Workflow: |
| 14 | + |
| 15 | +### Step 1: Analyze OCPSTRAT Ticket |
| 16 | +- Fetch the Jira ticket from https://issues.redhat.com/browse/$1 |
| 17 | +- Extract feature description, acceptance criteria, and technical details |
| 18 | +- Identify all linked USHIFT tickets (look in "Issue Links" section) |
| 19 | +- Find GitHub PR links from USHIFT tickets or OCPSTRAT ticket |
| 20 | + |
| 21 | +**VALIDATION - Check for sufficient information**: |
| 22 | +After analyzing the ticket, verify: |
| 23 | +1. **Description Quality**: Does the ticket have detailed description, acceptance criteria, or technical implementation details? |
| 24 | +2. **PR Links**: Are there any useful GitHub PR links in the OCPSTRAT ticket or linked USHIFT tickets? |
| 25 | + |
| 26 | +**If BOTH conditions fail** (no detailed description AND no PR links): |
| 27 | +- ⚠️ **Ask user for additional information**: |
| 28 | + "The OCPSTRAT ticket lacks detailed information for test generation. It's missing: |
| 29 | + - Detailed feature description or acceptance criteria |
| 30 | + - Linked USHIFT tickets with GitHub PRs |
| 31 | + |
| 32 | + Please provide ONE of the following to continue: |
| 33 | + 1. A link to documentation (PR description, GitHub .md files, design docs) |
| 34 | + 2. A brief description of the feature functionality and expected behavior |
| 35 | + 3. Additional context about what this feature does |
| 36 | + |
| 37 | + Or type 'skip' to proceed with limited information (may result in generic tests)." |
| 38 | + |
| 39 | +- **Wait for user response**: |
| 40 | + - If user provides documentation link: Fetch and analyze it |
| 41 | + - If user provides description: Use it as supplementary context |
| 42 | + - If user types 'skip': Proceed with warning that tests may be generic |
| 43 | + |
| 44 | +**If at least ONE condition passes**, proceed to Step 2. |
| 45 | + |
| 46 | +### Step 2: Analyze Existing Test Coverage |
| 47 | +- For each GitHub PR found, check if it contains Robot Framework test files (*.robot) |
| 48 | +- Note the test file names and their location in the PR |
| 49 | +- Read and analyze existing test cases to understand what's already covered |
| 50 | +- Identify functionality already covered by existing tests |
| 51 | + |
| 52 | +### Step 3: Generate Top 10 Most Impactful Missing Tests |
| 53 | + |
| 54 | +**Create test case document in current working directory**: `test_cases_OCPSTRAT-XXXX.md` |
| 55 | + |
| 56 | +Focus ONLY on the **10 most impactful test scenarios NOT already covered**: |
| 57 | + |
| 58 | +1. **Core Functionality** - Primary use cases not tested |
| 59 | +2. **Configuration Edge Cases** - Invalid/boundary configurations not covered |
| 60 | +3. **Dynamic Behavior** - Runtime changes, reloads not tested |
| 61 | +4. **Integration Gaps** - Component interactions not validated |
| 62 | +5. **Multi-tenant/Namespace** - Cross-namespace scenarios missing |
| 63 | +6. **Error Handling** - Failure modes not covered |
| 64 | +7. **Upgrade/Compatibility** - Version compatibility gaps |
| 65 | +8. **Performance** - Load/scale testing if missing |
| 66 | +9. **Security** - Permission/isolation tests not present |
| 67 | +10. **Real Customer Scenarios** - Use cases from RFE not tested |
| 68 | + |
| 69 | +For each test, provide: |
| 70 | +- **Test ID**: USHIFT-XXX-TC-YYY (using the USHIFT ticket number) |
| 71 | +- **Priority**: Critical/High/Medium |
| 72 | +- **Coverage Gap**: What existing tests don't cover |
| 73 | +- **Test Description**: Clear objective |
| 74 | +- **Steps to Reproduce**: Concrete test steps with actual config/commands |
| 75 | +- **Expected Results**: Expected outcome for each step |
| 76 | + |
| 77 | +### Step 4: Create Robot Framework Test Files |
| 78 | + |
| 79 | +**BEFORE writing any tests:** |
| 80 | +1. Search for existing keyword files in the codebase |
| 81 | +2. Identify reusable keywords for common operations |
| 82 | +3. Check for existing resource files and utilities |
| 83 | +4. Use Grep/Glob to find similar test patterns |
| 84 | + |
| 85 | +Common keyword locations to check: |
| 86 | +- `test/extended/util/*.robot` - Utility keywords |
| 87 | +- `resources/**/*.robot` - Shared resource files |
| 88 | +- Existing test files in same feature area |
| 89 | + |
| 90 | +**When creating tests:** |
| 91 | +- ✅ **REUSE** existing keywords whenever possible |
| 92 | +- ❌ **DON'T** create duplicate keywords that already exist |
| 93 | +- ✅ **EXTEND** existing keyword files if new keywords are truly needed |
| 94 | +- ❌ **DON'T** reinvent common operations (oc commands, pod management, etc.) |
| 95 | + |
| 96 | +**Robot Framework Test File Creation Process:** |
| 97 | +- Generate test case documentation in current working directory as `test_cases_OCPSTRAT-XXXX.md` |
| 98 | +- Robot Framework test files will be created in microshift repository AFTER git branch is created in Step 5 |
| 99 | +- Follow microshift repo naming convention: lowercase with hyphens (kebab-case) |
| 100 | + - Example files in microshift: `backup-restore-on-reboot.robot`, `multi-nic.robot`, `isolated-network.robot` |
| 101 | +- If Robot Framework tests exist in PRs, create files with matching names |
| 102 | +- If no existing Robot tests, create new file in appropriate `test/suites/<category>/` subdirectory: |
| 103 | + - For DNS/network features: `test/suites/network/<feature-name>.robot` (e.g., `coredns-hosts-file.robot`) |
| 104 | + - Use feature-based naming: `<feature-name>.robot` (kebab-case, lowercase) |
| 105 | +- Implement the top 3-5 most critical missing tests in Robot Framework |
| 106 | +- Follow existing patterns from similar test files in microshift codebase |
| 107 | +- Include proper setup, teardown, and error handling |
| 108 | + |
| 109 | +**CRITICAL Robot Framework Teardown Rules** (from `.cursor/rules/robot-framework-teardown.md` in the microshift repository): |
| 110 | +- ✅ **DO**: Write clean teardowns without `Run Keyword And Ignore Error` |
| 111 | +- ❌ **DON'T**: Use `Run Keyword And Ignore Error` in ANY teardown section |
| 112 | +- Robot Framework teardowns automatically continue execution even if keywords fail |
| 113 | +- This applies to: `[Teardown]`, `Suite Teardown`, `Test Teardown`, and keyword teardowns |
| 114 | +- Only use `Run Keyword And Ignore Error` in test cases/setup when you need conditional logic |
| 115 | + |
| 116 | +**Correct Teardown Example**: |
| 117 | +```robot |
| 118 | +Suite Teardown Cleanup Test Resources |
| 119 | +
|
| 120 | +Cleanup Test Resources |
| 121 | + [Documentation] Clean up all test resources |
| 122 | + Oc Delete pod --all -n ${NAMESPACE} |
| 123 | + Remove Test Files |
| 124 | + Restart MicroShift |
| 125 | +``` |
| 126 | + |
| 127 | +**Incorrect Teardown (DON'T DO THIS)**: |
| 128 | +```robot |
| 129 | +Suite Teardown Run Keyword And Ignore Error Cleanup Test Resources |
| 130 | +
|
| 131 | +Cleanup Test Resources |
| 132 | + Run Keyword And Ignore Error Oc Delete pod --all -n ${NAMESPACE} |
| 133 | + Run Keyword And Ignore Error Remove Test Files |
| 134 | +``` |
| 135 | + |
| 136 | +**Keyword Reuse Example**: |
| 137 | +```robot |
| 138 | +# ✅ GOOD - Reusing existing keywords |
| 139 | +*** Test Cases *** |
| 140 | +Test CoreDNS Hosts File |
| 141 | + [Documentation] Test hosts file resolution |
| 142 | + Setup MicroShift Config dns.hostsFile=/etc/custom-hosts |
| 143 | + Restart MicroShift |
| 144 | + Wait For MicroShift Ready |
| 145 | + Deploy Test Pod dns-test ${NAMESPACE} |
| 146 | + ${ip}= Resolve Hostname In Pod dns-test ${NAMESPACE} test.local |
| 147 | + Should Be Equal ${ip} 192.168.1.100 |
| 148 | +
|
| 149 | +# ❌ BAD - Creating duplicate keywords |
| 150 | +*** Keywords *** |
| 151 | +My Custom MicroShift Restart |
| 152 | + [Documentation] Restart MicroShift (DON'T DO THIS - use existing keyword!) |
| 153 | + Run Process systemctl restart microshift |
| 154 | + Sleep 10s |
| 155 | +``` |
| 156 | + |
| 157 | +### Step 5: Create Git Branch and Robot Framework Tests in MicroShift Repository |
| 158 | + |
| 159 | +**IMPORTANT**: Before creating git branch, **WAIT for user confirmation**. |
| 160 | + |
| 161 | +Ask user for confirmation: |
| 162 | + |
| 163 | +**Prompt user**: "Would you like me to create a new git branch in the microshift repository? The branch will be named `test-OCPSTRAT-XXXX-$(date +%Y%m%d)`. (yes/no)" |
| 164 | + |
| 165 | +**If user confirms (yes)**: |
| 166 | + |
| 167 | +#### 5.1: Create Git Branch |
| 168 | +1. Ask user for the microshift repository path on their system |
| 169 | +2. Navigate to the microshift repository |
| 170 | +3. Check current git status |
| 171 | +4. Create new branch: `test-OCPSTRAT-XXXX-$(date +%Y%m%d)` |
| 172 | +5. Confirm branch creation and provide branch name |
| 173 | + |
| 174 | +**Prompt user**: "Please provide the full path to your microshift repository (e.g., /home/username/microshift):" |
| 175 | + |
| 176 | +**Commands** (use the path provided by user): |
| 177 | +```bash |
| 178 | +cd <user-provided-microshift-repo-path> |
| 179 | +git status |
| 180 | +git checkout -b test-OCPSTRAT-XXXX-$(date +%Y%m%d) |
| 181 | +git branch --show-current |
| 182 | +``` |
| 183 | + |
| 184 | +#### 5.2: Create Robot Framework Test Files in the New Branch |
| 185 | + |
| 186 | +After branch is created, create Robot Framework test file directly in the microshift repository: |
| 187 | + |
| 188 | +1. Determine appropriate test suite directory based on feature type |
| 189 | + - Network/DNS features: `test/suites/network/` |
| 190 | + - Storage features: `test/suites/storage/` |
| 191 | + - Backup features: `test/suites/backup/` |
| 192 | + - etc. |
| 193 | + |
| 194 | +2. Create the .robot file with kebab-case naming convention |
| 195 | + - Example: `test/suites/network/coredns-hosts-file.robot` |
| 196 | + |
| 197 | +3. Implement the top 3-5 most critical tests from Step 3 |
| 198 | + |
| 199 | +4. Add file to git staging |
| 200 | + |
| 201 | +**Commands** (use the user-provided microshift repository path): |
| 202 | +```bash |
| 203 | +# File will be created at appropriate path, e.g.: |
| 204 | +# <microshift-repo-path>/test/suites/network/<feature-name>.robot |
| 205 | + |
| 206 | +# After file is created, stage it |
| 207 | +cd <user-provided-microshift-repo-path> |
| 208 | +git add test/suites/<category>/<feature-name>.robot |
| 209 | +git status |
| 210 | +``` |
| 211 | + |
| 212 | +**Output to user**: |
| 213 | +- Branch created: test-OCPSTRAT-XXXX-YYYYMMDD |
| 214 | +- Repository: <user-provided-microshift-repo-path> |
| 215 | +- Current branch: [branch name] |
| 216 | +- Robot Framework test file created: test/suites/<category>/<feature-name>.robot |
| 217 | +- File staged for commit: Ready to commit |
| 218 | + |
| 219 | +### Step 6: Summary Report |
| 220 | +Provide: |
| 221 | +- List of USHIFT tickets and PRs analyzed |
| 222 | +- Existing test files found (with coverage summary) |
| 223 | +- Test case document (10 test cases) - filename and path |
| 224 | +- Robot Framework test files created (with test count) - filename and path |
| 225 | +- Git branch created (branch name and repository path) - if created |
| 226 | +- Coverage gaps addressed |
| 227 | +- Remaining gaps (if any) |
0 commit comments