Skip to content

Test Coverage: Address gaps from PR #861 and improve race condition detection #870

Closed

Description

@malibio

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

  1. Unit test coverage gaps - New helper functions lack direct tests
  2. 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() in reactive-node-service.svelte.ts

    • Test edge cases: empty parent children, missing old parent in children list, single child, many children
  • flushAndWaitForNodes() in shared-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-operations and test actual exports

Rust (Backend)

  • node_exists() in surreal_store.rs:983

    • Test existing node returns true
    • Test non-existent node returns false
    • Test with invalid ID format
  • get_parent_id() in surreal_store.rs:1968

    • Test root node (no parent) returns None
    • Test child node returns correct parent ID
    • Test non-existent node
  • get_node_type() in surreal_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

  1. All unit test gaps from Part 1 are covered
  2. At least one E2E test exists that would have caught the Perf: Optimize embedded SurrealDB for ~1000x faster node updates #861 race conditions
  3. CI pipeline includes integration tests with real backend
  4. 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:full command works with real SurrealDB
  • Documentation updated with testing strategy

Labels

testing, infrastructure, tech-debt

Priority

Medium - Not blocking features, but improves development confidence

References

Activity

  1. malibio commented on Feb 2, 2026

    @malibio
    CollaboratorAuthor

    Test Baseline (starting implementation)

    • Frontend: 104 test files, 3501 tests passed
    • Rust: 767 tests passed

    Starting implementation of test coverage improvements.

  2. self-assigned this
    on Feb 2, 2026
  3. added 2 commits that reference this issue on Feb 2, 2026
    2db9792
    34aaf98
  4. malibio commented on Feb 2, 2026

    @malibio
    CollaboratorAuthor

    Part 2 Complete ✅

    All acceptance criteria for Part 2 have been implemented:

    • Part 2A: Browser integration test infrastructure documented in testing-guide.md, with rapid-keyboard-operations.test.ts (13 tests) covering keyboard event sequencing and focus management
    • Part 2B: Stress test for rapid indent/outdent in rapid-hierarchy-operations.test.ts (17 tests) covering 100+ operation scenarios, floating point precision, and concurrent operations
    • Part 2C: test:integration:full command added that runs unit + browser + performance + Rust tests
    • Documentation: Updated testing-guide.md with stress test section

    Final test count:

    • Frontend: 3546 tests (baseline was 3501)
    • Browser: 90 tests (+13 new)
    • Rust: 777 tests (unchanged)

    PR #878 is ready for review.

  5. added 2 commits that reference this issue on Feb 4, 2026
    657ada9
    34ac9e5
  6. added a commit that references this issue on Feb 26, 2026
    df05b1b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions