-
Notifications
You must be signed in to change notification settings - Fork 37
fix: test isolation and proper error handling for constraint violations #600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This commit addresses test isolation issues and improves error handling: **Test Isolation Fix:** - Fixed vitest.config.ts: Changed `isolate: false` to `isolate: true` - Previously, all test files shared the same in-memory database worker context - This caused spurious SQLITE_CONSTRAINT_PRIMARYKEY errors across tests - Now each test file gets its own isolated database instance **Error Handling Improvements:** - Fixed projects.ts: Corrected SQLite error detection - Changed from checking `error.code` to `error.cause.code` - Now properly returns 409 Conflict for duplicate project IDs instead of 500 - SQLite constraint violations are in `error.cause.code`, not `error.code` **Test Quality:** - Removed workaround in projects.test.ts that accepted both 409 and 500 - Tests now strictly expect correct HTTP status codes - Reduced test output noise by using debug level for expected tool discovery failures in test environment **Test Results:** - All 371 tests passing (51 skipped) - Eliminated spurious primary key constraint errors - Dramatically reduced ERROR log output during test runs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
Claude finished @amikofalvy's task —— View job Code Review Complete ✅I've conducted a comprehensive review of the test isolation and error handling fixes. Here's my detailed analysis: SummaryThis is a high-quality, well-targeted fix that addresses two critical issues: test isolation problems and incorrect SQLite error handling. The changes are minimal, surgical, and thoroughly tested. ✅ Strengths1. Excellent Problem Identification & Root Cause Analysis
2. Surgical, Minimal Changes
3. Consistent Error Handling PatternThe fix aligns with existing codebase patterns. I found other files already using the correct
4. Proper Test Quality Improvements
🤔 Areas for Consideration1. Inconsistency Across ProjectsIssue: Risk: The same test isolation issues could occur in Recommendation: Consider updating 2. Incomplete Error Handling MigrationI found one location that might still have the old pattern:
Recommendation: Review and potentially update this to use 3. Error Structure DocumentationObservation: The SQLite error structure ( Suggestion: Consider adding a code comment explaining why 🏗️ Architectural ConsiderationsTest Isolation StrategyThe move to
Error Handling ConsistencyThe codebase now has a consistent approach to SQLite constraint handling, which is excellent for:
🧪 Testing ExcellenceTest Strategy
Test Quality ImprovementsThe removal of the 409/500 status code workaround is particularly good: // BEFORE (problematic workaround):
expect([409, 500]).toContain(res2.status);
// AFTER (correct validation):
expect(res2.status).toBe(409); 🔒 Security & Data IntegrityProper Constraint Validation
Database Safety
💡 Recommendations
🎯 ConclusionThis is an exemplary bug fix that demonstrates:
The changes are ready for production and will significantly improve test reliability and API error handling consistency. Recommendation: ✅ APPROVE - This PR addresses critical issues with surgical precision and excellent test coverage. |
Summary
This PR addresses critical test isolation issues and improves error handling in the agents-manage-api:
Test Isolation Fix ✅
vitest.config.ts
: Changedisolate: false
toisolate: true
SQLITE_CONSTRAINT_PRIMARYKEY
errors across unrelated testsError Handling Improvements ✅
src/routes/projects.ts
: Corrected SQLite error detection logicerror.code
instead oferror.cause.code
for SQLite constraint violationsTest Quality Improvements ✅
src/__tests__/routes/crud/projects.test.ts
: Removed workaround that masked the error handling bugpackages/agents-core/src/data-access/tools.ts
: Added conditional logging based onENVIRONMENT
variableTest Results
Technical Details
SQLite Error Structure:
Test Isolation:
Files Changed
agents-manage-api/vitest.config.ts
- Test isolation fixagents-manage-api/src/routes/projects.ts
- Error handling correctionagents-manage-api/src/__tests__/routes/crud/projects.test.ts
- Removed workaroundpackages/agents-core/src/data-access/tools.ts
- Conditional logging for testsFuture Work
A follow-up PR will address remaining instances where the API returns 500 for predictable errors (foreign key violations, validation errors) that should use proper HTTP status codes (400, 404, 409).
🤖 Generated with Claude Code