test(db): cover dotted-name helper, schema-inspection helpers, orphan sweep#14
Merged
Conversation
… sweep Adds 22 additive unit tests to src-tauri/src/db/mod.rs::mod tests covering helpers that the existing test block didn't exercise directly: * is_legacy_dotted_tool_name — 5 tests (all known prefixes, canonical underscore rejection, external MCP names, empty/dotless strings, dot-terminated prefix requirement) * table_exists, column_exists — 3 tests (present/absent semantics) * foreign_key_targets, drop_table_if_exists — 4 tests (referenced table listing, no-op on absent table) * sweep_orphaned_running_state — 5 tests (running → failed, COALESCE preserves existing error, non-running rows untouched, idempotence, empty table) * canonicalize_legacy_tool_names — 4 JSON-blob edge cases (non-array content skipped, parts without tool_name skipped, only first dot rewritten in replacen, mixed legacy/canonical names in same row) No production code changes; all additions live inside the existing #[cfg(test)] mod tests block. Validation: cargo fmt --check ✓ cargo clippy -- -D warnings ✓ (lib-only, CI parity) cargo test --lib ✓ 344 passing / 1 ignored (was 322/1) npm run lint ✓ 0 errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds 21 additive unit tests to
src-tauri/src/db/mod.rs::mod tests, covering helpers the existing 12-test block did not exercise directly:is_legacy_dotted_tool_name(pure)table_exists,column_existsforeign_key_targets,drop_table_if_existssweep_orphaned_running_stateCOALESCEkeeps existing error, non-running rows untouched, idempotence, empty tablecanonicalize_legacy_tool_names(JSON-blob edge cases)tool_nameskipped, only first dot rewritten viareplacen, mixed legacy/canonical names in same rowPlus two helpers local to the test module (
create_workspace_tasks_for_sweep_test,insert_sweep_task) so the sweep tests pin only the columns the production code reads/writes.Why
sweep_orphaned_running_stateis what prevents stuck `running` workspace_tasks from haunting users after a crash; if it silently no-ops, those rows linger forever.is_legacy_dotted_tool_namedecides which historic tool names get rewritten on startup; a wrong prefix list breaks OpenAI-compatible providers on saved sessions.table_exists/column_exists/foreign_key_targets/drop_table_if_existsgate every migration; a regression silently breaks "is the legacy table present?" checks.canonicalize_legacy_tool_namesblob path uses `replacen('.', "_", 1)` — the new tests pin that behavior so a refactor to `replace` would fail loudly. (Reviewer noted: the direct-column SQL path uses `REPLACE` which replaces all dots — this is a pre-existing inconsistency on dot-rich names like `bash.exec.advanced`. Out of scope for this PR; tests document the current behavior of each path.)No production code changes; all additions live inside the existing `#[cfg(test)] mod tests` block. Branch is based on `main` at `7067b08` (Release v26.5.22).
Validation
Review
Both Code Reviewer members verdict: production_quality (0 blocking findings). Two info-severity notes recorded:
🤖 Generated by CLAI QA automation.