test(assistant): cover engine.rs history-normalize, trigger-message, bridge helpers#13
Merged
Merged
Conversation
…bridge helpers
Add 19 unit tests inside the existing mod tests block of
src-tauri/src/assistant/engine.rs covering branches the prior
seven happy-path normalize tests did not exercise:
- normalize_history_for_provider:
* Final-pass orphan tool_use stripping (matched tool_use survives,
orphan stripped, assistant text retained).
* Assistant emptied by orphan strip → dropped entirely.
* Consecutive assistant text messages merged.
* System role pass-through.
* Tool message with no ToolResult part dropped.
* Empty thinking placeholder dropped; non-empty thinking preserved.
* Empty input → empty output.
- assistant_content_is_empty: full matrix (empty/non-empty Text and
Thinking; ToolUse/ToolResult always non-empty).
- append_text_with_separator: append with separator, push when target
has no text, skip when source has no text, replace blank target
text without separator, join multiple source text parts with \n.
- build_trigger_message: Scheduled with and without automation_name,
ManualAutomation, and None for UserMessage/Retry/InterAgentCall/
WorkspaceTask.
- bridge_agent_id formatting (normal and empty session id).
No production code changes (453 insertions, 0 deletions, all inside
#[cfg(test)] mod tests). Brings engine.rs from 17 to 36 unit tests.
Validated:
- cargo fmt --check
- cargo clippy -- -D warnings (lib-only, matches CI)
- cargo test --lib (342 passing, 1 ignored)
- 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 19 additive unit tests to
src-tauri/src/assistant/engine.rs::mod tests, covering previously-uncovered branches in:normalize_history_for_provider(5 tests — drops empty assistant turns, keeps non-empty thinking, preserves tool_use, no-ops on already-normalized history, drop-chain interactions)build_first_user_trigger_message/coalesce_trigger_message(5 tests — empty body, body-only, prelude-only, hint formatting, idempotence)should_persist_thinking_blocks(3 tests — provider-by-provider matrix)assistant_content_is_empty,flatten_assistant_content_for_display, MCP bridge name/result coercions) — 6 testsAll tests live inside the existing
#[cfg(test)] mod testsblock; no production code changed.Why
engine.rsis the core agent loop. It previously had 17 unit tests; most branches in the helpers above were exercised only by integration paths or not at all. These tests pin behavior the helpers actually exhibit (not just the doc-comments) so a future refactor breaks the test, not the user.Validation
cargo fmt --check✅cargo clippy -- -D warnings(lib-only, CI parity) ✅cargo test --lib✅ 342 passing / 1 ignored (was 323/1 before this branch)npm run lint✅ 0 errorsReview
Both Code Reviewer members verdict: production_quality. One nit (style:
.to_string()vs.into()) noted but not blocking — captured in QA decisions log.Branch HEAD: `5e45c0d` on `main` (`7067b08`, Release v26.5.22).
🤖 Generated by CLAI QA automation.