Repository navigation
Closed
Description
Background
PR #861 (Optimize embedded SurrealDB) introduced significant race condition fixes for indent/outdent operations. These bugs were discovered through manual testing, not automated tests, exposing gaps in our test infrastructure.
Problem
- Unit test coverage gaps - New helper functions lack direct tests
- Race conditions not caught proactively - Our test infrastructure uses mocked backends, so timing issues between frontend and backend aren't detected until manual testing
Part 1: Unit Test Coverage Gaps
TypeScript (Frontend)
-
calculateOutdentInsertOrder()inreactive-node-service.svelte.ts- Test edge cases: empty parent children, missing old parent in children list, single child, many children
-
flushAndWaitForNodes()inshared-node-store.svelte.ts- Test waiting for specific nodes to flush
- Test timeout behavior
- Test concurrent flush requests
-
pending-operations.ts- Import actual module instead of reimplementing- Current tests reimplement the logic locally rather than testing the real module
- Should import from
$lib/services/pending-operationsand test actual exports
Rust (Backend)
-
node_exists()insurreal_store.rs:983- Test existing node returns true
- Test non-existent node returns false
- Test with invalid ID format
-
get_parent_id()insurreal_store.rs:1968- Test root node (no parent) returns None
- Test child node returns correct parent ID
- Test non-existent node
-
get_node_type()insurreal_store.rs:2007- Test returns correct type for each node type (text, task, date, etc.)
- Test non-existent node returns None
Part 2: Test Infrastructure Improvements
Problem Analysis
Current test limitations that allowed race conditions to slip through:
| Layer | Current State | Gap |
|---|---|---|
| Unit tests | Mock Tauri commands | Can't test real timing |
| Integration tests | In-memory store | No real DB latency |
| Browser tests | Playwright + mocks | No backend integration |
| E2E tests | None | No full stack testing |
Proposed Solutions
A. Browser Integration Tests with Real Backend
- Create test mode that runs Tauri backend in test harness
- Playwright tests that communicate with real SurrealDB
- Simulate rapid keyboard sequences (Enter→Tab→Shift+Tab)
- Detect race conditions through assertion failures, not manual testing
B. Stress/Chaos Tests for Concurrency
- Rapid indent/outdent sequence tests (100+ operations)
- Concurrent node creation while moving
- Random operation sequences to find edge cases
- Run with artificial latency injection to expose timing windows
C. Integration Test Mode with Real Database
-
bun run test:integration:full- Uses real embedded SurrealDB - Slower but catches timing issues
- Run in CI before merge to main
Success Criteria
- All unit test gaps from Part 1 are covered
- At least one E2E test exists that would have caught the Perf: Optimize embedded SurrealDB for ~1000x faster node updates #861 race conditions
- CI pipeline includes integration tests with real backend
- New race condition bugs are caught by automated tests, not manual testing
Acceptance Criteria
- Part 1: All listed unit tests added and passing
- Part 2A: Browser integration test infrastructure documented and at least 1 test running
- Part 2B: At least one stress test for rapid indent/outdent
- Part 2C:
test:integration:fullcommand works with real SurrealDB - Documentation updated with testing strategy
Labels
testing, infrastructure, tech-debt
Priority
Medium - Not blocking features, but improves development confidence
References
Metadata
Metadata
Assignees
Labels
No labels
Activity
malibio commentedon Feb 2, 2026
Test Baseline (starting implementation)
Starting implementation of test coverage improvements.
Test: Add comprehensive unit tests for PR #861 helper functions (closes
Test: Add stress tests for race condition detection (closes #870 Part 2)
malibio commentedon Feb 2, 2026
Part 2 Complete ✅
All acceptance criteria for Part 2 have been implemented:
rapid-keyboard-operations.test.ts(13 tests) covering keyboard event sequencing and focus managementrapid-hierarchy-operations.test.ts(17 tests) covering 100+ operation scenarios, floating point precision, and concurrent operationstest:integration:fullcommand added that runs unit + browser + performance + Rust testsFinal test count:
PR #878 is ready for review.
Test Coverage: Address gaps from PR #861 and improve race condition d…
Test Coverage: Address gaps from PR #861 and improve race condition d…
Test Coverage: Address gaps from PR #861 and improve race condition d…