|
| 1 | +# Existing Implementation Validation Pattern |
| 2 | + |
| 3 | +When you discover existing code that appears to implement the requested functionality, validate three things: location correctness, functionality, and clear communication to the user. |
| 4 | + |
| 5 | +## The Problem |
| 6 | + |
| 7 | +Agents often find existing implementations and immediately conclude the task is done without: |
| 8 | +- Verifying the implementation is in the correct location/context |
| 9 | +- Testing that it actually works as expected |
| 10 | +- Clearly communicating the task status to the user |
| 11 | + |
| 12 | +This leads to: |
| 13 | +- Missing implementations in the wrong location (main app vs specific sub-app) |
| 14 | +- Assuming code works without verification |
| 15 | +- Silent completion that leaves users uncertain |
| 16 | + |
| 17 | +## The Three-Step Validation Process |
| 18 | + |
| 19 | +### 1. Location Validation |
| 20 | + |
| 21 | +Even if the functionality exists somewhere in the codebase, verify it's in the RIGHT place: |
| 22 | + |
| 23 | +```bash |
| 24 | +# Task: "Add redirects to freebuff/web/next.config.mjs" |
| 25 | +# Found: Redirects in web/next.config.mjs |
| 26 | +# Problem: Wrong location - freebuff/web is a separate app |
| 27 | +``` |
| 28 | + |
| 29 | +**Check:** |
| 30 | +- Is this the correct file path mentioned in the task? |
| 31 | +- Is this the right application/service (monorepo apps are separate) |
| 32 | +- Does the implementation serve the intended use case? |
| 33 | + |
| 34 | +### 2. Functionality Validation |
| 35 | + |
| 36 | +Don't assume existing code works. Test the actual behavior: |
| 37 | + |
| 38 | +```bash |
| 39 | +# For Next.js redirects |
| 40 | +curl -I http://localhost:PORT/b/test123 |
| 41 | +# Should return 307/308 with correct Location header |
| 42 | + |
| 43 | +# For API endpoints |
| 44 | +curl http://localhost:PORT/api/endpoint |
| 45 | +# Should return expected response |
| 46 | + |
| 47 | +# For features |
| 48 | +# Test the actual user-facing behavior |
| 49 | +``` |
| 50 | + |
| 51 | +**Verify:** |
| 52 | +- The implementation is active (not just configured) |
| 53 | +- It handles the exact patterns requested |
| 54 | +- Edge cases work (query parameters, special characters) |
| 55 | + |
| 56 | +### 3. Clear Communication |
| 57 | + |
| 58 | +Always explicitly tell the user what you found and what the status is: |
| 59 | + |
| 60 | +**✅ When implementation exists and works in the right place:** |
| 61 | +``` |
| 62 | +I found the redirect configuration in freebuff/web/next.config.mjs: |
| 63 | +
|
| 64 | +[show the code] |
| 65 | +
|
| 66 | +Testing confirms it works correctly: |
| 67 | +$ curl -I http://localhost:3001/b/test123 |
| 68 | +HTTP/1.1 307 Temporary Redirect |
| 69 | +Location: https://go.trybeluga.ai/test123 |
| 70 | +
|
| 71 | +The feature is already implemented and functional. No changes needed. |
| 72 | +``` |
| 73 | + |
| 74 | +**✅ When implementation exists but in wrong location:** |
| 75 | +``` |
| 76 | +I found redirect configuration in the main web/next.config.mjs, but the task requires it in freebuff/web/next.config.mjs (separate app). |
| 77 | +
|
| 78 | +Adding the redirect to freebuff/web/next.config.mjs: |
| 79 | +
|
| 80 | +[show the changes] |
| 81 | +
|
| 82 | +This will enable the redirect specifically for the freebuff web app. |
| 83 | +``` |
| 84 | + |
| 85 | +**✅ When implementation doesn't exist:** |
| 86 | +``` |
| 87 | +I need to add the redirect configuration to freebuff/web/next.config.mjs: |
| 88 | +
|
| 89 | +[show the changes] |
| 90 | +
|
| 91 | +This will redirect /b/:hash to https://go.trybeluga.ai/:hash as requested. |
| 92 | +``` |
| 93 | + |
| 94 | +## Context-Specific Validation |
| 95 | + |
| 96 | +### Monorepo Applications |
| 97 | + |
| 98 | +In monorepos, similar functionality may exist in multiple apps: |
| 99 | +- `web/` - main application |
| 100 | +- `freebuff/web/` - separate free tier app |
| 101 | +- Each has its own `next.config.mjs`, `package.json`, etc. |
| 102 | + |
| 103 | +**Always check the specific path mentioned in the task.** |
| 104 | + |
| 105 | +### Configuration vs Runtime |
| 106 | + |
| 107 | +Configuration existing ≠ feature working: |
| 108 | +- **Next.js redirects:** Must be in active config AND server restarted |
| 109 | +- **API routes:** Must be in correct location AND export right methods |
| 110 | +- **Environment variables:** Must be set in runtime environment |
| 111 | + |
| 112 | +### Test Coverage |
| 113 | + |
| 114 | +If tests exist, use them as validation: |
| 115 | +```typescript |
| 116 | +// If you find tests like this: |
| 117 | +test('redirects to go.trybeluga.ai with the hash', async ({ request }) => { |
| 118 | + const response = await request.get('/b/test123', { maxRedirects: 0 }) |
| 119 | + expect(response.status()).toBe(307) |
| 120 | + expect(response.headers()['location']).toBe('https://go.trybeluga.ai/test123') |
| 121 | +}) |
| 122 | + |
| 123 | +// Run them to verify functionality |
| 124 | +bun test path/to/redirect.test.ts |
| 125 | +``` |
| 126 | + |
| 127 | +## Anti-Patterns to Avoid |
| 128 | + |
| 129 | +❌ **Silent assumption:** |
| 130 | +``` |
| 131 | +// Found redirect in web/next.config.mjs, task must be done |
| 132 | +// (Without checking if it's the right location or communicating status) |
| 133 | +``` |
| 134 | + |
| 135 | +❌ **Location confusion:** |
| 136 | +``` |
| 137 | +// Task asks for freebuff/web/next.config.mjs |
| 138 | +// Found in web/next.config.mjs |
| 139 | +// Assumed they're the same thing |
| 140 | +``` |
| 141 | + |
| 142 | +❌ **No status communication:** |
| 143 | +``` |
| 144 | +// Making no changes without explaining why |
| 145 | +// User left wondering if their request was handled |
| 146 | +``` |
| 147 | + |
| 148 | +## Key Principle |
| 149 | + |
| 150 | +**Existing code is only a solution if it's in the right place, works correctly, and serves the intended use case.** Always validate all three before claiming task completion. |
0 commit comments