Skip to content

Strengthen Ollama integration test assertions to reject empty responses #1446

Closed

Description

@malibio

Overview

`test_ollama_inference_with_tools` passes even when the model returns zero output — providing false confidence that tool-calling works. A separate production-prompt test is needed to catch the exact scenario that caused the empty-response failure in production.

Problem Statement

`test_ollama_inference_with_tools` (`packages/agent/tests/ollama_integration.rs` line 186) only asserts that no `StreamingChunk::Error` chunks were emitted:

```rust
// Model may or may not call the tool — both are valid responses.
// Not all models support tool calling; some return no chunks in that case.
// Verify only that no Error chunks were emitted.
let has_error = collected.iter().any(|c| matches!(c, StreamingChunk::Error { .. }));
assert!(!has_error, "Should not receive Error chunks");
```

An empty response — zero chunks of any kind — passes this test silently. When the `num_ctx` bug (see #1443) caused Ollama to truncate the system prompt and return 1 completion token, this test still passed because no `Error` chunk was emitted.

The test also uses a minimal 2-message prompt far under 4096 tokens, so it never exercises the context-pressure scenario that actually breaks production.

Proposed Solution

Strengthen existing test

Assert the response is non-empty: at least one `ToolCallStart` chunk or at least one non-empty `Token` chunk. A tool-capable model that returns nothing in response to a direct question is broken — it is not a valid outcome.

Add production-prompt test

Add `test_ollama_inference_with_production_prompt` that:

  • Builds a system prompt using `PromptAssembler::assemble_static` (the same function the production app uses, ~7KB output)
  • Passes all 14 production tool definitions
  • Sends via `LocalAgentService::send_message()`
  • Asserts the response is non-empty

This mirrors the exact request shape that produced `prompt_tokens=4095, completion_tokens=1` in production.

Acceptance Criteria

  • `test_ollama_inference_with_tools` asserts at least one `ToolCallStart` or non-empty `Token` chunk is received
  • New test `test_ollama_inference_with_production_prompt` passes against `gemma4:e4b` with a full production system prompt and 14 tools
  • Both tests skip gracefully when Ollama is not running
  • `bun run test:all` passes with no new failures
  • Code passes `bun run quality:fix`

Technical Specifications

Files to Modify

  • `ollama_integration.rs`: `packages/agent/tests/ollama_integration.rs`
    • `test_ollama_inference_with_tools` (line 186–248): replace weak assertion with:
      ```rust
      let has_content = collected.iter().any(|c| matches!(
      c,
      StreamingChunk::ToolCallStart { .. } | StreamingChunk::Token { text } if !text.is_empty()
      ));
      assert!(has_content, "Expected a tool call or non-empty text, got: {:?}", collected);
      ```
    • Add `test_ollama_inference_with_production_prompt` using `PromptAssembler::assemble_static` and the full tool list from `StubToolExecutor::new()`

Context

This issue targets test correctness independently of the `num_ctx`/serde fixes in #1443. Even after those bugs are fixed, these tests must exist to catch future regressions of the same class.

Related Issues

Activity

  1. added 2 commits that reference this issue on Jun 22, 2026
    4eb3f09
    58fe6a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions