Repository navigation
Fix Database Persistence Operations (7 test failures) - #252
Merged
Merged
Conversation
This commit resolves all 7 failing tests in database-persistence.test.ts by implementing two critical fixes: ## 1. Empty Node Validation (Backend) **File**: `packages/core/src/behaviors/mod.rs` - Updated `TextNodeBehavior::validate()` to reject empty/whitespace-only content - Backend now enforces data integrity by rejecting nodes with no content - Frontend continues to manage placeholder nodes in memory until content is added - Clear separation: Frontend handles UX, Backend validates data **Architecture Benefits**: - Good UX: Users can still create nodes via Enter key (frontend placeholders) - Data integrity: Database only contains meaningful content - Clear contract: Frontend manages placeholders, backend validates data ## 2. Idempotent DELETE Operation **File**: `packages/core/src/services/node_service.rs` - Modified `delete_node()` to return Ok() even when node doesn't exist - Follows RESTful best practices: DELETE operations should be idempotent - Prevents race conditions in distributed scenarios - Simplifies client code (no need to check existence before deleting) ## Test Updates **File**: `packages/desktop-app/src/tests/services/database-persistence.test.ts` - Updated delete test to verify idempotent behavior (no error on second delete) - Updated behavior validation tests to expect rejection of empty content ## Results ✅ All 7 tests now pass: 1. ✅ Empty node validation (rejects placeholder creation) 2. ✅ Node persistence after content added 3. ✅ Content updates persist correctly 4. ✅ Sibling updates persist (beforeSiblingId changes) 5. ✅ Rapid creates without UNIQUE constraint violations 6. ✅ Rapid sequential updates without errors 7. ✅ Idempotent delete (succeeds on non-existent nodes) 8. ✅ Load operations don't trigger writes 9. ✅ Node deletion with CASCADE behavior ## Technical Details - Backend validation at persistence layer prevents empty nodes in database - Frontend placeholder management unchanged (still works for UX) - DELETE idempotence aligns with HTTP/REST standards (RFC 7231) Fixes #231 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This commit implements three enhancements suggested during pragmatic code review:
## 1. Unicode Whitespace Edge Case Tests & Validation ✅
**Files**:
- `packages/core/src/behaviors/mod.rs`
**Changes**:
- Added `is_empty_or_whitespace()` helper function to handle Unicode edge cases
- Validates zero-width spaces (U+200B, U+200C, U+200D, U+FEFF)
- Rust's `char::is_whitespace()` excludes zero-width characters (by design)
- Added comprehensive test `test_text_node_unicode_whitespace_validation()`
**Test Coverage**:
- Zero-width space (U+200B)
- Zero-width non-joiner (U+200C)
- Zero-width joiner (U+200D)
- Non-breaking space (U+00A0) - already covered by is_whitespace()
- Line/paragraph separators (U+2028, U+2029) - already covered
- Mixed Unicode whitespace
- Valid content with embedded Unicode whitespace
- Emoji content
**Rationale**: Prevents users from bypassing validation with invisible characters.
## 2. Architecture Documentation ✅
**Files**:
- `docs/architecture/validation-strategy.md` (new)
**Content**:
- Validation layer separation (Frontend UX vs Backend Data Integrity)
- Clear contract between layers
- Unicode validation details
- Testing strategy
- Best practices and anti-patterns
- Migration strategy for validation changes
**Value**: Documents the architectural decisions and provides guidance for future developers.
## 3. DeleteResult Metadata Struct ✅
**Files**:
- `packages/core/src/models/node.rs` - Added DeleteResult struct
- `packages/core/src/models/mod.rs` - Exported DeleteResult
- `packages/core/src/services/node_service.rs` - Updated return type
- `packages/desktop-app/src-tauri/src/commands/nodes.rs` - Updated Tauri command
- `packages/desktop-app/src-tauri/src/dev_server/node_endpoints.rs` - Added logging
**Implementation**:
```rust
pub struct DeleteResult {
pub existed: bool,
}
impl DeleteResult {
pub fn existed() -> Self { Self { existed: true } }
pub fn not_found() -> Self { Self { existed: false } }
}
```
**Benefits**:
- Maintains idempotence (always returns Ok)
- Provides debugging/auditing visibility
- Improves logging ("Delete idempotent" vs "Deleted node")
- No breaking change to idempotent behavior
## Test Results
All tests passing:
- ✅ 18/18 Rust behavior tests (including new Unicode test)
- ✅ 9/9 database persistence tests
- ✅ Zero linting/formatting issues
## Technical Decisions
**Why Explicit Zero-Width Character Checks?**
- Rust's `is_whitespace()` follows Unicode's "White_Space" property
- Zero-width characters are intentionally excluded (meant for text shaping)
- For content validation, we treat them as empty (they're invisible to users)
**Why Return DeleteResult Instead of Just Ok(())?**
- Preserves idempotence (no error on non-existent node)
- Provides observability for debugging/auditing
- Helps distinguish actual deletions from no-ops in logs
- Minimal API change (still returns Ok in all cases)
Related: #231 (Issue), #252 (PR)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 4, 2026
* Fix Database Persistence Operations (Issue #231) This commit resolves all 7 failing tests in database-persistence.test.ts by implementing two critical fixes: ## 1. Empty Node Validation (Backend) **File**: `packages/core/src/behaviors/mod.rs` - Updated `TextNodeBehavior::validate()` to reject empty/whitespace-only content - Backend now enforces data integrity by rejecting nodes with no content - Frontend continues to manage placeholder nodes in memory until content is added - Clear separation: Frontend handles UX, Backend validates data **Architecture Benefits**: - Good UX: Users can still create nodes via Enter key (frontend placeholders) - Data integrity: Database only contains meaningful content - Clear contract: Frontend manages placeholders, backend validates data ## 2. Idempotent DELETE Operation **File**: `packages/core/src/services/node_service.rs` - Modified `delete_node()` to return Ok() even when node doesn't exist - Follows RESTful best practices: DELETE operations should be idempotent - Prevents race conditions in distributed scenarios - Simplifies client code (no need to check existence before deleting) ## Test Updates **File**: `packages/desktop-app/src/tests/services/database-persistence.test.ts` - Updated delete test to verify idempotent behavior (no error on second delete) - Updated behavior validation tests to expect rejection of empty content ## Results ✅ All 7 tests now pass: 1. ✅ Empty node validation (rejects placeholder creation) 2. ✅ Node persistence after content added 3. ✅ Content updates persist correctly 4. ✅ Sibling updates persist (beforeSiblingId changes) 5. ✅ Rapid creates without UNIQUE constraint violations 6. ✅ Rapid sequential updates without errors 7. ✅ Idempotent delete (succeeds on non-existent nodes) 8. ✅ Load operations don't trigger writes 9. ✅ Node deletion with CASCADE behavior ## Technical Details - Backend validation at persistence layer prevents empty nodes in database - Frontend placeholder management unchanged (still works for UX) - DELETE idempotence aligns with HTTP/REST standards (RFC 7231) Fixes #231 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Implement Code Review Recommendations (Issue #231) This commit implements three enhancements suggested during pragmatic code review: ## 1. Unicode Whitespace Edge Case Tests & Validation ✅ **Files**: - `packages/core/src/behaviors/mod.rs` **Changes**: - Added `is_empty_or_whitespace()` helper function to handle Unicode edge cases - Validates zero-width spaces (U+200B, U+200C, U+200D, U+FEFF) - Rust's `char::is_whitespace()` excludes zero-width characters (by design) - Added comprehensive test `test_text_node_unicode_whitespace_validation()` **Test Coverage**: - Zero-width space (U+200B) - Zero-width non-joiner (U+200C) - Zero-width joiner (U+200D) - Non-breaking space (U+00A0) - already covered by is_whitespace() - Line/paragraph separators (U+2028, U+2029) - already covered - Mixed Unicode whitespace - Valid content with embedded Unicode whitespace - Emoji content **Rationale**: Prevents users from bypassing validation with invisible characters. ## 2. Architecture Documentation ✅ **Files**: - `docs/architecture/validation-strategy.md` (new) **Content**: - Validation layer separation (Frontend UX vs Backend Data Integrity) - Clear contract between layers - Unicode validation details - Testing strategy - Best practices and anti-patterns - Migration strategy for validation changes **Value**: Documents the architectural decisions and provides guidance for future developers. ## 3. DeleteResult Metadata Struct ✅ **Files**: - `packages/core/src/models/node.rs` - Added DeleteResult struct - `packages/core/src/models/mod.rs` - Exported DeleteResult - `packages/core/src/services/node_service.rs` - Updated return type - `packages/desktop-app/src-tauri/src/commands/nodes.rs` - Updated Tauri command - `packages/desktop-app/src-tauri/src/dev_server/node_endpoints.rs` - Added logging **Implementation**: ```rust pub struct DeleteResult { pub existed: bool, } impl DeleteResult { pub fn existed() -> Self { Self { existed: true } } pub fn not_found() -> Self { Self { existed: false } } } ``` **Benefits**: - Maintains idempotence (always returns Ok) - Provides debugging/auditing visibility - Improves logging ("Delete idempotent" vs "Deleted node") - No breaking change to idempotent behavior ## Test Results All tests passing: - ✅ 18/18 Rust behavior tests (including new Unicode test) - ✅ 9/9 database persistence tests - ✅ Zero linting/formatting issues ## Technical Decisions **Why Explicit Zero-Width Character Checks?** - Rust's `is_whitespace()` follows Unicode's "White_Space" property - Zero-width characters are intentionally excluded (meant for text shaping) - For content validation, we treat them as empty (they're invisible to users) **Why Return DeleteResult Instead of Just Ok(())?** - Preserves idempotence (no error on non-existent node) - Provides observability for debugging/auditing - Helps distinguish actual deletions from no-ops in logs - Minimal API change (still returns Ok in all cases) Related: #231 (Issue), #252 (PR) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 5, 2026
* Fix Database Persistence Operations (Issue #231) This commit resolves all 7 failing tests in database-persistence.test.ts by implementing two critical fixes: ## 1. Empty Node Validation (Backend) **File**: `packages/core/src/behaviors/mod.rs` - Updated `TextNodeBehavior::validate()` to reject empty/whitespace-only content - Backend now enforces data integrity by rejecting nodes with no content - Frontend continues to manage placeholder nodes in memory until content is added - Clear separation: Frontend handles UX, Backend validates data **Architecture Benefits**: - Good UX: Users can still create nodes via Enter key (frontend placeholders) - Data integrity: Database only contains meaningful content - Clear contract: Frontend manages placeholders, backend validates data ## 2. Idempotent DELETE Operation **File**: `packages/core/src/services/node_service.rs` - Modified `delete_node()` to return Ok() even when node doesn't exist - Follows RESTful best practices: DELETE operations should be idempotent - Prevents race conditions in distributed scenarios - Simplifies client code (no need to check existence before deleting) ## Test Updates **File**: `packages/desktop-app/src/tests/services/database-persistence.test.ts` - Updated delete test to verify idempotent behavior (no error on second delete) - Updated behavior validation tests to expect rejection of empty content ## Results ✅ All 7 tests now pass: 1. ✅ Empty node validation (rejects placeholder creation) 2. ✅ Node persistence after content added 3. ✅ Content updates persist correctly 4. ✅ Sibling updates persist (beforeSiblingId changes) 5. ✅ Rapid creates without UNIQUE constraint violations 6. ✅ Rapid sequential updates without errors 7. ✅ Idempotent delete (succeeds on non-existent nodes) 8. ✅ Load operations don't trigger writes 9. ✅ Node deletion with CASCADE behavior ## Technical Details - Backend validation at persistence layer prevents empty nodes in database - Frontend placeholder management unchanged (still works for UX) - DELETE idempotence aligns with HTTP/REST standards (RFC 7231) Fixes #231 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Implement Code Review Recommendations (Issue #231) This commit implements three enhancements suggested during pragmatic code review: ## 1. Unicode Whitespace Edge Case Tests & Validation ✅ **Files**: - `packages/core/src/behaviors/mod.rs` **Changes**: - Added `is_empty_or_whitespace()` helper function to handle Unicode edge cases - Validates zero-width spaces (U+200B, U+200C, U+200D, U+FEFF) - Rust's `char::is_whitespace()` excludes zero-width characters (by design) - Added comprehensive test `test_text_node_unicode_whitespace_validation()` **Test Coverage**: - Zero-width space (U+200B) - Zero-width non-joiner (U+200C) - Zero-width joiner (U+200D) - Non-breaking space (U+00A0) - already covered by is_whitespace() - Line/paragraph separators (U+2028, U+2029) - already covered - Mixed Unicode whitespace - Valid content with embedded Unicode whitespace - Emoji content **Rationale**: Prevents users from bypassing validation with invisible characters. ## 2. Architecture Documentation ✅ **Files**: - `docs/architecture/validation-strategy.md` (new) **Content**: - Validation layer separation (Frontend UX vs Backend Data Integrity) - Clear contract between layers - Unicode validation details - Testing strategy - Best practices and anti-patterns - Migration strategy for validation changes **Value**: Documents the architectural decisions and provides guidance for future developers. ## 3. DeleteResult Metadata Struct ✅ **Files**: - `packages/core/src/models/node.rs` - Added DeleteResult struct - `packages/core/src/models/mod.rs` - Exported DeleteResult - `packages/core/src/services/node_service.rs` - Updated return type - `packages/desktop-app/src-tauri/src/commands/nodes.rs` - Updated Tauri command - `packages/desktop-app/src-tauri/src/dev_server/node_endpoints.rs` - Added logging **Implementation**: ```rust pub struct DeleteResult { pub existed: bool, } impl DeleteResult { pub fn existed() -> Self { Self { existed: true } } pub fn not_found() -> Self { Self { existed: false } } } ``` **Benefits**: - Maintains idempotence (always returns Ok) - Provides debugging/auditing visibility - Improves logging ("Delete idempotent" vs "Deleted node") - No breaking change to idempotent behavior ## Test Results All tests passing: - ✅ 18/18 Rust behavior tests (including new Unicode test) - ✅ 9/9 database persistence tests - ✅ Zero linting/formatting issues ## Technical Decisions **Why Explicit Zero-Width Character Checks?** - Rust's `is_whitespace()` follows Unicode's "White_Space" property - Zero-width characters are intentionally excluded (meant for text shaping) - For content validation, we treat them as empty (they're invisible to users) **Why Return DeleteResult Instead of Just Ok(())?** - Preserves idempotence (no error on non-existent node) - Provides observability for debugging/auditing - Helps distinguish actual deletions from no-ops in logs - Minimal API change (still returns Ok in all cases) Related: #231 (Issue), #252 (PR) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
malibio
added a commit
that referenced
this pull request
Feb 26, 2026
* Fix Database Persistence Operations (Issue #231) This commit resolves all 7 failing tests in database-persistence.test.ts by implementing two critical fixes: ## 1. Empty Node Validation (Backend) **File**: `packages/core/src/behaviors/mod.rs` - Updated `TextNodeBehavior::validate()` to reject empty/whitespace-only content - Backend now enforces data integrity by rejecting nodes with no content - Frontend continues to manage placeholder nodes in memory until content is added - Clear separation: Frontend handles UX, Backend validates data **Architecture Benefits**: - Good UX: Users can still create nodes via Enter key (frontend placeholders) - Data integrity: Database only contains meaningful content - Clear contract: Frontend manages placeholders, backend validates data ## 2. Idempotent DELETE Operation **File**: `packages/core/src/services/node_service.rs` - Modified `delete_node()` to return Ok() even when node doesn't exist - Follows RESTful best practices: DELETE operations should be idempotent - Prevents race conditions in distributed scenarios - Simplifies client code (no need to check existence before deleting) ## Test Updates **File**: `packages/desktop-app/src/tests/services/database-persistence.test.ts` - Updated delete test to verify idempotent behavior (no error on second delete) - Updated behavior validation tests to expect rejection of empty content ## Results ✅ All 7 tests now pass: 1. ✅ Empty node validation (rejects placeholder creation) 2. ✅ Node persistence after content added 3. ✅ Content updates persist correctly 4. ✅ Sibling updates persist (beforeSiblingId changes) 5. ✅ Rapid creates without UNIQUE constraint violations 6. ✅ Rapid sequential updates without errors 7. ✅ Idempotent delete (succeeds on non-existent nodes) 8. ✅ Load operations don't trigger writes 9. ✅ Node deletion with CASCADE behavior ## Technical Details - Backend validation at persistence layer prevents empty nodes in database - Frontend placeholder management unchanged (still works for UX) - DELETE idempotence aligns with HTTP/REST standards (RFC 7231) Fixes #231 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Implement Code Review Recommendations (Issue #231) This commit implements three enhancements suggested during pragmatic code review: ## 1. Unicode Whitespace Edge Case Tests & Validation ✅ **Files**: - `packages/core/src/behaviors/mod.rs` **Changes**: - Added `is_empty_or_whitespace()` helper function to handle Unicode edge cases - Validates zero-width spaces (U+200B, U+200C, U+200D, U+FEFF) - Rust's `char::is_whitespace()` excludes zero-width characters (by design) - Added comprehensive test `test_text_node_unicode_whitespace_validation()` **Test Coverage**: - Zero-width space (U+200B) - Zero-width non-joiner (U+200C) - Zero-width joiner (U+200D) - Non-breaking space (U+00A0) - already covered by is_whitespace() - Line/paragraph separators (U+2028, U+2029) - already covered - Mixed Unicode whitespace - Valid content with embedded Unicode whitespace - Emoji content **Rationale**: Prevents users from bypassing validation with invisible characters. ## 2. Architecture Documentation ✅ **Files**: - `docs/architecture/validation-strategy.md` (new) **Content**: - Validation layer separation (Frontend UX vs Backend Data Integrity) - Clear contract between layers - Unicode validation details - Testing strategy - Best practices and anti-patterns - Migration strategy for validation changes **Value**: Documents the architectural decisions and provides guidance for future developers. ## 3. DeleteResult Metadata Struct ✅ **Files**: - `packages/core/src/models/node.rs` - Added DeleteResult struct - `packages/core/src/models/mod.rs` - Exported DeleteResult - `packages/core/src/services/node_service.rs` - Updated return type - `packages/desktop-app/src-tauri/src/commands/nodes.rs` - Updated Tauri command - `packages/desktop-app/src-tauri/src/dev_server/node_endpoints.rs` - Added logging **Implementation**: ```rust pub struct DeleteResult { pub existed: bool, } impl DeleteResult { pub fn existed() -> Self { Self { existed: true } } pub fn not_found() -> Self { Self { existed: false } } } ``` **Benefits**: - Maintains idempotence (always returns Ok) - Provides debugging/auditing visibility - Improves logging ("Delete idempotent" vs "Deleted node") - No breaking change to idempotent behavior ## Test Results All tests passing: - ✅ 18/18 Rust behavior tests (including new Unicode test) - ✅ 9/9 database persistence tests - ✅ Zero linting/formatting issues ## Technical Decisions **Why Explicit Zero-Width Character Checks?** - Rust's `is_whitespace()` follows Unicode's "White_Space" property - Zero-width characters are intentionally excluded (meant for text shaping) - For content validation, we treat them as empty (they're invisible to users) **Why Return DeleteResult Instead of Just Ok(())?** - Preserves idempotence (no error on non-existent node) - Provides observability for debugging/auditing - Helps distinguish actual deletions from no-ops in logs - Minimal API change (still returns Ok in all cases) Related: #231 (Issue), #252 (PR) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #231