Repository navigation
Description
Bug: Database Persistence Failures
Related to: Issue #208 (Comprehensive Test Coverage)
Test File: src/tests/services/database-persistence.test.ts
Failures: 7 tests failing
⚠️ Agent Instructions - READ FIRST
1. Prerequisites Check
Answer: Issue #245 IS COMPLETE. ✅ Proceed with implementation.
The PersistenceCoordinator test infrastructure is now in place. You can run tests reliably.
2. Scope & Priority
Answer: Address issues in this order:
Priority 1 - Infrastructure Issues (Fix First):
- Read-only operations triggering writes → Test infrastructure issue
- Rapid sequential updates → May be fixed by PersistenceCoordinator already
Priority 2 - Validation Issues:
3. Empty node validation → Frontend/backend coordination
4. Placeholder behavior → Related to empty nodes
5. Sibling update persistence → Verify PersistenceCoordinator handles this
Priority 3 - Design Decisions:
6. Node deletion cascade/promotion → Business logic decision needed
7. Non-idempotent delete → See answer #5 below
Start by running tests to see which are actually still failing after #245.
3. Testing Approach
Answer: YES, run tests FIRST to see current state.
bun run test src/tests/services/database-persistence.test.tsMany issues may already be fixed by:
- Issue Fix test failures after PersistenceCoordinator integration #245 (test infrastructure)
- PersistenceCoordinator dependency tracking
- Recent SharedNodeStore refactoring
Document which tests still fail and tackle those.
4. Branching Strategy
Answer: Create a single feature branch for this issue.
git checkout -b feature/issue-231-database-persistence-fixes5. Design Decision: Idempotent Delete
Answer: Make deletion idempotent (return success on non-existent nodes).
Rationale:
- RESTful best practice: DELETE should be idempotent
- Simplifies client code (no need to check existence first)
- Prevents race conditions in distributed scenarios
- HTTP DELETE typically returns 200/204 even if resource doesn't exist
Implementation:
- Backend: Return success if node doesn't exist (don't error)
- Update test Tauri desktop app launches successfully #6 to verify idempotent behavior
⚠️ CRITICAL: Use PersistenceCoordinator Pattern
DO NOT call SharedNodeStore directly for persistence operations.
All persistence should go through the proper flow:
// ✅ CORRECT - Use service layer
reactiveNodeService.updateNode(nodeId, changes);
└─> sharedNodeStore.updateNode(...)
└─> PersistenceCoordinator.persist(...)
// ❌ WRONG - Don't bypass the service layer
sharedNodeStore.setNode(...); // Unless you're the service layerThe PersistenceCoordinator handles:
- Dependency tracking (parent before child)
- Debouncing (content) vs immediate (structural)
- FOREIGN KEY constraint ordering
- Race condition prevention
Files you'll likely modify:
packages/desktop-app/src/lib/services/reactive-node-service.svelte.ts(service layer)packages/desktop-app/src-tauri/src/commands.rs(backend validation/idempotent delete)- Test file to adjust expectations after fixes
Prerequisites
✅ Issue #245 is COMPLETE - Test infrastructure fixed, proceed with implementation.
Problem
The comprehensive tests have exposed bugs in database persistence layer:
- Empty nodes not being rejected properly
- Placeholder behavior inconsistent
- Sibling updates (beforeSiblingId changes) not persisting
- Rapid sequential updates causing errors
- Node deletion cascade/promotion issues
- Non-idempotent delete (errors on non-existent)
- Read operations triggering unintended writes
Failing Tests
- should reject empty nodes - backend validation prevents placeholder creation
- should persist node after content added (first character triggers)
- should persist sibling updates (beforeSiblingId changes saved)
- should handle rapid sequential updates without database errors
- should delete node and handle children via cascade/promotion
- should error when deleting non-existent node → UPDATE: Make idempotent
- should load nodes without triggering writes (read-only operation)
Implementation Steps
Step 1: Run Tests & Document Current State
bun run test src/tests/services/database-persistence.test.tsDocument which tests fail. Some may already pass after #245 and recent refactoring.
Step 2: Fix Remaining Issues
Based on test results, fix in priority order:
- Read-only operations (test infrastructure)
- Empty node validation
- Sibling update persistence
- Rapid updates
- Deletion behavior
Step 3: Make Delete Idempotent
Update backend to return success (not error) when deleting non-existent node.
File: packages/desktop-app/src-tauri/src/commands.rs
Look for delete_node command and handle "not found" case gracefully.
Step 4: Verify All Tests Pass
bun run test src/tests/services/database-persistence.test.tsAcceptance Criteria
- All 7 tests pass
- Empty node validation works correctly
- Sibling updates persist via PersistenceCoordinator
- Concurrent operations safe (PersistenceCoordinator handles this)
- Deletion is idempotent (succeeds on non-existent nodes)
- Read operations don't trigger writes
- Quality checks pass:
bun run quality:fix
Estimated Effort
- Time: 2-3 hours
- Complexity: Low-Medium (many issues may already be fixed)
- Risk: Low (test-driven, clear validation)
Testing
Run: bun run test src/tests/services/database-persistence.test.ts
Activity
Fix Database Persistence Operations (Issue #231)
Implement Code Review Recommendations (Issue #231)
Fix Database Persistence Operations (7 test failures) (#252)
Fix Database Persistence Operations (7 test failures) (#252)
Fix Database Persistence Operations (7 test failures) (#252)
Fix Database Persistence Operations (7 test failures) (#252)