Repository navigation
Closed
Description
Critical: Test Environment Hiding Real Bugs
Related to: Issue #208 (Comprehensive Test Coverage)
Blocks: Issues #228-#233 (all bug fix issues)
Priority: CRITICAL - Must fix before working on other bug issues
Problem
The comprehensive tests are giving false confidence because:
- SharedNodeStore silently swallows database errors in tests (lines 352-360 in shared-node-store.ts)
- Tests don't wait for async database writes before checking persistence
- Result: Tests pass even when database persistence is broken!
This explains why:
- Tests show 93.3% pass rate
- Manual testing reveals basic bugs (create node fails)
- HTTP 500 errors in dev server logs are hidden from tests
Root Cause
1. Silent Error Swallowing
// shared-node-store.ts:352-360
} catch (dbError) {
// Only log database errors in non-test environments
// Tests run without Tauri and database writes are expected to fail
if (typeof process === 'undefined' || process.env.NODE_ENV \!== 'test') {
console.error(`[SharedNodeStore] Database write failed for node ${node.id}:`, dbError);
}
}This comment is WRONG: Tests DO have database access via HttpAdapter, but errors are hidden!
2. Race Conditions
// Test creates node (queues async database write)
const nodeId = service.createNode('node-1', '', 'text');
// IMMEDIATELY checks database (write might not be done\!)
const dbNode = await adapter.getNode(nodeId);
expect(dbNode).toBeDefined(); // ❌ May pass/fail randomlyImpact
CRITICAL: All test results in #208 are unreliable. Issues #228-#233 may have:
- False failures (race conditions)
- OR worse: Missing real failures (errors swallowed)
Solution
Part 1: Surface Database Errors in Tests
// In shared-node-store.ts, change error handler:
} catch (dbError) {
// Log in all environments
console.error(`[SharedNodeStore] Database write failed for node ${node.id}:`, dbError);
// In test environment, also track failures so tests can assert
if (typeof process \!== 'undefined' && process.env.NODE_ENV === 'test') {
// Store error for test verification
this.lastDatabaseError = dbError;
}
}Part 2: Add Wait Helper for Tests
// In test-database.ts or new test-helpers.ts
export async function waitForDatabaseWrites(maxWaitMs = 5000): Promise<void> {
// Wait for database write queue to flush
// Implementation options:
// 1. Poll SharedNodeStore.hasPendingWrites()
// 2. Add callback to queueDatabaseWrite completion
// 3. Simple timeout-based wait with verification
}Part 3: Update Test Pattern
// Before (race condition):
const nodeId = service.createNode('node-1', '', 'text');
const dbNode = await adapter.getNode(nodeId);
expect(dbNode).toBeDefined();
// After (properly waits):
const nodeId = service.createNode('node-1', '', 'text');
await waitForDatabaseWrites(); // ← Add this
const dbNode = await adapter.getNode(nodeId);
expect(dbNode).toBeDefined();Acceptance Criteria
- SharedNodeStore logs ALL database errors (including in tests)
- Tests fail visibly when database writes fail (no silent swallowing)
-
waitForDatabaseWrites()helper added - All integration tests updated to use wait helper
- Re-run full test suite to get ACCURATE failure count
- Update issues Fix Indent/Outdent Operations (12 test failures) #228-Fix UI & Service Integration Issues (14 test failures) #233 if failure counts change
Expected Outcome
After this fix:
- ✅ Tests will FAIL when they should (catching real bugs)
- ✅ We'll see HTTP 500 errors that are currently hidden
- ✅ Manual testing bugs WILL be caught by tests
⚠️ More tests will fail (this is GOOD - they're catching real bugs!)
Testing
# After fix, run full suite:
bun run test
# Expect: More failures revealed (not fewer)
# Why: Tests are now catching bugs that were silently swallowedWork Order
- This issue FIRST - Makes tests reliable
- Then re-assess Fix Indent/Outdent Operations (12 test failures) #228-Fix UI & Service Integration Issues (14 test failures) #233 with accurate failure counts
- Then fix the real bugs revealed by tests
Metadata
Metadata
Assignees
Labels
No labels
Activity
Fix Test Environment to Surface Database Errors & Race Conditions
Fix Test Environment to Surface Database Errors & Race Conditions (#236)
malibio commentedon Oct 11, 2025
✅ Issue Completed
Successfully fixed test infrastructure to surface database errors and prevent race conditions.
Implementation Summary
Core Changes:
testErrors[],getTestErrors(),clearTestErrors())hasPendingWrites()getter for write queue visibilitywaitForDatabaseWrites()helper with configurable pollingQuality Improvements (from code review):
Results
Before: Tests passed even when database persistence was broken (false confidence)
After: Tests now fail visibly when database writes fail, catching real bugs
Test Coverage:
Quality Gates:
Merged PR
PR #236 merged to main in commit
42e1781Impact on Related Issues
This infrastructure fix enables reliable testing for issues #228-#233. The test suite now properly detects database persistence failures that were previously hidden.
Fix Test Environment to Surface Database Errors & Race Conditions (#236)
Fix Test Environment to Surface Database Errors & Race Conditions (#236)
Fix Test Environment to Surface Database Errors & Race Conditions (#236)