Skip to content

test(db): cover dotted-name helper, schema-inspection helpers, orphan sweep#14

Merged
juacker merged 1 commit into
mainfrom
qa/db-mod-helper-tests
May 22, 2026
Merged

test(db): cover dotted-name helper, schema-inspection helpers, orphan sweep#14
juacker merged 1 commit into
mainfrom
qa/db-mod-helper-tests

Conversation

@juacker
Copy link
Copy Markdown
Owner

@juacker juacker commented May 22, 2026

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:

Helper New tests
is_legacy_dotted_tool_name (pure) 5 — all prefixes, underscore form rejection, external MCP rejection, empty/dotless, prefix boundary
table_exists, column_exists 3 — present/absent semantics on in-memory SQLite
foreign_key_targets, drop_table_if_exists 4 — referenced-table listing, empty-vec for absent table, no-op on absent table
sweep_orphaned_running_state 5 — running → failed, COALESCE keeps existing error, non-running rows untouched, idempotence, empty table
canonicalize_legacy_tool_names (JSON-blob edge cases) 4 — non-array content skipped, parts without tool_name skipped, only first dot rewritten via replacen, mixed legacy/canonical names in same row

Plus 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_state is 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_name decides 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_exists gate every migration; a regression silently breaks "is the legacy table present?" checks.
  • canonicalize_legacy_tool_names blob 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

  • `cargo fmt --check` ✅
  • `cargo clippy -- -D warnings` (lib-only, CI parity) ✅
  • `cargo test --lib` → 344 passing / 1 ignored (was 323/1 before this branch — 22 unit tests gained including helper-driven new variants of `column_exists` checked in one body)
  • `npm run lint` → 0 errors (46 unchanged warnings)

Review

Both Code Reviewer members verdict: production_quality (0 blocking findings). Two info-severity notes recorded:

  1. Test count framing (the diff adds 21 `#[test]` cases; one "test" in my draft notes was actually a fixture helper). Corrected here.
  2. Pre-existing production inconsistency between SQL `REPLACE` (direct column) and Rust `replacen('.', _, 1)` (JSON blob) — out of scope; documented in test names.

🤖 Generated by CLAI QA automation.

… 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
@juacker juacker marked this pull request as ready for review May 22, 2026 13:17
@juacker juacker marked this pull request as draft May 22, 2026 13:30
@juacker juacker marked this pull request as ready for review May 22, 2026 13:33
@juacker juacker merged commit fd5f2cf into main May 22, 2026
1 check 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