|
| 1 | +# Implementation Validation Pattern |
| 2 | + |
| 3 | +When you find existing code that appears to implement the requested functionality, always validate that it actually works before claiming the task is complete. |
| 4 | + |
| 5 | +## The Problem |
| 6 | + |
| 7 | +Agents often discover existing implementations and immediately conclude the task is done without testing functionality. This leads to: |
| 8 | +- Claiming features work when they don't |
| 9 | +- Missing broken configurations that look correct in code |
| 10 | +- Failing to communicate actual task status clearly |
| 11 | +- Users left uncertain whether their request was fulfilled |
| 12 | + |
| 13 | +## The Validation Process |
| 14 | + |
| 15 | +### 1. Find the Implementation |
| 16 | + |
| 17 | +When you discover code that seems to match the requirements: |
| 18 | + |
| 19 | +```bash |
| 20 | +# Found redirect in next.config.mjs |
| 21 | +{ |
| 22 | + source: '/b/:hash', |
| 23 | + destination: 'https://go.trybeluga.ai/:hash', |
| 24 | + permanent: false, |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +### 2. Test the Actual Functionality |
| 29 | + |
| 30 | +Don't assume code works just because it exists. Test the user-facing behavior: |
| 31 | + |
| 32 | +```bash |
| 33 | +# For Next.js redirects - test the actual redirect |
| 34 | +curl -I http://localhost:3000/b/test123 |
| 35 | +# Should return 307/308 with Location header |
| 36 | + |
| 37 | +# For API endpoints - test the endpoint |
| 38 | +curl http://localhost:3000/api/endpoint |
| 39 | +# Should return expected response |
| 40 | + |
| 41 | +# For UI features - verify the user flow works |
| 42 | +``` |
| 43 | + |
| 44 | +### 3. Check Runtime vs Configuration |
| 45 | + |
| 46 | +Code existing ≠ code working. Verify the implementation is active: |
| 47 | + |
| 48 | +- **Next.js redirects**: Must be in active config AND server restarted |
| 49 | +- **API routes**: File must exist in correct location AND export right methods |
| 50 | +- **Features**: Code must be imported/called from the right places |
| 51 | +- **Environment**: Required env vars, database state, etc. |
| 52 | + |
| 53 | +### 4. Validate Against Exact Requirements |
| 54 | + |
| 55 | +Even working code might not match the specific requirements: |
| 56 | + |
| 57 | +- **URL patterns**: `/b/:hash` vs `/b/:id` vs `/buffer/:hash` |
| 58 | +- **Destinations**: `https://go.trybeluga.ai/:hash` vs other domains |
| 59 | +- **Behavior**: temporary vs permanent redirects, query handling |
| 60 | + |
| 61 | +## Response Patterns |
| 62 | + |
| 63 | +### ✅ When Implementation Works |
| 64 | + |
| 65 | +``` |
| 66 | +I found the redirect configuration in next.config.mjs and verified it works: |
| 67 | +
|
| 68 | +[show the existing code] |
| 69 | +
|
| 70 | +Testing confirms functionality: |
| 71 | +$ curl -I http://localhost:3000/b/test123 |
| 72 | +HTTP/1.1 307 Temporary Redirect |
| 73 | +Location: https://go.trybeluga.ai/test123 |
| 74 | +
|
| 75 | +The feature is already implemented and working correctly. |
| 76 | +``` |
| 77 | + |
| 78 | +### ✅ When Implementation Exists But Broken |
| 79 | + |
| 80 | +``` |
| 81 | +I found redirect configuration in next.config.mjs, but testing shows it's not working: |
| 82 | +
|
| 83 | +[show the existing code] |
| 84 | +
|
| 85 | +Testing reveals the issue: |
| 86 | +$ curl -I http://localhost:3000/b/test123 |
| 87 | +HTTP/1.1 404 Not Found |
| 88 | +
|
| 89 | +The server needs to be restarted for redirects to take effect. |
| 90 | +After restart, the redirect works correctly. |
| 91 | +``` |
| 92 | + |
| 93 | +### ✅ When Implementation Is Missing |
| 94 | + |
| 95 | +``` |
| 96 | +I need to add the redirect configuration to next.config.mjs: |
| 97 | +
|
| 98 | +[show the changes being made] |
| 99 | +
|
| 100 | +This will redirect /b/:hash to https://go.trybeluga.ai/:hash as requested. |
| 101 | +``` |
| 102 | + |
| 103 | +## Testing Strategies by Feature Type |
| 104 | + |
| 105 | +### Web Redirects |
| 106 | +```bash |
| 107 | +curl -I http://localhost:PORT/path |
| 108 | +# Check status code (307/308) and Location header |
| 109 | +``` |
| 110 | + |
| 111 | +### API Endpoints |
| 112 | +```bash |
| 113 | +curl http://localhost:PORT/api/endpoint |
| 114 | +# Check response status and body |
| 115 | +``` |
| 116 | + |
| 117 | +### Database Features |
| 118 | +```bash |
| 119 | +# Check if tables/columns exist |
| 120 | +# Verify data can be inserted/queried |
| 121 | +# Test constraints and relationships |
| 122 | +``` |
| 123 | + |
| 124 | +### UI Components |
| 125 | +```bash |
| 126 | +# Start dev server and manually test |
| 127 | +# Or run existing test suite |
| 128 | +bun test path/to/feature.test.ts |
| 129 | +``` |
| 130 | + |
| 131 | +## Use Existing Tests When Available |
| 132 | + |
| 133 | +If tests exist for the feature: |
| 134 | + |
| 135 | +1. **Read the test file** to understand expected behavior |
| 136 | +2. **Run the tests** to verify current implementation |
| 137 | +3. **Report test results** as evidence of functionality |
| 138 | + |
| 139 | +Example: |
| 140 | +```typescript |
| 141 | +test('redirects to go.trybeluga.ai with the hash', async ({ request }) => { |
| 142 | + const response = await request.get('/b/test123', { maxRedirects: 0 }) |
| 143 | + expect(response.status()).toBe(307) |
| 144 | + expect(response.headers()['location']).toBe('https://go.trybeluga.ai/test123') |
| 145 | +}) |
| 146 | +``` |
| 147 | + |
| 148 | +If these tests exist and pass, the feature is confirmed working. |
| 149 | + |
| 150 | +## Anti-Patterns to Avoid |
| 151 | + |
| 152 | +❌ **Assuming functionality without testing**: |
| 153 | +``` |
| 154 | +"The redirect is already implemented in next.config.mjs. No changes needed." |
| 155 | +// Without actually verifying it works |
| 156 | +``` |
| 157 | + |
| 158 | +❌ **Confusing configuration with functionality**: |
| 159 | +``` |
| 160 | +// Code exists in config file ≠ feature works at runtime |
| 161 | +``` |
| 162 | + |
| 163 | +❌ **Silent completion without communication**: |
| 164 | +``` |
| 165 | +// Making no changes and not explaining why |
| 166 | +// Leaving user unsure if their request was handled |
| 167 | +``` |
| 168 | + |
| 169 | +## Key Principle |
| 170 | + |
| 171 | +**Code that looks right might not work right.** Always test the actual user-facing behavior before claiming a feature is complete. When in doubt, verify through testing rather than code inspection alone. |
0 commit comments