Skip to content

fix(tests): eliminate flaky tests via hermetic StorageBackend#4

Merged
juice094 merged 7 commits into
mainfrom
fix/flaky-tests
May 6, 2026
Merged

fix(tests): eliminate flaky tests via hermetic StorageBackend#4
juice094 merged 7 commits into
mainfrom
fix/flaky-tests

Conversation

@juice094
Copy link
Copy Markdown
Owner

@juice094 juice094 commented May 6, 2026

Problem

CI Test job fails intermittently on Windows due to 6 flaky tests caused by DEVBASE_DATA_DIR environment-variable races under parallel execution (--test-threads=4).

Root Cause

DEVBASE_DATA_DIR is process-global. Parallel tests overwrite each other's value, causing:

  • PermissionDenied (two tests open the same Tantivy index dir)
  • Assertion mismatches (tests read wrong SQLite / vault data)

Fix

Production-grade injection architecture:

  • Extract TempStorageBackend as pub(crate) test helper (isolated temp dirs, zero env vars)
  • Add explicit-path APIs to search: init_index_at, list_indexed_repo_ids_at, sync_index_to_db_at, index_is_empty_at, search_repos_at
  • Add
    epair_tantivy_consistency_at to storage
  • Add
    l_filter_repos_at to repo tool
  • Refactor vault tools to pre-compute �ault_dir from ctx.storage before spawn_blocking
  • Migrate all 6 flaky tests to TempStorageBackend + AppContext::with_storage()

Verification

`
cargo test --workspace -- --test-threads=4

result: ok. 390 passed; 0 failed; 3 ignored

`

Scope

  • src/search.rs
  • src/storage.rs
  • src/mcp/tests.rs
  • src/mcp/tools/repo.rs
  • src/mcp/tools/vault.rs
  • src/mcp/tools/workflow.rs

juice094 added 2 commits May 6, 2026 14:00
Fixes Dependabot alerts #9, #10:
- rust-openssl undefined behavior in X509Ref::ocsp_responders
- High severity, certificates with non-UTF-8 OCSP URLs
Root cause: DEVBASE_DATA_DIR environment variable is process-global;
parallel tests overwrite each other's value causing PermissionDenied
and assertion failures.

Production-grade fix:
- Extract TempStorageBackend as pub(crate) test helper (isolated temp dirs)
- Add explicit-path APIs to search module: init_index_at, list_indexed_repo_ids_at,
  sync_index_to_db_at, index_is_empty_at, search_repos_at
- Add repair_tantivy_consistency_at to storage module
- Add nl_filter_repos_at to repo tool
- Refactor vault tools to pre-compute vault_dir from ctx.storage before spawn_blocking
- Migrate all 6 flaky tests to TempStorageBackend + AppContext::with_storage()
  without any environment variable mutations

Flaky tests fixed:
- test_nl_filter_repos_tantivy_finds_devbase
- test_vault_graph_basic
- test_vault_graph_filtered_by_repo
- test_workflow_run_not_found
- test_sync_index_to_db_removes_orphans
- test_repair_tantivy_consistency_detects_orphan

Parallel test execution (--test-threads=4) now stable: 390 passed, 0 failed.
@juice094 juice094 force-pushed the fix/flaky-tests branch 5 times, most recently from cc7d375 to 1f2853e Compare May 6, 2026 08:45
- scan.rs: canonicalize root and ignored_dirs to fix path comparison
  on Windows where TempDir returns short (8.3) filenames while
  dunce::canonicalize expands them, causing starts_with to fail.

- sync/tests.rs: replace repo.signature() with explicit
  git2::Signature::now() to avoid failure on CI runners without
  global git config (user.name / user.email).

- mcp/tests.rs: migrate test_ctx() from DEVBASE_DATA_DIR env var
  to TempStorageBackend injection, eliminating global state pollution
  that caused flaky test_tools_call_devkit_query under --test-threads=4.
@juice094 juice094 force-pushed the fix/flaky-tests branch from 1f2853e to 9c6fadf Compare May 6, 2026 09:05
juice094 added 4 commits May 6, 2026 17:26
Replace all 7 occurrences of std::env::set_var with TempStorageBackend injection or direct tmp path usage across vault.rs, workflow.rs, executor.rs, state.rs. Enforces RF-2.1.
- Replace LICENSE with AGPL-3.0 full text

- Add LICENSE-COMMERCIAL.md for commercial licensing inquiries

- Update Cargo.toml: license = AGPL-3.0-or-later

- Update README.md badge + dual license notice in Chinese

- Update AGENTS.md with licensing policy section
cargo test --all-targets passes --test-threads to bench binaries,
which criterion does not accept. Use --lib --tests --bins --examples
instead.
test_run_skill_success intermittently times out on Windows CI runners
under load. 5s is too tight for process spawn + Python interpreter
startup on shared runners.
@juice094 juice094 merged commit 31772fd into main May 6, 2026
5 checks passed
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