Skip to content

Fix UI & Service Integration Issues (ALL 14 test failures fixed - 100% complete) - #257

Merged
malibio merged 3 commits into
mainfrom
feature/issue-233-fix-ui-service-integration
Oct 12, 2025
Merged

malibio merged 3 commits into
mainfrom
feature/issue-233-fix-ui-service-integration

Conversation

@malibio

@malibio malibio commented Oct 12, 2025 •

Copy link
Copy Markdown
Collaborator

Summary

Fixed all 14 test failures from issue #233 by addressing three distinct root causes:

  1. Event-driven content reprocessing overwrote manually-set mentions
  2. Vitest module duplication created separate plugin registry instances
  3. Test used incorrect source type for persistence validation

Test Results - ALL PASSING ✅

Before: 14 test failures across 6 test files
After: 0 test failures - 100% complete

  • ✅ Node Operations: 28/28 tests (was 3 failures)
  • ✅ Slash Commands: 6/6 tests (was 5 failures)
  • ✅ SharedNodeStore: 52/52 tests (was 1 failure)
  • ✅ Hierarchy Service: 22/22 tests (was 4 failures)
  • ✅ Performance Tests: All passing (was 1 failure)
  • ✅ Node Ordering: 8/8 tests (already passing)

Fixes

1. Node Operations Tests (3 failures) - FIXED

Root Cause: Event-driven content reprocessing overwrote manually-set mentions

Problem:

  • updateNodeMentions() set mentions to ['root2']
  • SharedNodeStore.updateNode() emitted event with updateType: 'content'
  • Event triggered processContentMentions() which re-extracted from content (empty)
  • Re-extracted mentions overwrote the manual setting

Solution:

  • Modified SharedNodeStore.updateNode() to intelligently set updateType
  • When ONLY mentions change: updateType = 'metadata' (not 'content')
  • Prevents content reprocessing from overwriting manual mentions
  • Added skipConflictDetection: true for mentions (computed field)

Files Changed:

  • src/lib/services/shared-node-store.ts
  • src/lib/services/reactive-node-service.svelte.ts

2. Slash Command Integration Tests (5 failures) - FIXED

Root Cause: Vitest module duplication created two plugin registry instances

Problem:

Solution (Credit: @frontend-architect agent):

  • Moved plugin registration from global-setup.ts → setup.ts
  • Setup files run in SAME context (Happy-DOM) as tests
  • Single registry instance shared across all code
  • Real integration testing without mocks

Files Changed:

  • src/tests/setup.ts - Added plugin registration
  • src/tests/global-setup.ts - Removed registration, added documentation
  • src/lib/plugins/plugin-registry.ts - Proper TypeScript types
  • src/lib/components/viewers/index.ts - Removed duplicate registration

Documentation:

  • docs/architecture/development/lessons/vitest-module-duplication-fix.md - Complete analysis and solution

3. SharedNodeStore Test (1 failure) - FIXED

Root Cause: Test used viewer source but expected persistence

Problem:

  • Test called updateNode() with viewerSource for content change
  • Architecture: viewer content changes DON'T persist immediately
  • BaseNodeViewer handles debouncing for viewer sources
  • Test incorrectly expected immediate persistence

Solution:

  • Changed test to use external source instead of viewer source
  • External sources trigger proper debounced persistence
  • Test now correctly validates the persistence flow

Files Changed:

  • src/tests/services/shared-node-store.test.ts

Architecture Compliance

All fixes maintain proper architecture:

  • ✅ Always use PersistenceCoordinator (no direct database calls)
  • ✅ Event-driven updates with correct updateType
  • ✅ Real integration testing (no mocks for core services)
  • ✅ Proper separation of concerns (viewer vs external sources)

Quality Checks

  • ✅ bun run quality:fix - All checks passing
  • ✅ No lint errors or warnings
  • ✅ Type checking passing
  • ✅ Rust formatting and clippy passing

Test Plan

All test suites pass:

bunx vitest run src/tests/services/node-operations-service.test.ts
bunx vitest run src/tests/integration/slash-command-integration.test.ts
bunx vitest run src/tests/services/shared-node-store.test.ts
bunx vitest run src/tests/services/hierarchy-service.test.ts

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

- Added sharedNodeStore.__resetForTesting() to global beforeEach in setup.ts
- Prevents node data leakage between test suites
- Fixes all 4 hierarchy service test failures
- Also fixes performance test failure (getVisibleNodes)

Fixes #233 (partial - 5 of 14 failures fixed)

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

Co-Authored-By: Claude <[email protected]>
This commit resolves all remaining test failures from issue #233,
bringing the total fixes to 14/14 tests (100% complete).

## Fixes

### 1. Node Operations Tests (3 failures) - FIXED
**Root Cause**: Event-driven content reprocessing overwrote manually-set mentions

**Problem**:
- updateNodeMentions() set mentions to ['root2']
- SharedNodeStore.updateNode() emitted event with updateType: 'content'
- Event triggered processContentMentions() which re-extracted from content
- Re-extracted mentions (empty) overwrote the manual setting

**Solution**:
- Modified SharedNodeStore.updateNode() to intelligently set updateType
- When ONLY mentions change: updateType = 'metadata' (not 'content')
- Prevents content reprocessing from overwriting manual mentions
- Added skipConflictDetection for mentions (computed field)

**Files**:
- src/lib/services/shared-node-store.ts
- src/lib/services/reactive-node-service.svelte.ts

### 2. Slash Command Integration Tests (5 failures) - FIXED
**Root Cause**: Vitest module duplication created two plugin registry instances

**Problem**:
- Global setup (Node context) registered plugins to instance #1
- Tests (Happy-DOM context) accessed instance #2 with 0 plugins
- Vite creates separate module graphs for different contexts
- Even globalThis singleton couldn't bridge the gap

**Solution** (Credit: frontend-architect agent):
- Moved plugin registration from global-setup.ts → setup.ts
- Setup files run in SAME context (Happy-DOM) as tests
- Single registry instance shared across all code
- Real integration testing without mocks

**Files**:
- src/tests/setup.ts - Added plugin registration
- src/tests/global-setup.ts - Removed registration, added docs
- src/lib/plugins/plugin-registry.ts - Proper TypeScript types
- src/lib/components/viewers/index.ts - Removed duplicate registration

**Documentation**:
- Added comprehensive lesson learned doc explaining the issue

### 3. SharedNodeStore Test (1 failure) - FIXED
**Root Cause**: Test used viewer source but expected persistence

**Problem**:
- Test called updateNode() with viewerSource for content change
- Architecture: viewer content changes DON'T persist immediately
- BaseNodeViewer handles debouncing for viewer sources
- Test incorrectly expected immediate persistence

**Solution**:
- Changed test to use external source instead of viewer source
- External sources trigger proper debounced persistence
- Test now correctly validates the persistence flow

**Files**:
- src/tests/services/shared-node-store.test.ts

## Architecture Compliance

All fixes maintain proper architecture:
✅ Always use PersistenceCoordinator (no direct database calls)
✅ Event-driven updates with correct updateType
✅ Real integration testing (no mocks for core services)
✅ Proper separation of concerns (viewer vs external sources)

## Test Results

Before: 14 test failures across 6 test files
After: 0 test failures - ALL TESTS PASSING (100%)

- ✅ Node Operations: 28/28 tests passing
- ✅ Slash Commands: 6/6 tests passing
- ✅ SharedNodeStore: 52/52 tests passing
- ✅ Hierarchy Service: 22/22 tests passing (from PR #257)
- ✅ Performance Tests: All passing (from PR #257)
- ✅ Node Ordering: 8/8 tests passing (already fixed)

## Quality Checks

✅ bun run quality:fix - All checks passing
✅ No lint errors or warnings
✅ Type checking passing
✅ Rust formatting and clippy passing

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

Co-Authored-By: Claude <[email protected]>
@malibio malibio changed the title Fix UI & Service Integration Issues (5 of 14 test failures fixed) Fix UI & Service Integration Issues (ALL 14 test failures fixed - 100% complete) Oct 12, 2025
This commit implements all recommendations from the pragmatic code review,
including the optional/nice-to-have improvements.

## Changes

### 1. Extract determineUpdateType() Logic
- Added private methods `determineUpdateType()` and `isMetadataOnlyUpdate()`
- Improves testability and maintainability
- Makes it easier to add new computed fields in the future
- Files: `shared-node-store.ts`

### 2. Add isComputedField Flag
- Added `isComputedField` flag to `UpdateOptions` interface
- Automatically sets skipPersistence=true and skipConflictDetection=true
- Makes intent explicit when updating computed/derived fields
- Updated `updateNodeMentions()` to use the new flag
- Files: `update-protocol.ts`, `shared-node-store.ts`, `reactive-node-service.svelte.ts`

### 3. Simplify Plugin Registry Singleton
- Removed globalThis pattern (didn't solve duplication anyway)
- Now uses simple module-level export
- Clearer comments explaining Vitest context separation
- Files: `plugin-registry.ts`

### 4. Add Table of Contents to Documentation
- Added comprehensive TOC to vitest-module-duplication-fix.md
- Improves navigation for the 257-line document
- Files: `vitest-module-duplication-fix.md`

### 5. Improve Plugin Registration Error Handling
- Added try-catch around plugin registration in setup.ts
- Better error messages for debugging
- Fail-fast behavior ensures tests can't run without plugins
- Files: `setup.ts`

### 6. Add Testing Pattern to Main Documentation
- Added "CRITICAL: Vitest Setup File Pattern" section to testing-guide.md
- Explains when to use setupFiles vs globalSetup
- Includes correct and wrong patterns with examples
- Links to detailed lesson learned document
- Files: `testing-guide.md`

### 7. Create Follow-up Issue
- Created issue #258 for SharedNodeStore unhandled rejection errors
- Documents the 966 unhandled promise rejections from cancelPending()
- Not blocking for this PR (pre-existing issue)

## Quality Checks

✅ All lint/format checks passing
✅ Type checking passing
✅ Rust formatting and clippy passing
✅ No breaking changes

## Related Issues

- Implements all recommendations from pragmatic-code-review of #233
- Creates follow-up issue #258 for test infrastructure improvements

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

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit 7c49fb0 into main Oct 12, 2025
@malibio
malibio deleted the feature/issue-233-fix-ui-service-integration branch October 12, 2025 20:14
malibio added a commit that referenced this pull request Feb 4, 2026
…% complete) (#257)

* Fix hierarchy service tests by resetting SharedNodeStore between tests

- Added sharedNodeStore.__resetForTesting() to global beforeEach in setup.ts
- Prevents node data leakage between test suites
- Fixes all 4 hierarchy service test failures
- Also fixes performance test failure (getVisibleNodes)

Fixes #233 (partial - 5 of 14 failures fixed)

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

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

* Fix all 9 remaining UI & service integration test failures

This commit resolves all remaining test failures from issue #233,
bringing the total fixes to 14/14 tests (100% complete).

## Fixes

### 1. Node Operations Tests (3 failures) - FIXED
**Root Cause**: Event-driven content reprocessing overwrote manually-set mentions

**Problem**:
- updateNodeMentions() set mentions to ['root2']
- SharedNodeStore.updateNode() emitted event with updateType: 'content'
- Event triggered processContentMentions() which re-extracted from content
- Re-extracted mentions (empty) overwrote the manual setting

**Solution**:
- Modified SharedNodeStore.updateNode() to intelligently set updateType
- When ONLY mentions change: updateType = 'metadata' (not 'content')
- Prevents content reprocessing from overwriting manual mentions
- Added skipConflictDetection for mentions (computed field)

**Files**:
- src/lib/services/shared-node-store.ts
- src/lib/services/reactive-node-service.svelte.ts

### 2. Slash Command Integration Tests (5 failures) - FIXED
**Root Cause**: Vitest module duplication created two plugin registry instances

**Problem**:
- Global setup (Node context) registered plugins to instance #1
- Tests (Happy-DOM context) accessed instance #2 with 0 plugins
- Vite creates separate module graphs for different contexts
- Even globalThis singleton couldn't bridge the gap

**Solution** (Credit: frontend-architect agent):
- Moved plugin registration from global-setup.ts → setup.ts
- Setup files run in SAME context (Happy-DOM) as tests
- Single registry instance shared across all code
- Real integration testing without mocks

**Files**:
- src/tests/setup.ts - Added plugin registration
- src/tests/global-setup.ts - Removed registration, added docs
- src/lib/plugins/plugin-registry.ts - Proper TypeScript types
- src/lib/components/viewers/index.ts - Removed duplicate registration

**Documentation**:
- Added comprehensive lesson learned doc explaining the issue

### 3. SharedNodeStore Test (1 failure) - FIXED
**Root Cause**: Test used viewer source but expected persistence

**Problem**:
- Test called updateNode() with viewerSource for content change
- Architecture: viewer content changes DON'T persist immediately
- BaseNodeViewer handles debouncing for viewer sources
- Test incorrectly expected immediate persistence

**Solution**:
- Changed test to use external source instead of viewer source
- External sources trigger proper debounced persistence
- Test now correctly validates the persistence flow

**Files**:
- src/tests/services/shared-node-store.test.ts

## Architecture Compliance

All fixes maintain proper architecture:
✅ Always use PersistenceCoordinator (no direct database calls)
✅ Event-driven updates with correct updateType
✅ Real integration testing (no mocks for core services)
✅ Proper separation of concerns (viewer vs external sources)

## Test Results

Before: 14 test failures across 6 test files
After: 0 test failures - ALL TESTS PASSING (100%)

- ✅ Node Operations: 28/28 tests passing
- ✅ Slash Commands: 6/6 tests passing
- ✅ SharedNodeStore: 52/52 tests passing
- ✅ Hierarchy Service: 22/22 tests passing (from PR #257)
- ✅ Performance Tests: All passing (from PR #257)
- ✅ Node Ordering: 8/8 tests passing (already fixed)

## Quality Checks

✅ bun run quality:fix - All checks passing
✅ No lint errors or warnings
✅ Type checking passing
✅ Rust formatting and clippy passing

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

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

* Implement code review recommendations for issue #233

This commit implements all recommendations from the pragmatic code review,
including the optional/nice-to-have improvements.

## Changes

### 1. Extract determineUpdateType() Logic
- Added private methods `determineUpdateType()` and `isMetadataOnlyUpdate()`
- Improves testability and maintainability
- Makes it easier to add new computed fields in the future
- Files: `shared-node-store.ts`

### 2. Add isComputedField Flag
- Added `isComputedField` flag to `UpdateOptions` interface
- Automatically sets skipPersistence=true and skipConflictDetection=true
- Makes intent explicit when updating computed/derived fields
- Updated `updateNodeMentions()` to use the new flag
- Files: `update-protocol.ts`, `shared-node-store.ts`, `reactive-node-service.svelte.ts`

### 3. Simplify Plugin Registry Singleton
- Removed globalThis pattern (didn't solve duplication anyway)
- Now uses simple module-level export
- Clearer comments explaining Vitest context separation
- Files: `plugin-registry.ts`

### 4. Add Table of Contents to Documentation
- Added comprehensive TOC to vitest-module-duplication-fix.md
- Improves navigation for the 257-line document
- Files: `vitest-module-duplication-fix.md`

### 5. Improve Plugin Registration Error Handling
- Added try-catch around plugin registration in setup.ts
- Better error messages for debugging
- Fail-fast behavior ensures tests can't run without plugins
- Files: `setup.ts`

### 6. Add Testing Pattern to Main Documentation
- Added "CRITICAL: Vitest Setup File Pattern" section to testing-guide.md
- Explains when to use setupFiles vs globalSetup
- Includes correct and wrong patterns with examples
- Links to detailed lesson learned document
- Files: `testing-guide.md`

### 7. Create Follow-up Issue
- Created issue #258 for SharedNodeStore unhandled rejection errors
- Documents the 966 unhandled promise rejections from cancelPending()
- Not blocking for this PR (pre-existing issue)

## Quality Checks

✅ All lint/format checks passing
✅ Type checking passing
✅ Rust formatting and clippy passing
✅ No breaking changes

## Related Issues

- Implements all recommendations from pragmatic-code-review of #233
- Creates follow-up issue #258 for test infrastructure improvements

🤖 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
…% complete) (#257)

* Fix hierarchy service tests by resetting SharedNodeStore between tests

- Added sharedNodeStore.__resetForTesting() to global beforeEach in setup.ts
- Prevents node data leakage between test suites
- Fixes all 4 hierarchy service test failures
- Also fixes performance test failure (getVisibleNodes)

Fixes #233 (partial - 5 of 14 failures fixed)

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

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

* Fix all 9 remaining UI & service integration test failures

This commit resolves all remaining test failures from issue #233,
bringing the total fixes to 14/14 tests (100% complete).

## Fixes

### 1. Node Operations Tests (3 failures) - FIXED
**Root Cause**: Event-driven content reprocessing overwrote manually-set mentions

**Problem**:
- updateNodeMentions() set mentions to ['root2']
- SharedNodeStore.updateNode() emitted event with updateType: 'content'
- Event triggered processContentMentions() which re-extracted from content
- Re-extracted mentions (empty) overwrote the manual setting

**Solution**:
- Modified SharedNodeStore.updateNode() to intelligently set updateType
- When ONLY mentions change: updateType = 'metadata' (not 'content')
- Prevents content reprocessing from overwriting manual mentions
- Added skipConflictDetection for mentions (computed field)

**Files**:
- src/lib/services/shared-node-store.ts
- src/lib/services/reactive-node-service.svelte.ts

### 2. Slash Command Integration Tests (5 failures) - FIXED
**Root Cause**: Vitest module duplication created two plugin registry instances

**Problem**:
- Global setup (Node context) registered plugins to instance #1
- Tests (Happy-DOM context) accessed instance #2 with 0 plugins
- Vite creates separate module graphs for different contexts
- Even globalThis singleton couldn't bridge the gap

**Solution** (Credit: frontend-architect agent):
- Moved plugin registration from global-setup.ts → setup.ts
- Setup files run in SAME context (Happy-DOM) as tests
- Single registry instance shared across all code
- Real integration testing without mocks

**Files**:
- src/tests/setup.ts - Added plugin registration
- src/tests/global-setup.ts - Removed registration, added docs
- src/lib/plugins/plugin-registry.ts - Proper TypeScript types
- src/lib/components/viewers/index.ts - Removed duplicate registration

**Documentation**:
- Added comprehensive lesson learned doc explaining the issue

### 3. SharedNodeStore Test (1 failure) - FIXED
**Root Cause**: Test used viewer source but expected persistence

**Problem**:
- Test called updateNode() with viewerSource for content change
- Architecture: viewer content changes DON'T persist immediately
- BaseNodeViewer handles debouncing for viewer sources
- Test incorrectly expected immediate persistence

**Solution**:
- Changed test to use external source instead of viewer source
- External sources trigger proper debounced persistence
- Test now correctly validates the persistence flow

**Files**:
- src/tests/services/shared-node-store.test.ts

## Architecture Compliance

All fixes maintain proper architecture:
✅ Always use PersistenceCoordinator (no direct database calls)
✅ Event-driven updates with correct updateType
✅ Real integration testing (no mocks for core services)
✅ Proper separation of concerns (viewer vs external sources)

## Test Results

Before: 14 test failures across 6 test files
After: 0 test failures - ALL TESTS PASSING (100%)

- ✅ Node Operations: 28/28 tests passing
- ✅ Slash Commands: 6/6 tests passing
- ✅ SharedNodeStore: 52/52 tests passing
- ✅ Hierarchy Service: 22/22 tests passing (from PR #257)
- ✅ Performance Tests: All passing (from PR #257)
- ✅ Node Ordering: 8/8 tests passing (already fixed)

## Quality Checks

✅ bun run quality:fix - All checks passing
✅ No lint errors or warnings
✅ Type checking passing
✅ Rust formatting and clippy passing

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

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

* Implement code review recommendations for issue #233

This commit implements all recommendations from the pragmatic code review,
including the optional/nice-to-have improvements.

## Changes

### 1. Extract determineUpdateType() Logic
- Added private methods `determineUpdateType()` and `isMetadataOnlyUpdate()`
- Improves testability and maintainability
- Makes it easier to add new computed fields in the future
- Files: `shared-node-store.ts`

### 2. Add isComputedField Flag
- Added `isComputedField` flag to `UpdateOptions` interface
- Automatically sets skipPersistence=true and skipConflictDetection=true
- Makes intent explicit when updating computed/derived fields
- Updated `updateNodeMentions()` to use the new flag
- Files: `update-protocol.ts`, `shared-node-store.ts`, `reactive-node-service.svelte.ts`

### 3. Simplify Plugin Registry Singleton
- Removed globalThis pattern (didn't solve duplication anyway)
- Now uses simple module-level export
- Clearer comments explaining Vitest context separation
- Files: `plugin-registry.ts`

### 4. Add Table of Contents to Documentation
- Added comprehensive TOC to vitest-module-duplication-fix.md
- Improves navigation for the 257-line document
- Files: `vitest-module-duplication-fix.md`

### 5. Improve Plugin Registration Error Handling
- Added try-catch around plugin registration in setup.ts
- Better error messages for debugging
- Fail-fast behavior ensures tests can't run without plugins
- Files: `setup.ts`

### 6. Add Testing Pattern to Main Documentation
- Added "CRITICAL: Vitest Setup File Pattern" section to testing-guide.md
- Explains when to use setupFiles vs globalSetup
- Includes correct and wrong patterns with examples
- Links to detailed lesson learned document
- Files: `testing-guide.md`

### 7. Create Follow-up Issue
- Created issue #258 for SharedNodeStore unhandled rejection errors
- Documents the 966 unhandled promise rejections from cancelPending()
- Not blocking for this PR (pre-existing issue)

## Quality Checks

✅ All lint/format checks passing
✅ Type checking passing
✅ Rust formatting and clippy passing
✅ No breaking changes

## Related Issues

- Implements all recommendations from pragmatic-code-review of #233
- Creates follow-up issue #258 for test infrastructure improvements

🤖 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
…% complete) (#257)

* Fix hierarchy service tests by resetting SharedNodeStore between tests

- Added sharedNodeStore.__resetForTesting() to global beforeEach in setup.ts
- Prevents node data leakage between test suites
- Fixes all 4 hierarchy service test failures
- Also fixes performance test failure (getVisibleNodes)

Fixes #233 (partial - 5 of 14 failures fixed)

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

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

* Fix all 9 remaining UI & service integration test failures

This commit resolves all remaining test failures from issue #233,
bringing the total fixes to 14/14 tests (100% complete).

## Fixes

### 1. Node Operations Tests (3 failures) - FIXED
**Root Cause**: Event-driven content reprocessing overwrote manually-set mentions

**Problem**:
- updateNodeMentions() set mentions to ['root2']
- SharedNodeStore.updateNode() emitted event with updateType: 'content'
- Event triggered processContentMentions() which re-extracted from content
- Re-extracted mentions (empty) overwrote the manual setting

**Solution**:
- Modified SharedNodeStore.updateNode() to intelligently set updateType
- When ONLY mentions change: updateType = 'metadata' (not 'content')
- Prevents content reprocessing from overwriting manual mentions
- Added skipConflictDetection for mentions (computed field)

**Files**:
- src/lib/services/shared-node-store.ts
- src/lib/services/reactive-node-service.svelte.ts

### 2. Slash Command Integration Tests (5 failures) - FIXED
**Root Cause**: Vitest module duplication created two plugin registry instances

**Problem**:
- Global setup (Node context) registered plugins to instance #1
- Tests (Happy-DOM context) accessed instance #2 with 0 plugins
- Vite creates separate module graphs for different contexts
- Even globalThis singleton couldn't bridge the gap

**Solution** (Credit: frontend-architect agent):
- Moved plugin registration from global-setup.ts → setup.ts
- Setup files run in SAME context (Happy-DOM) as tests
- Single registry instance shared across all code
- Real integration testing without mocks

**Files**:
- src/tests/setup.ts - Added plugin registration
- src/tests/global-setup.ts - Removed registration, added docs
- src/lib/plugins/plugin-registry.ts - Proper TypeScript types
- src/lib/components/viewers/index.ts - Removed duplicate registration

**Documentation**:
- Added comprehensive lesson learned doc explaining the issue

### 3. SharedNodeStore Test (1 failure) - FIXED
**Root Cause**: Test used viewer source but expected persistence

**Problem**:
- Test called updateNode() with viewerSource for content change
- Architecture: viewer content changes DON'T persist immediately
- BaseNodeViewer handles debouncing for viewer sources
- Test incorrectly expected immediate persistence

**Solution**:
- Changed test to use external source instead of viewer source
- External sources trigger proper debounced persistence
- Test now correctly validates the persistence flow

**Files**:
- src/tests/services/shared-node-store.test.ts

## Architecture Compliance

All fixes maintain proper architecture:
✅ Always use PersistenceCoordinator (no direct database calls)
✅ Event-driven updates with correct updateType
✅ Real integration testing (no mocks for core services)
✅ Proper separation of concerns (viewer vs external sources)

## Test Results

Before: 14 test failures across 6 test files
After: 0 test failures - ALL TESTS PASSING (100%)

- ✅ Node Operations: 28/28 tests passing
- ✅ Slash Commands: 6/6 tests passing
- ✅ SharedNodeStore: 52/52 tests passing
- ✅ Hierarchy Service: 22/22 tests passing (from PR #257)
- ✅ Performance Tests: All passing (from PR #257)
- ✅ Node Ordering: 8/8 tests passing (already fixed)

## Quality Checks

✅ bun run quality:fix - All checks passing
✅ No lint errors or warnings
✅ Type checking passing
✅ Rust formatting and clippy passing

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

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

* Implement code review recommendations for issue #233

This commit implements all recommendations from the pragmatic code review,
including the optional/nice-to-have improvements.

## Changes

### 1. Extract determineUpdateType() Logic
- Added private methods `determineUpdateType()` and `isMetadataOnlyUpdate()`
- Improves testability and maintainability
- Makes it easier to add new computed fields in the future
- Files: `shared-node-store.ts`

### 2. Add isComputedField Flag
- Added `isComputedField` flag to `UpdateOptions` interface
- Automatically sets skipPersistence=true and skipConflictDetection=true
- Makes intent explicit when updating computed/derived fields
- Updated `updateNodeMentions()` to use the new flag
- Files: `update-protocol.ts`, `shared-node-store.ts`, `reactive-node-service.svelte.ts`

### 3. Simplify Plugin Registry Singleton
- Removed globalThis pattern (didn't solve duplication anyway)
- Now uses simple module-level export
- Clearer comments explaining Vitest context separation
- Files: `plugin-registry.ts`

### 4. Add Table of Contents to Documentation
- Added comprehensive TOC to vitest-module-duplication-fix.md
- Improves navigation for the 257-line document
- Files: `vitest-module-duplication-fix.md`

### 5. Improve Plugin Registration Error Handling
- Added try-catch around plugin registration in setup.ts
- Better error messages for debugging
- Fail-fast behavior ensures tests can't run without plugins
- Files: `setup.ts`

### 6. Add Testing Pattern to Main Documentation
- Added "CRITICAL: Vitest Setup File Pattern" section to testing-guide.md
- Explains when to use setupFiles vs globalSetup
- Includes correct and wrong patterns with examples
- Links to detailed lesson learned document
- Files: `testing-guide.md`

### 7. Create Follow-up Issue
- Created issue #258 for SharedNodeStore unhandled rejection errors
- Documents the 966 unhandled promise rejections from cancelPending()
- Not blocking for this PR (pre-existing issue)

## Quality Checks

✅ All lint/format checks passing
✅ Type checking passing
✅ Rust formatting and clippy passing
✅ No breaking changes

## Related Issues

- Implements all recommendations from pragmatic-code-review of #233
- Creates follow-up issue #258 for test infrastructure improvements

🤖 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.

1 participant