Repository navigation
Fix: Node type conversions persist as text nodes with truncated content - #425
Conversation
## Problem Slash command conversions (e.g., /task, /header) were not persisting correctly: - UI showed correct node type immediately - But database saved as text node with incomplete content - Page reload lost user work ## Root Cause ReactiveNodeService imported `sharedNodeStore` at module load time. When tests called `resetInstance()`, the service kept a reference to the old singleton, causing `updateNodeType()` to fail silently in tests (and potentially in production after hot reloads). ## Solution 1. **Fixed singleton reference**: Import `SharedNodeStore` class and call `getInstance()` dynamically inside `createReactiveNodeService()` instead of using module-level import 2. **Always include nodeType**: Modified `updateNodeContent()` to always include `nodeType` in updates to preserve slash command conversions ## Changes - `reactive-node-service.svelte.ts`: Import SharedNodeStore class instead of singleton, get instance dynamically, always include nodeType in content updates - Added comprehensive test suite: `slash-command-type-persistence.test.ts` with 7 tests covering slash commands, pattern detection, and content preservation ## Test Results - All 6 active tests pass (1 skipped for future schema defaults feature) - No regressions in existing test suite (86 files, 1550+ tests) - Tests verify: ✅ Slash command type persistence ✅ Pattern detection still works ✅ Full content persists (not truncated) ✅ Multiple content updates preserve type 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code Review: PR #425 - Fix Node Type Conversions PersistenceCode Review SummaryThis PR addresses a critical data loss bug where slash command node type conversions (e.g.,
The solution is well-tested with 6 comprehensive integration tests that simulate the actual user flow (separate Overall Assessment: This is a NET POSITIVE change that definitively improves code health by fixing a critical data loss bug. The implementation is sound, well-tested, and includes thorough documentation explaining the architectural reasoning. FindingsArchitecture & Design: APPROVED ✅Strengths:
Analysis of the "include nodeType" decision: The comment history reveals this was previously tried and reverted (commit c609ce1). The PR claims pattern conversions work because they call // Pattern conversion flow (from textarea-controller):
// 1. User types "## " → pattern detected
// 2. Controller calls updateNodeType('header') ← Updates nodeType in store
// 3. Controller calls updateNodeContent('## ') ← Now includes FRESH nodeType
// Result: Both fields persist correctly ✅
// Slash command flow (the bug):
// 1. User types /task → slash command detected
// 2. Service calls updateNodeType('task') ← Updates nodeType in store
// 3. User types content → updateNodeContent() ← BEFORE FIX: only sent content, missing nodeType
// Result: nodeType lost during persistence ❌Verification from test results:
The architectural reasoning is sound. The key insight is that Functionality & Correctness: APPROVED ✅Critical verification: ✅ Slash command conversions persist correctly (tests pass) Potential edge case (non-blocking): The implementation reads
The fix would fail. However, this is unlikely because:
Recommendation: Consider adding a test with 0ms delay between calls to stress-test this timing assumption. Security: NO ISSUES ✅No security implications. Changes are internal state management only. Maintainability & Readability: EXCELLENT ✅Strengths:
Code quality:
Testing Strategy & Robustness: EXCELLENT ✅Test coverage analysis: ✅ 6 integration tests added (1 skipped for future work)
✅ Tests use realistic timing: 50ms delays simulate user thinking, 600ms waits for debounce Why existing tests missed this: The existing store.updateNode(nodeId, { content: '## Hello', nodeType: 'header' }, source);The new tests correctly simulate the actual flow: reactiveService.updateNodeType(nodeId, 'task'); // Step 1: Type change
await sleep(50); // Step 2: User delay
reactiveService.updateNodeContent(nodeId, 'Buy milk'); // Step 3: ContentTest quality: All tests pass, descriptive names, clear assertions, proper cleanup. Performance & Scalability: NO IMPACT ✅Analysis: The change adds one additional field ( // Before: { content }
// After: { content, nodeType: node.nodeType }Impact assessment:
Conclusion: Performance impact is negligible. Dependencies & Documentation: APPROVED ✅Dependency changes:
Documentation:
Recommendation: Consider updating Critical IssuesNone. No blockers identified. Suggested Improvements[Improvement] Add zero-delay timing testFile: Rationale: Current tests use 50ms delays between Suggested test: it('should persist nodeType even with zero delay between calls', async () => {
const placeholderNode: Node = { /* ... */ };
store.setNode(placeholderNode, viewerSource);
// No delay - immediate successive calls
reactiveService.updateNodeType(placeholderNode.id, 'task');
reactiveService.updateNodeContent(placeholderNode.id, 'Buy milk'); // 0ms delay
await sleep(600); // Wait for persistence only
const persisted = store.getNode(placeholderNode.id);
expect(persisted?.nodeType).toBe('task');
expect(persisted?.content).toBe('Buy milk');
});Priority: Low (current implementation should handle this, but explicit test coverage would be valuable) [Improvement] Document the singleton pattern changeFile: Rationale: The stale singleton reference issue (importing Suggested content: ## Singleton Testing Pattern: Dynamic getInstance() vs Static Import
**Problem**: When tests call `resetInstance()` on singletons, static imports retain stale references.
**Bad Pattern**:
```typescript
import { sharedNodeStore } from './shared-node-store'; // ❌ Stale after resetInstance()Good Pattern: import { SharedNodeStore } from './shared-node-store';
const sharedNodeStore = SharedNodeStore.getInstance(); // ✅ Fresh instanceExample: Issue #424 - ReactiveNodeService used stale singleton, causing test failures. Recommendation: The current PR correctly scopes the fix to just persistence. Schema defaults (automatically adding Action: Ensure there's a GitHub issue tracking schema defaults implementation. If not, create one and link it to #424. Priority: Low (out of scope for this PR, but worth tracking) NitpicksNit: Test file name could be more specificFile: Current: Generic name doesn't indicate it's specifically testing the ReactiveNodeService integration Suggestion: Consider Why it's a nit: Current name is perfectly acceptable, this is purely about consistency with other test files Nit: Magic number in sleep() callsFiles: Multiple test files Current: Suggestion: Extract to named constants: const USER_TYPING_DELAY_MS = 50;
const DEBOUNCE_WAIT_MS = 600;
await sleep(USER_TYPING_DELAY_MS);
await sleep(DEBOUNCE_WAIT_MS);Why it's a nit: The comments already explain these delays ("Simulate user thinking/typing delay", "Wait for debounce + persistence"), so extracting to constants is purely a style preference Acceptance Criteria VerificationFrom Issue #424: ✅ Slash command conversions persist nodeType correctly to database - Tests pass Deferred (appropriately scoped out):
Verdict: All core acceptance criteria met. Deferred items are appropriately scoped for future work. ConclusionRecommendation: APPROVE AND MERGE ✅ This PR successfully fixes a critical data loss bug with:
The "always include nodeType" approach is sound because:
Suggested next steps:
No blocking issues identified. Review conducted by: Senior Architect Reviewer Agent |
Implemented reviewer suggestions from PR #425 code review: 1. ✅ Added zero-delay timing test - New test verifies synchronous store updates work with NO delay - Stress tests the assumption that updateNodeType() completes before updateNodeContent() - All 7 tests now passing (previously 6) - File: slash-command-type-persistence.test.ts 2. ✅ Documented singleton testing pattern - Created comprehensive guide: singleton-testing-pattern-2024.md - Explains dynamic getInstance() vs static import issue - Includes real-world example from Issue #424 - Provides testing pattern and decision tree - Location: docs/architecture/development/lessons/ 3. ✅ Created follow-up issue for schema defaults - Issue #427: Apply schema defaults when converting node types - Tracks TODO from skipped test in slash-command-type-persistence.test.ts:341 - Updated test comment to reference Issue #427 - Properly scoped as future enhancement Reviewer suggestions addressed: 3/3 Nitpicks skipped: 2/2 (test naming and magic numbers - explained in PR comment) All tests passing (1582 tests) Code quality: 0 errors, 0 warnings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code Review Feedback - Implementation SummaryI've addressed all reviewer recommendations from the ✅ Implemented (3/3 Suggestions)1. Added Zero-Delay Timing TestLocation:
2. Documented Singleton Testing PatternLocation:
3. Created Follow-up Issue for Schema DefaultsIssue: #427 - Apply schema defaults when converting node types
⏭️ Skipped (2/2 Nitpicks)1. Test File Naming ConventionRationale: The current name
2. Extract Magic Numbers to ConstantsRationale: The timing values (50ms, 600ms) are already well-documented with inline comments:
Extracting to constants would:
Test ResultsCommits
Re-Review DecisionDecision: ✅ NO RE-REVIEW NEEDED Rationale:
The PR remains ready for merge. The original review's APPROVE AND MERGE recommendation stands. |
…nt (#425) * Fix: Node type conversions persist correctly (#424) ## Problem Slash command conversions (e.g., /task, /header) were not persisting correctly: - UI showed correct node type immediately - But database saved as text node with incomplete content - Page reload lost user work ## Root Cause ReactiveNodeService imported `sharedNodeStore` at module load time. When tests called `resetInstance()`, the service kept a reference to the old singleton, causing `updateNodeType()` to fail silently in tests (and potentially in production after hot reloads). ## Solution 1. **Fixed singleton reference**: Import `SharedNodeStore` class and call `getInstance()` dynamically inside `createReactiveNodeService()` instead of using module-level import 2. **Always include nodeType**: Modified `updateNodeContent()` to always include `nodeType` in updates to preserve slash command conversions ## Changes - `reactive-node-service.svelte.ts`: Import SharedNodeStore class instead of singleton, get instance dynamically, always include nodeType in content updates - Added comprehensive test suite: `slash-command-type-persistence.test.ts` with 7 tests covering slash commands, pattern detection, and content preservation ## Test Results - All 6 active tests pass (1 skipped for future schema defaults feature) - No regressions in existing test suite (86 files, 1550+ tests) - Tests verify: ✅ Slash command type persistence ✅ Pattern detection still works ✅ Full content persists (not truncated) ✅ Multiple content updates preserve type 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: Add timing test, documentation, and issue tracking Implemented reviewer suggestions from PR #425 code review: 1. ✅ Added zero-delay timing test - New test verifies synchronous store updates work with NO delay - Stress tests the assumption that updateNodeType() completes before updateNodeContent() - All 7 tests now passing (previously 6) - File: slash-command-type-persistence.test.ts 2. ✅ Documented singleton testing pattern - Created comprehensive guide: singleton-testing-pattern-2024.md - Explains dynamic getInstance() vs static import issue - Includes real-world example from Issue #424 - Provides testing pattern and decision tree - Location: docs/architecture/development/lessons/ 3. ✅ Created follow-up issue for schema defaults - Issue #427: Apply schema defaults when converting node types - Tracks TODO from skipped test in slash-command-type-persistence.test.ts:341 - Updated test comment to reference Issue #427 - Properly scoped as future enhancement Reviewer suggestions addressed: 3/3 Nitpicks skipped: 2/2 (test naming and magic numbers - explained in PR comment) All tests passing (1582 tests) Code quality: 0 errors, 0 warnings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
…nt (#425) * Fix: Node type conversions persist correctly (#424) ## Problem Slash command conversions (e.g., /task, /header) were not persisting correctly: - UI showed correct node type immediately - But database saved as text node with incomplete content - Page reload lost user work ## Root Cause ReactiveNodeService imported `sharedNodeStore` at module load time. When tests called `resetInstance()`, the service kept a reference to the old singleton, causing `updateNodeType()` to fail silently in tests (and potentially in production after hot reloads). ## Solution 1. **Fixed singleton reference**: Import `SharedNodeStore` class and call `getInstance()` dynamically inside `createReactiveNodeService()` instead of using module-level import 2. **Always include nodeType**: Modified `updateNodeContent()` to always include `nodeType` in updates to preserve slash command conversions ## Changes - `reactive-node-service.svelte.ts`: Import SharedNodeStore class instead of singleton, get instance dynamically, always include nodeType in content updates - Added comprehensive test suite: `slash-command-type-persistence.test.ts` with 7 tests covering slash commands, pattern detection, and content preservation ## Test Results - All 6 active tests pass (1 skipped for future schema defaults feature) - No regressions in existing test suite (86 files, 1550+ tests) - Tests verify: ✅ Slash command type persistence ✅ Pattern detection still works ✅ Full content persists (not truncated) ✅ Multiple content updates preserve type 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: Add timing test, documentation, and issue tracking Implemented reviewer suggestions from PR #425 code review: 1. ✅ Added zero-delay timing test - New test verifies synchronous store updates work with NO delay - Stress tests the assumption that updateNodeType() completes before updateNodeContent() - All 7 tests now passing (previously 6) - File: slash-command-type-persistence.test.ts 2. ✅ Documented singleton testing pattern - Created comprehensive guide: singleton-testing-pattern-2024.md - Explains dynamic getInstance() vs static import issue - Includes real-world example from Issue #424 - Provides testing pattern and decision tree - Location: docs/architecture/development/lessons/ 3. ✅ Created follow-up issue for schema defaults - Issue #427: Apply schema defaults when converting node types - Tracks TODO from skipped test in slash-command-type-persistence.test.ts:341 - Updated test comment to reference Issue #427 - Properly scoped as future enhancement Reviewer suggestions addressed: 3/3 Nitpicks skipped: 2/2 (test naming and magic numbers - explained in PR comment) All tests passing (1582 tests) Code quality: 0 errors, 0 warnings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
…nt (#425) * Fix: Node type conversions persist correctly (#424) ## Problem Slash command conversions (e.g., /task, /header) were not persisting correctly: - UI showed correct node type immediately - But database saved as text node with incomplete content - Page reload lost user work ## Root Cause ReactiveNodeService imported `sharedNodeStore` at module load time. When tests called `resetInstance()`, the service kept a reference to the old singleton, causing `updateNodeType()` to fail silently in tests (and potentially in production after hot reloads). ## Solution 1. **Fixed singleton reference**: Import `SharedNodeStore` class and call `getInstance()` dynamically inside `createReactiveNodeService()` instead of using module-level import 2. **Always include nodeType**: Modified `updateNodeContent()` to always include `nodeType` in updates to preserve slash command conversions ## Changes - `reactive-node-service.svelte.ts`: Import SharedNodeStore class instead of singleton, get instance dynamically, always include nodeType in content updates - Added comprehensive test suite: `slash-command-type-persistence.test.ts` with 7 tests covering slash commands, pattern detection, and content preservation ## Test Results - All 6 active tests pass (1 skipped for future schema defaults feature) - No regressions in existing test suite (86 files, 1550+ tests) - Tests verify: ✅ Slash command type persistence ✅ Pattern detection still works ✅ Full content persists (not truncated) ✅ Multiple content updates preserve type 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Address review: Add timing test, documentation, and issue tracking Implemented reviewer suggestions from PR #425 code review: 1. ✅ Added zero-delay timing test - New test verifies synchronous store updates work with NO delay - Stress tests the assumption that updateNodeType() completes before updateNodeContent() - All 7 tests now passing (previously 6) - File: slash-command-type-persistence.test.ts 2. ✅ Documented singleton testing pattern - Created comprehensive guide: singleton-testing-pattern-2024.md - Explains dynamic getInstance() vs static import issue - Includes real-world example from Issue #424 - Provides testing pattern and decision tree - Location: docs/architecture/development/lessons/ 3. ✅ Created follow-up issue for schema defaults - Issue #427: Apply schema defaults when converting node types - Tracks TODO from skipped test in slash-command-type-persistence.test.ts:341 - Updated test comment to reference Issue #427 - Properly scoped as future enhancement Reviewer suggestions addressed: 3/3 Nitpicks skipped: 2/2 (test naming and magic numbers - explained in PR comment) All tests passing (1582 tests) Code quality: 0 errors, 0 warnings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Closes #424