Skip to content

Fix Backspace/Delete Operations (Issue #229) - #254

Merged
malibio merged 3 commits into
mainfrom
feature/issue-229-fix-backspace-delete-operations
Oct 12, 2025
Merged

malibio merged 3 commits into
mainfrom
feature/issue-229-fix-backspace-delete-operations

Conversation

@malibio

@malibio malibio commented Oct 12, 2025

Copy link
Copy Markdown
Collaborator

Fix Backspace/Delete Operations (9 test failures)

Fixes #229

Summary

This PR fixes all 9 failing tests in backspace-operations.test.ts by ensuring proper persistence sequencing and dependency management through PersistenceCoordinator.

Root Causes Identified

  1. Content updates not persisting: Using viewerSource for content-only updates caused persistence to be skipped
  2. Race conditions on deletion: Child promotion and sibling chain updates weren't completing before node deletion
  3. FOREIGN KEY violations: containerNodeId not being updated for promoted children and nested descendants
  4. Incorrect promotion logic: Root-level node deletions were making children siblings instead of promoting to root
  5. Missing root tracking: Promoted root-level children weren't added to _rootNodeIds array

Changes Made

1. Content Update Persistence (reactive-node-service.svelte.ts:756-761)

  • Changed content update source from 'viewer' to 'external' to ensure persistence
  • Using 'viewer' source skipped content-only updates per shared-node-store.ts:254
  • Now content merges persist to database before deletion

2. Fixed Child Promotion Logic (reactive-node-service.svelte.ts:1092-1115)

  • Root-level node deletions now promote children to root (parentId=null)
  • Previous logic incorrectly made children siblings of previous node
  • Properly distinguishes between root-level and nested node promotion

3. Added Root Node Tracking (reactive-node-service.svelte.ts:1155-1158)

  • Promoted children now added to _rootNodeIds array
  • Ensures promoted nodes appear in visibleNodes list
  • Fixes visual order test expectations

4. Fixed Container ID Updates (reactive-node-service.svelte.ts:1128-1136)

  • Update containerNodeId when promoting children to prevent FOREIGN KEY violations
  • Container inherits from new parent's container (or null for root-level)

5. Recursive Descendant Fix (reactive-node-service.svelte.ts:1167-1195)

  • Added fixDescendantContainerIds() to recursively update nested descendants
  • Grandchildren and deeper descendants now get updated containerNodeIds
  • Prevents FOREIGN KEY violations when deleting nodes with nested children

6. Proper Wait Dependencies (reactive-node-service.svelte.ts:765)

  • Added previousNodeId to nodesToWaitFor for content update
  • Ensures all structural changes complete before deletion
  • Prevents race conditions and 500 errors

Test Results

✅ All 10 tests in backspace-operations.test.ts now pass:

  • ✅ should combine two text nodes and preserve content
  • ✅ should position cursor at junction point when combining
  • ✅ should strip formatting from current node when combining
  • ✅ should promote children when combining nodes with children
  • ✅ should repair sibling chain after combining
  • ✅ should handle combining nodes with nested children
  • ✅ should emit correct events when combining
  • ✅ should handle combining when previous node is at different depth
  • ✅ should strip task checkbox formatting when combining
  • ✅ should no-op when combineNodes called with non-existent previous node

Testing

bunx vitest run src/tests/integration/backspace-operations.test.ts

All tests pass with no database errors or FOREIGN KEY violations.

🤖 Generated with Claude Code

malibio and others added 3 commits October 12, 2025 17:05
This fixes all 9 failing tests in backspace-operations.test.ts by ensuring proper
persistence sequencing and dependency management through PersistenceCoordinator.

## Changes Made:

### 1. Content Update Persistence (reactive-node-service.svelte.ts:756-761)
- Changed content update source from 'viewer' to 'external' to ensure persistence
- Using 'viewer' source skipped content-only updates (shared-node-store.ts:254)
- Now content merges persist to database before deletion

### 2. Fixed Child Promotion Logic (reactive-node-service.svelte.ts:1092-1115)
- Root-level node deletions now promote children to root (parentId=null)
- Previous logic incorrectly made children siblings of previous node
- Fixes "should promote children" test failure

### 3. Added Root Node Tracking (reactive-node-service.svelte.ts:1155-1158)
- Promoted children now added to _rootNodeIds array
- Ensures promoted nodes appear in visibleNodes list
- Fixes visual order test expectations

### 4. Fixed Container ID Updates (reactive-node-service.svelte.ts:1128-1136)
- Update containerNodeId when promoting children to prevent FOREIGN KEY violations
- Container inherits from new parent's container (or null for root-level)

### 5. Recursive Descendant Fix (reactive-node-service.svelte.ts:1167-1195)
- Added fixDescendantContainerIds() to recursively update nested descendants
- Grandchildren and deeper descendants now get updated containerNodeIds
- Prevents FOREIGN KEY violations when deleting nodes with nested children
- Fixes "should handle combining nodes with nested children" test

### 6. Proper Wait Dependencies (reactive-node-service.svelte.ts:765)
- Added previousNodeId to nodesToWaitFor for content update
- Ensures all structural changes complete before deletion
- Prevents race conditions and 500 errors

## Test Results:
- All 10 tests in backspace-operations.test.ts now pass
- No database errors or FOREIGN KEY violations
- Content properly persisted and merged
- Children correctly promoted with proper hierarchy

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…wait

Replace manual `await waitForNodeSaves()` logic with declarative dependency
mechanism in PersistenceCoordinator. This is the architecturally correct approach.

## Changes:

### 1. Enhanced SharedNodeStore.deleteNode() (shared-node-store.ts:469-522)
- Added optional `dependencies` parameter
- Pass dependencies to PersistenceCoordinator.persist()
- Documents that dependencies prevent FOREIGN KEY violations

### 2. Simplified combineNodes() (reactive-node-service.svelte.ts:744-785)
- Removed async/await and manual wait logic
- Changed from `async function` to `function` (synchronous)
- Collect dependencies and pass to deleteNode() directly
- PersistenceCoordinator handles sequencing automatically

## Benefits:

✅ **More Declarative**: Dependencies are explicit, not implicit in wait logic
✅ **Better Encapsulation**: Coordination logic stays in PersistenceCoordinator
✅ **Simpler Code**: Removed 15 lines of manual wait/error handling
✅ **Architecturally Correct**: Uses the dependency system as designed
✅ **Same Behavior**: All 10 tests still pass

## Before (Manual Await):
```typescript
const nodesToWaitFor = [node1, node2, node3];
await sharedNodeStore.waitForNodeSaves(nodesToWaitFor);
// Check for failures, log errors...
sharedNodeStore.deleteNode(nodeId, source);
```

## After (Declarative Dependencies):
```typescript
const dependencies = [node1, node2, node3];
sharedNodeStore.deleteNode(nodeId, source, false, dependencies);
```

PersistenceCoordinator ensures the dependencies complete before deletion executes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add comprehensive documentation for PersistenceCoordinator usage patterns,
including the declarative dependency approach used in Issue #229.

## Contents:

### Core Patterns:
1. Simple Immediate Persistence - Single node operations
2. Deletion with Dependencies - Recommended pattern from #229
3. Ancestor Chain Dependencies - Automatic handling
4. Structural vs Content Updates - Different persistence modes

### Anti-Patterns:
- Manual await logic (replaced in #229)
- Direct database calls
- Ignoring containerNodeId updates

### Testing:
- Test pattern using waitForDatabaseWrites()
- Database state verification

### Examples:
- combineNodes() from #229 as canonical reference
- Code snippets for each pattern
- When to use each approach

This documentation will help future developers implement similar
operations correctly (move, bulk delete, etc.) using the dependency
system as designed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit 03a4e0a into main Oct 12, 2025
@malibio
malibio deleted the feature/issue-229-fix-backspace-delete-operations branch October 12, 2025 16:11
malibio added a commit that referenced this pull request Feb 4, 2026
* Fix backspace/delete operations to use PersistenceCoordinator properly

This fixes all 9 failing tests in backspace-operations.test.ts by ensuring proper
persistence sequencing and dependency management through PersistenceCoordinator.

## Changes Made:

### 1. Content Update Persistence (reactive-node-service.svelte.ts:756-761)
- Changed content update source from 'viewer' to 'external' to ensure persistence
- Using 'viewer' source skipped content-only updates (shared-node-store.ts:254)
- Now content merges persist to database before deletion

### 2. Fixed Child Promotion Logic (reactive-node-service.svelte.ts:1092-1115)
- Root-level node deletions now promote children to root (parentId=null)
- Previous logic incorrectly made children siblings of previous node
- Fixes "should promote children" test failure

### 3. Added Root Node Tracking (reactive-node-service.svelte.ts:1155-1158)
- Promoted children now added to _rootNodeIds array
- Ensures promoted nodes appear in visibleNodes list
- Fixes visual order test expectations

### 4. Fixed Container ID Updates (reactive-node-service.svelte.ts:1128-1136)
- Update containerNodeId when promoting children to prevent FOREIGN KEY violations
- Container inherits from new parent's container (or null for root-level)

### 5. Recursive Descendant Fix (reactive-node-service.svelte.ts:1167-1195)
- Added fixDescendantContainerIds() to recursively update nested descendants
- Grandchildren and deeper descendants now get updated containerNodeIds
- Prevents FOREIGN KEY violations when deleting nodes with nested children
- Fixes "should handle combining nodes with nested children" test

### 6. Proper Wait Dependencies (reactive-node-service.svelte.ts:765)
- Added previousNodeId to nodesToWaitFor for content update
- Ensures all structural changes complete before deletion
- Prevents race conditions and 500 errors

## Test Results:
- All 10 tests in backspace-operations.test.ts now pass
- No database errors or FOREIGN KEY violations
- Content properly persisted and merged
- Children correctly promoted with proper hierarchy

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Refactor: Use PersistenceCoordinator dependencies instead of manual await

Replace manual `await waitForNodeSaves()` logic with declarative dependency
mechanism in PersistenceCoordinator. This is the architecturally correct approach.

## Changes:

### 1. Enhanced SharedNodeStore.deleteNode() (shared-node-store.ts:469-522)
- Added optional `dependencies` parameter
- Pass dependencies to PersistenceCoordinator.persist()
- Documents that dependencies prevent FOREIGN KEY violations

### 2. Simplified combineNodes() (reactive-node-service.svelte.ts:744-785)
- Removed async/await and manual wait logic
- Changed from `async function` to `function` (synchronous)
- Collect dependencies and pass to deleteNode() directly
- PersistenceCoordinator handles sequencing automatically

## Benefits:

✅ **More Declarative**: Dependencies are explicit, not implicit in wait logic
✅ **Better Encapsulation**: Coordination logic stays in PersistenceCoordinator
✅ **Simpler Code**: Removed 15 lines of manual wait/error handling
✅ **Architecturally Correct**: Uses the dependency system as designed
✅ **Same Behavior**: All 10 tests still pass

## Before (Manual Await):
```typescript
const nodesToWaitFor = [node1, node2, node3];
await sharedNodeStore.waitForNodeSaves(nodesToWaitFor);
// Check for failures, log errors...
sharedNodeStore.deleteNode(nodeId, source);
```

## After (Declarative Dependencies):
```typescript
const dependencies = [node1, node2, node3];
sharedNodeStore.deleteNode(nodeId, source, false, dependencies);
```

PersistenceCoordinator ensures the dependencies complete before deletion executes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* docs: Add PersistenceCoordinator patterns and best practices guide

Add comprehensive documentation for PersistenceCoordinator usage patterns,
including the declarative dependency approach used in Issue #229.

## Contents:

### Core Patterns:
1. Simple Immediate Persistence - Single node operations
2. Deletion with Dependencies - Recommended pattern from #229
3. Ancestor Chain Dependencies - Automatic handling
4. Structural vs Content Updates - Different persistence modes

### Anti-Patterns:
- Manual await logic (replaced in #229)
- Direct database calls
- Ignoring containerNodeId updates

### Testing:
- Test pattern using waitForDatabaseWrites()
- Database state verification

### Examples:
- combineNodes() from #229 as canonical reference
- Code snippets for each pattern
- When to use each approach

This documentation will help future developers implement similar
operations correctly (move, bulk delete, etc.) using the dependency
system as designed.

🤖 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 backspace/delete operations to use PersistenceCoordinator properly

This fixes all 9 failing tests in backspace-operations.test.ts by ensuring proper
persistence sequencing and dependency management through PersistenceCoordinator.

## Changes Made:

### 1. Content Update Persistence (reactive-node-service.svelte.ts:756-761)
- Changed content update source from 'viewer' to 'external' to ensure persistence
- Using 'viewer' source skipped content-only updates (shared-node-store.ts:254)
- Now content merges persist to database before deletion

### 2. Fixed Child Promotion Logic (reactive-node-service.svelte.ts:1092-1115)
- Root-level node deletions now promote children to root (parentId=null)
- Previous logic incorrectly made children siblings of previous node
- Fixes "should promote children" test failure

### 3. Added Root Node Tracking (reactive-node-service.svelte.ts:1155-1158)
- Promoted children now added to _rootNodeIds array
- Ensures promoted nodes appear in visibleNodes list
- Fixes visual order test expectations

### 4. Fixed Container ID Updates (reactive-node-service.svelte.ts:1128-1136)
- Update containerNodeId when promoting children to prevent FOREIGN KEY violations
- Container inherits from new parent's container (or null for root-level)

### 5. Recursive Descendant Fix (reactive-node-service.svelte.ts:1167-1195)
- Added fixDescendantContainerIds() to recursively update nested descendants
- Grandchildren and deeper descendants now get updated containerNodeIds
- Prevents FOREIGN KEY violations when deleting nodes with nested children
- Fixes "should handle combining nodes with nested children" test

### 6. Proper Wait Dependencies (reactive-node-service.svelte.ts:765)
- Added previousNodeId to nodesToWaitFor for content update
- Ensures all structural changes complete before deletion
- Prevents race conditions and 500 errors

## Test Results:
- All 10 tests in backspace-operations.test.ts now pass
- No database errors or FOREIGN KEY violations
- Content properly persisted and merged
- Children correctly promoted with proper hierarchy

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Refactor: Use PersistenceCoordinator dependencies instead of manual await

Replace manual `await waitForNodeSaves()` logic with declarative dependency
mechanism in PersistenceCoordinator. This is the architecturally correct approach.

## Changes:

### 1. Enhanced SharedNodeStore.deleteNode() (shared-node-store.ts:469-522)
- Added optional `dependencies` parameter
- Pass dependencies to PersistenceCoordinator.persist()
- Documents that dependencies prevent FOREIGN KEY violations

### 2. Simplified combineNodes() (reactive-node-service.svelte.ts:744-785)
- Removed async/await and manual wait logic
- Changed from `async function` to `function` (synchronous)
- Collect dependencies and pass to deleteNode() directly
- PersistenceCoordinator handles sequencing automatically

## Benefits:

✅ **More Declarative**: Dependencies are explicit, not implicit in wait logic
✅ **Better Encapsulation**: Coordination logic stays in PersistenceCoordinator
✅ **Simpler Code**: Removed 15 lines of manual wait/error handling
✅ **Architecturally Correct**: Uses the dependency system as designed
✅ **Same Behavior**: All 10 tests still pass

## Before (Manual Await):
```typescript
const nodesToWaitFor = [node1, node2, node3];
await sharedNodeStore.waitForNodeSaves(nodesToWaitFor);
// Check for failures, log errors...
sharedNodeStore.deleteNode(nodeId, source);
```

## After (Declarative Dependencies):
```typescript
const dependencies = [node1, node2, node3];
sharedNodeStore.deleteNode(nodeId, source, false, dependencies);
```

PersistenceCoordinator ensures the dependencies complete before deletion executes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* docs: Add PersistenceCoordinator patterns and best practices guide

Add comprehensive documentation for PersistenceCoordinator usage patterns,
including the declarative dependency approach used in Issue #229.

## Contents:

### Core Patterns:
1. Simple Immediate Persistence - Single node operations
2. Deletion with Dependencies - Recommended pattern from #229
3. Ancestor Chain Dependencies - Automatic handling
4. Structural vs Content Updates - Different persistence modes

### Anti-Patterns:
- Manual await logic (replaced in #229)
- Direct database calls
- Ignoring containerNodeId updates

### Testing:
- Test pattern using waitForDatabaseWrites()
- Database state verification

### Examples:
- combineNodes() from #229 as canonical reference
- Code snippets for each pattern
- When to use each approach

This documentation will help future developers implement similar
operations correctly (move, bulk delete, etc.) using the dependency
system as designed.

🤖 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 backspace/delete operations to use PersistenceCoordinator properly

This fixes all 9 failing tests in backspace-operations.test.ts by ensuring proper
persistence sequencing and dependency management through PersistenceCoordinator.

## Changes Made:

### 1. Content Update Persistence (reactive-node-service.svelte.ts:756-761)
- Changed content update source from 'viewer' to 'external' to ensure persistence
- Using 'viewer' source skipped content-only updates (shared-node-store.ts:254)
- Now content merges persist to database before deletion

### 2. Fixed Child Promotion Logic (reactive-node-service.svelte.ts:1092-1115)
- Root-level node deletions now promote children to root (parentId=null)
- Previous logic incorrectly made children siblings of previous node
- Fixes "should promote children" test failure

### 3. Added Root Node Tracking (reactive-node-service.svelte.ts:1155-1158)
- Promoted children now added to _rootNodeIds array
- Ensures promoted nodes appear in visibleNodes list
- Fixes visual order test expectations

### 4. Fixed Container ID Updates (reactive-node-service.svelte.ts:1128-1136)
- Update containerNodeId when promoting children to prevent FOREIGN KEY violations
- Container inherits from new parent's container (or null for root-level)

### 5. Recursive Descendant Fix (reactive-node-service.svelte.ts:1167-1195)
- Added fixDescendantContainerIds() to recursively update nested descendants
- Grandchildren and deeper descendants now get updated containerNodeIds
- Prevents FOREIGN KEY violations when deleting nodes with nested children
- Fixes "should handle combining nodes with nested children" test

### 6. Proper Wait Dependencies (reactive-node-service.svelte.ts:765)
- Added previousNodeId to nodesToWaitFor for content update
- Ensures all structural changes complete before deletion
- Prevents race conditions and 500 errors

## Test Results:
- All 10 tests in backspace-operations.test.ts now pass
- No database errors or FOREIGN KEY violations
- Content properly persisted and merged
- Children correctly promoted with proper hierarchy

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Refactor: Use PersistenceCoordinator dependencies instead of manual await

Replace manual `await waitForNodeSaves()` logic with declarative dependency
mechanism in PersistenceCoordinator. This is the architecturally correct approach.

## Changes:

### 1. Enhanced SharedNodeStore.deleteNode() (shared-node-store.ts:469-522)
- Added optional `dependencies` parameter
- Pass dependencies to PersistenceCoordinator.persist()
- Documents that dependencies prevent FOREIGN KEY violations

### 2. Simplified combineNodes() (reactive-node-service.svelte.ts:744-785)
- Removed async/await and manual wait logic
- Changed from `async function` to `function` (synchronous)
- Collect dependencies and pass to deleteNode() directly
- PersistenceCoordinator handles sequencing automatically

## Benefits:

✅ **More Declarative**: Dependencies are explicit, not implicit in wait logic
✅ **Better Encapsulation**: Coordination logic stays in PersistenceCoordinator
✅ **Simpler Code**: Removed 15 lines of manual wait/error handling
✅ **Architecturally Correct**: Uses the dependency system as designed
✅ **Same Behavior**: All 10 tests still pass

## Before (Manual Await):
```typescript
const nodesToWaitFor = [node1, node2, node3];
await sharedNodeStore.waitForNodeSaves(nodesToWaitFor);
// Check for failures, log errors...
sharedNodeStore.deleteNode(nodeId, source);
```

## After (Declarative Dependencies):
```typescript
const dependencies = [node1, node2, node3];
sharedNodeStore.deleteNode(nodeId, source, false, dependencies);
```

PersistenceCoordinator ensures the dependencies complete before deletion executes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* docs: Add PersistenceCoordinator patterns and best practices guide

Add comprehensive documentation for PersistenceCoordinator usage patterns,
including the declarative dependency approach used in Issue #229.

## Contents:

### Core Patterns:
1. Simple Immediate Persistence - Single node operations
2. Deletion with Dependencies - Recommended pattern from #229
3. Ancestor Chain Dependencies - Automatic handling
4. Structural vs Content Updates - Different persistence modes

### Anti-Patterns:
- Manual await logic (replaced in #229)
- Direct database calls
- Ignoring containerNodeId updates

### Testing:
- Test pattern using waitForDatabaseWrites()
- Database state verification

### Examples:
- combineNodes() from #229 as canonical reference
- Code snippets for each pattern
- When to use each approach

This documentation will help future developers implement similar
operations correctly (move, bulk delete, etc.) using the dependency
system as designed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Backspace/Delete Operations (9 test failures)

1 participant