Test Coverage: Address gaps from PR #861 and improve race condition detection#878
Conversation
Agents repeatedly make the mistake of running `bun run gh:*` commands from subdirectories like packages/desktop-app/ instead of the repo root. These commands fail with "Script not found" because the gh scripts are defined in the root package.json. Added: - Prominent warning in startup sequence step 4 with correct/wrong examples - Reminder notes on steps 7 and 8 (assign/status commands) - New entry in "Common mistakes agents make" list Co-Authored-By: Claude <noreply@anthropic.com>
#870 Part 1) ## Part 1: Unit Test Coverage Gaps ### TypeScript (Frontend) - Add 13 tests for `calculateOutdentInsertOrderPure()` in reactive-node-service - Refactored to pure function for testability - Tests edge cases: empty parent, missing old parent, single/many children - Tests fractional order precision and various positions - Add 6 tests for `flushAndWaitForNodes()` in shared-node-store-coverage - Tests flushing specific nodes, concurrent flush requests - Tests timeout behavior, mix of pending/non-pending nodes - Tests error reporting for failed operations - Add 10 tests for pending-operations module - Now imports actual module exports instead of reimplementing logic - Tests trackMoveOperation, waitForPendingMoveOperations, getPendingMoveOperation - Tests race condition prevention patterns (Issue #662 scenario) ### Rust (Backend) - Add 3 tests for `node_exists()` in surreal_store - Tests existing node returns true, non-existent returns false - Tests returns false after deletion - Add 3 tests for `get_parent_id()` in surreal_store - Tests root node returns None, child returns correct parent ID - Tests non-existent node returns None - Add 4 tests for `get_node_type()` in surreal_store - Tests correct type for text, task, date nodes - Tests non-existent node returns None ## Test Summary - Frontend: +28 tests (3501 → 3529) - Rust: +10 tests (767 → 777) Part 2 (test infrastructure improvements) to be addressed separately. Co-Authored-By: Claude <noreply@anthropic.com>
Code Review Report - PR #878Reviewer: Principal Engineer (AI Agent) SummaryThis PR adds comprehensive test coverage for critical functions identified in Issue #870 Part 1. The implementation is well-structured, follows project conventions, and improves testability by refactoring the Requirements ValidationIssue #870 Part 1 Acceptance Criteria:
Test counts match PR description: Frontend +28, Rust +10 Findings by PriorityArchitectural Design & Integrity[Positive] Pure Function Refactoring:
// Before: tightly coupled to structureTree
function calculateOutdentInsertOrder(newParentId: string, oldParentId: string): number {
const newParentChildren = structureTree.getChildrenWithOrder(newParentId);
// ... logic using newParentChildren
}
// After: pure function with injected dependencies
export function calculateOutdentInsertOrderPure(
children: Array<{ nodeId: string; order: number }>,
oldParentId: string
): number { /* pure logic */ }[Positive] Module Import Compliance: [Positive] CLAUDE.md Documentation: Functionality & CorrectnessAll test scenarios verify correct behavior:
Testing StrategyExcellent test organization:
SecurityNo security concerns - this PR adds test coverage only, no changes to security-sensitive paths. PerformanceNo performance concerns - tests use appropriate timeouts and add no overhead to production code. Nitpicks (Optional)Nit: The // Use real timers because we're testing actual timing coordination
// (fake timers don't properly simulate Promise.race/setTimeout interactions)
vi.useRealTimers();Nit: Consider extracting the repeated unique ID generation pattern: const uniqueNodeId = (prefix: string) => `${prefix}-${Math.random().toString(36).slice(2)}`;
// Usage: const nodeId = uniqueNodeId('test-node');ConclusionThis is a well-executed PR that directly addresses Issue #870 Part 1 requirements. The refactoring of Net Positive: YES - Improves test coverage + improves code testability Reviewed using the Pragmatic Code Review framework |
Reviewer nitpicks addressed: - Added `uniqueNodeId()` helper function for generating unique test node IDs - Added JSDoc explaining why unique IDs are needed (global module state) - Added comment block explaining why real timers are required for race condition tests (fake timers don't properly simulate Promise.race) Co-Authored-By: Claude <noreply@anthropic.com>
Review Feedback AddressedAddressed all reviewer nitpicks:
Commit: a56caba No re-review needed - these were minor documentation/style improvements with no logic changes. |
## Part 2A: Browser Integration Test Infrastructure - Added `rapid-keyboard-operations.test.ts` with 13 tests for: - Keyboard event sequencing (Enter→Tab, Tab→Shift+Tab patterns) - Focus management during rapid operations - High-frequency event handling (500+ events) - Event prevention and bubbling behavior ## Part 2B: Stress Tests for Rapid Indent/Outdent - Added `rapid-hierarchy-operations.test.ts` with 17 tests for: - `calculateOutdentInsertOrderPure()` edge cases - Floating point precision limits (50+ rapid insertions) - Concurrent operation simulation - Out-of-order completion patterns - PR #861 race condition scenarios ## Part 2C: test:integration:full Command - Added `test:integration:full` script that runs: - Unit tests (bun run test) - Browser tests (bun run test:browser) - Performance tests (bun run test:perf) - Rust tests (bun run rust:test) ## Documentation - Updated testing-guide.md with: - Stress test documentation and examples - Instructions for running tests - Future E2E testing considerations Test Results: - Frontend: 3546 tests passed (45 new tests added) - Browser: 90 tests passed (13 new tests added) - Rust: 777 tests passed Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Part 2 Complete ✅Added stress tests and browser integration tests for race condition detection. Part 2A: Browser Integration Tests
Part 2B: Stress Tests
Part 2C: test:integration:full Command
Updated Documentation
Final Test Results
All acceptance criteria from #870 are now complete. |
Documents the workflow for converting discovered UX bugs into regression tests: - Workflow steps: Discover → Fix → Test → Commit - Table mapping bug types to test file locations - Concrete example with Backspace→Enter sequence - Commit message convention for bug fixes with tests Key principle: Manual testing finds bugs, automated tests prevent regressions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Code Review Report - PR #878 (Re-Review: Part 2 Additions)Reviewer: Principal Engineer (AI Agent) SummaryThis re-review covers the Part 2 additions to Issue #870: stress tests for race condition detection, browser integration tests, and documentation updates. The initial review approved Part 1 (unit test coverage gaps) and the two nitpick suggestions have been addressed. Scope of Re-Review:
Requirements ValidationIssue #870 Acceptance Criteria:
Findings by PriorityArchitectural Design & Integrity[Positive] Well-Structured Browser Tests: [Positive] Stress Test Coverage: [Positive] Pure Function Testing Pattern Maintained: Functionality & Correctness[Positive] Race Condition Scenario Coverage:
[Positive] Floating Point Precision Demonstration: Testing Strategy[Positive] Test:Integration:Full Command: bun run test && bun run test:browser && bun run test:perf && bun run rust:testThis directly addresses acceptance criterion Part 2C. [Positive] Documentation Quality:
SecurityNo security concerns - this PR adds test coverage only. PerformanceNo performance concerns - test execution times are appropriate for their purpose. Minor Observations (Non-Blocking)Nit: In Nit: The Comparison: Initial Review vs Re-Review
ConclusionAll Part 2 acceptance criteria are met. The stress tests provide valuable race condition detection capabilities that would have caught the PR #861 bugs proactively. The browser tests focus appropriately on browser-specific APIs rather than overcomplicating with full component rendering. Net Positive: YES - Significantly improves race condition detection and documents testing strategy Reviewed using the Pragmatic Code Review framework |
malibio
left a comment
There was a problem hiding this comment.
REVIEW COMPLETE: All Issue #870 acceptance criteria satisfied. Part 1 unit tests and Part 2 stress tests/browser tests provide comprehensive coverage for race condition detection. Documentation is thorough. Recommendation: APPROVE (pending human reviewer approval due to GitHub self-review restriction).
Review Feedback AssessmentReviewed the re-review nitpicks from the code review:
Summary:
Conclusion: The implementation is already optimal. No additional changes required. |
…etection (#878) * Docs: Add explicit warning about gh script directory requirement Agents repeatedly make the mistake of running `bun run gh:*` commands from subdirectories like packages/desktop-app/ instead of the repo root. These commands fail with "Script not found" because the gh scripts are defined in the root package.json. Added: - Prominent warning in startup sequence step 4 with correct/wrong examples - Reminder notes on steps 7 and 8 (assign/status commands) - New entry in "Common mistakes agents make" list Co-Authored-By: Claude <noreply@anthropic.com> * Test: Add comprehensive unit tests for PR #861 helper functions (closes #870 Part 1) ## Part 1: Unit Test Coverage Gaps ### TypeScript (Frontend) - Add 13 tests for `calculateOutdentInsertOrderPure()` in reactive-node-service - Refactored to pure function for testability - Tests edge cases: empty parent, missing old parent, single/many children - Tests fractional order precision and various positions - Add 6 tests for `flushAndWaitForNodes()` in shared-node-store-coverage - Tests flushing specific nodes, concurrent flush requests - Tests timeout behavior, mix of pending/non-pending nodes - Tests error reporting for failed operations - Add 10 tests for pending-operations module - Now imports actual module exports instead of reimplementing logic - Tests trackMoveOperation, waitForPendingMoveOperations, getPendingMoveOperation - Tests race condition prevention patterns (Issue #662 scenario) ### Rust (Backend) - Add 3 tests for `node_exists()` in surreal_store - Tests existing node returns true, non-existent returns false - Tests returns false after deletion - Add 3 tests for `get_parent_id()` in surreal_store - Tests root node returns None, child returns correct parent ID - Tests non-existent node returns None - Add 4 tests for `get_node_type()` in surreal_store - Tests correct type for text, task, date nodes - Tests non-existent node returns None ## Test Summary - Frontend: +28 tests (3501 → 3529) - Rust: +10 tests (767 → 777) Part 2 (test infrastructure improvements) to be addressed separately. Co-Authored-By: Claude <noreply@anthropic.com> * Address review: Add helper function and document real timer usage Reviewer nitpicks addressed: - Added `uniqueNodeId()` helper function for generating unique test node IDs - Added JSDoc explaining why unique IDs are needed (global module state) - Added comment block explaining why real timers are required for race condition tests (fake timers don't properly simulate Promise.race) Co-Authored-By: Claude <noreply@anthropic.com> * Test: Add stress tests for race condition detection (closes #870 Part 2) ## Part 2A: Browser Integration Test Infrastructure - Added `rapid-keyboard-operations.test.ts` with 13 tests for: - Keyboard event sequencing (Enter→Tab, Tab→Shift+Tab patterns) - Focus management during rapid operations - High-frequency event handling (500+ events) - Event prevention and bubbling behavior ## Part 2B: Stress Tests for Rapid Indent/Outdent - Added `rapid-hierarchy-operations.test.ts` with 17 tests for: - `calculateOutdentInsertOrderPure()` edge cases - Floating point precision limits (50+ rapid insertions) - Concurrent operation simulation - Out-of-order completion patterns - PR #861 race condition scenarios ## Part 2C: test:integration:full Command - Added `test:integration:full` script that runs: - Unit tests (bun run test) - Browser tests (bun run test:browser) - Performance tests (bun run test:perf) - Rust tests (bun run rust:test) ## Documentation - Updated testing-guide.md with: - Stress test documentation and examples - Instructions for running tests - Future E2E testing considerations Test Results: - Frontend: 3546 tests passed (45 new tests added) - Browser: 90 tests passed (13 new tests added) - Rust: 777 tests passed Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Docs: Add UX bug → regression test workflow to testing guide Documents the workflow for converting discovered UX bugs into regression tests: - Workflow steps: Discover → Fix → Test → Commit - Table mapping bug types to test file locations - Concrete example with Backspace→Enter sequence - Commit message convention for bug fixes with tests Key principle: Manual testing finds bugs, automated tests prevent regressions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
…etection (#878) * Docs: Add explicit warning about gh script directory requirement Agents repeatedly make the mistake of running `bun run gh:*` commands from subdirectories like packages/desktop-app/ instead of the repo root. These commands fail with "Script not found" because the gh scripts are defined in the root package.json. Added: - Prominent warning in startup sequence step 4 with correct/wrong examples - Reminder notes on steps 7 and 8 (assign/status commands) - New entry in "Common mistakes agents make" list Co-Authored-By: Claude <noreply@anthropic.com> * Test: Add comprehensive unit tests for PR #861 helper functions (closes #870 Part 1) ## Part 1: Unit Test Coverage Gaps ### TypeScript (Frontend) - Add 13 tests for `calculateOutdentInsertOrderPure()` in reactive-node-service - Refactored to pure function for testability - Tests edge cases: empty parent, missing old parent, single/many children - Tests fractional order precision and various positions - Add 6 tests for `flushAndWaitForNodes()` in shared-node-store-coverage - Tests flushing specific nodes, concurrent flush requests - Tests timeout behavior, mix of pending/non-pending nodes - Tests error reporting for failed operations - Add 10 tests for pending-operations module - Now imports actual module exports instead of reimplementing logic - Tests trackMoveOperation, waitForPendingMoveOperations, getPendingMoveOperation - Tests race condition prevention patterns (Issue #662 scenario) ### Rust (Backend) - Add 3 tests for `node_exists()` in surreal_store - Tests existing node returns true, non-existent returns false - Tests returns false after deletion - Add 3 tests for `get_parent_id()` in surreal_store - Tests root node returns None, child returns correct parent ID - Tests non-existent node returns None - Add 4 tests for `get_node_type()` in surreal_store - Tests correct type for text, task, date nodes - Tests non-existent node returns None ## Test Summary - Frontend: +28 tests (3501 → 3529) - Rust: +10 tests (767 → 777) Part 2 (test infrastructure improvements) to be addressed separately. Co-Authored-By: Claude <noreply@anthropic.com> * Address review: Add helper function and document real timer usage Reviewer nitpicks addressed: - Added `uniqueNodeId()` helper function for generating unique test node IDs - Added JSDoc explaining why unique IDs are needed (global module state) - Added comment block explaining why real timers are required for race condition tests (fake timers don't properly simulate Promise.race) Co-Authored-By: Claude <noreply@anthropic.com> * Test: Add stress tests for race condition detection (closes #870 Part 2) ## Part 2A: Browser Integration Test Infrastructure - Added `rapid-keyboard-operations.test.ts` with 13 tests for: - Keyboard event sequencing (Enter→Tab, Tab→Shift+Tab patterns) - Focus management during rapid operations - High-frequency event handling (500+ events) - Event prevention and bubbling behavior ## Part 2B: Stress Tests for Rapid Indent/Outdent - Added `rapid-hierarchy-operations.test.ts` with 17 tests for: - `calculateOutdentInsertOrderPure()` edge cases - Floating point precision limits (50+ rapid insertions) - Concurrent operation simulation - Out-of-order completion patterns - PR #861 race condition scenarios ## Part 2C: test:integration:full Command - Added `test:integration:full` script that runs: - Unit tests (bun run test) - Browser tests (bun run test:browser) - Performance tests (bun run test:perf) - Rust tests (bun run rust:test) ## Documentation - Updated testing-guide.md with: - Stress test documentation and examples - Instructions for running tests - Future E2E testing considerations Test Results: - Frontend: 3546 tests passed (45 new tests added) - Browser: 90 tests passed (13 new tests added) - Rust: 777 tests passed Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Docs: Add UX bug → regression test workflow to testing guide Documents the workflow for converting discovered UX bugs into regression tests: - Workflow steps: Discover → Fix → Test → Commit - Table mapping bug types to test file locations - Concrete example with Backspace→Enter sequence - Commit message convention for bug fixes with tests Key principle: Manual testing finds bugs, automated tests prevent regressions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
…etection (#878) * Docs: Add explicit warning about gh script directory requirement Agents repeatedly make the mistake of running `bun run gh:*` commands from subdirectories like packages/desktop-app/ instead of the repo root. These commands fail with "Script not found" because the gh scripts are defined in the root package.json. Added: - Prominent warning in startup sequence step 4 with correct/wrong examples - Reminder notes on steps 7 and 8 (assign/status commands) - New entry in "Common mistakes agents make" list Co-Authored-By: Claude <noreply@anthropic.com> * Test: Add comprehensive unit tests for PR #861 helper functions (closes #870 Part 1) ## Part 1: Unit Test Coverage Gaps ### TypeScript (Frontend) - Add 13 tests for `calculateOutdentInsertOrderPure()` in reactive-node-service - Refactored to pure function for testability - Tests edge cases: empty parent, missing old parent, single/many children - Tests fractional order precision and various positions - Add 6 tests for `flushAndWaitForNodes()` in shared-node-store-coverage - Tests flushing specific nodes, concurrent flush requests - Tests timeout behavior, mix of pending/non-pending nodes - Tests error reporting for failed operations - Add 10 tests for pending-operations module - Now imports actual module exports instead of reimplementing logic - Tests trackMoveOperation, waitForPendingMoveOperations, getPendingMoveOperation - Tests race condition prevention patterns (Issue #662 scenario) ### Rust (Backend) - Add 3 tests for `node_exists()` in surreal_store - Tests existing node returns true, non-existent returns false - Tests returns false after deletion - Add 3 tests for `get_parent_id()` in surreal_store - Tests root node returns None, child returns correct parent ID - Tests non-existent node returns None - Add 4 tests for `get_node_type()` in surreal_store - Tests correct type for text, task, date nodes - Tests non-existent node returns None ## Test Summary - Frontend: +28 tests (3501 → 3529) - Rust: +10 tests (767 → 777) Part 2 (test infrastructure improvements) to be addressed separately. Co-Authored-By: Claude <noreply@anthropic.com> * Address review: Add helper function and document real timer usage Reviewer nitpicks addressed: - Added `uniqueNodeId()` helper function for generating unique test node IDs - Added JSDoc explaining why unique IDs are needed (global module state) - Added comment block explaining why real timers are required for race condition tests (fake timers don't properly simulate Promise.race) Co-Authored-By: Claude <noreply@anthropic.com> * Test: Add stress tests for race condition detection (closes #870 Part 2) ## Part 2A: Browser Integration Test Infrastructure - Added `rapid-keyboard-operations.test.ts` with 13 tests for: - Keyboard event sequencing (Enter→Tab, Tab→Shift+Tab patterns) - Focus management during rapid operations - High-frequency event handling (500+ events) - Event prevention and bubbling behavior ## Part 2B: Stress Tests for Rapid Indent/Outdent - Added `rapid-hierarchy-operations.test.ts` with 17 tests for: - `calculateOutdentInsertOrderPure()` edge cases - Floating point precision limits (50+ rapid insertions) - Concurrent operation simulation - Out-of-order completion patterns - PR #861 race condition scenarios ## Part 2C: test:integration:full Command - Added `test:integration:full` script that runs: - Unit tests (bun run test) - Browser tests (bun run test:browser) - Performance tests (bun run test:perf) - Rust tests (bun run rust:test) ## Documentation - Updated testing-guide.md with: - Stress test documentation and examples - Instructions for running tests - Future E2E testing considerations Test Results: - Frontend: 3546 tests passed (45 new tests added) - Browser: 90 tests passed (13 new tests added) - Rust: 777 tests passed Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Docs: Add UX bug → regression test workflow to testing guide Documents the workflow for converting discovered UX bugs into regression tests: - Workflow steps: Discover → Fix → Test → Commit - Table mapping bug types to test file locations - Concrete example with Backspace→Enter sequence - Commit message convention for bug fixes with tests Key principle: Manual testing finds bugs, automated tests prevent regressions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
Summary
Complete implementation of #870 - addresses both Part 1 (Unit Test Coverage) and Part 2 (Test Infrastructure Improvements).
Part 1: Unit Test Coverage Gaps
TypeScript (Frontend):
calculateOutdentInsertOrderPure()- refactored to pure function for testabilityflushAndWaitForNodes()- concurrent flush, timeout, error handlingpending-operationsmodule - imports actual exports instead of reimplementingRust (Backend):
node_exists()get_parent_id()get_node_type()Part 2: Test Infrastructure Improvements
Part 2A: Browser Integration Tests
rapid-keyboard-operations.test.ts(13 tests):Part 2B: Stress Tests for Race Conditions
rapid-hierarchy-operations.test.ts(17 tests):calculateOutdentInsertOrderPure()edge casesPart 2C: test:integration:full Command
test:integration:fullscript that runs all tests:Documentation
Test Results
Test plan
🤖 Generated with Claude Code