Skip to content

test(agent): strengthen Ollama integration assertions and add production-prompt test - #1449

Merged
malibio merged 1 commit into
mainfrom
worktree-issue-1446-strengthen-ollama-test-assertions
Jun 22, 2026
Merged

malibio merged 1 commit into
mainfrom
worktree-issue-1446-strengthen-ollama-test-assertions

Conversation

@malibio

@malibio malibio commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Strengthens test_ollama_inference_with_tools to assert at least one ToolCallStart or non-empty Token chunk is received (closes Strengthen Ollama integration test assertions to reject empty responses #1446)
  • Adds test_ollama_inference_with_production_prompt that exercises the full production system prompt via PromptAssembler::assemble_static with all 14 tools against gemma4:e4b
  • Promotes all_tool_definitions() visibility from pub(crate) to pub to allow integration test access

Test plan

  • Both tests skip gracefully when Ollama is not running
  • test_ollama_inference_with_tools fails if no meaningful chunk (ToolCallStart or non-empty Token) is received
  • test_ollama_inference_with_production_prompt asserts non-empty streaming response with all 14 production tools
  • bun run test:all passes with no new failures
  • Code passes bun run quality:fix

Closes #1446

🤖 Generated with Claude Code

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Review Type: Initial Review

This is a focused test-strengthening PR with a clear purpose: make Ollama integration tests reject the empty-response failure mode that slipped through the previous !has_error assertion. The changes are small, well-targeted, and directly address the regression scenario documented in issue #1443. This is a net improvement to the codebase.


Requirements Check

  • test_ollama_inference_with_tools asserts at least one ToolCallStart or non-empty Token chunk — implemented correctly
  • New test test_ollama_inference_with_production_prompt passes against gemma4:e4b with full production system prompt and 14 tools — test added and tool count assertion confirms 14
  • Both tests skip gracefully when Ollama is not running — ollama_running() guard present in both, with eprintln! skip messages
  • bun run test:all — no new compile-time issues; integration tests are gated behind Ollama availability
  • Code passes bun run quality:fix — no lint issues visible in the diff

Code Review Findings

[Improvement] packages/agent/tests/ollama_integration.rs line 283 — Tool count assertion is brittle

assert_eq!(tools.len(), 14, "Expected exactly 14 production tools");

Hardcoding 14 creates a maintenance trap: when a tool is added or removed, this assertion fails without a helpful explanation of why 14 is the expected number. Since Tool::ALL is the authoritative source and all_tool_definitions() is derived directly from it, the assertion should use Tool::ALL.len() rather than a magic number. Alternatively, since this is a test, a comment explaining "14 = len(Tool::ALL) at time of writing" would at minimum help the next author.

The deeper concern is whether this test is intended to freeze the tool count (i.e., catch accidental deletions) or merely confirm the function returns something. If the goal is the former, the assertion message should say "unexpected tool count — did you add or remove a tool without updating this test?" rather than just reporting the actual count. If the goal is the latter, assert!(!tools.is_empty()) is sufficient and more resilient.

[Improvement] packages/agent/tests/ollama_integration.rs lines 254-332 — New test deviates from the issue spec regarding LocalAgentService

The issue spec says the new test should send via LocalAgentService::send_message(), which mirrors the full production stack (prompt assembly + tool execution + session management). The implementation instead calls engine.generate() directly. This is a valid simplification — and the comment at line 272 explains the intent (mirroring the exact request shape from the num_ctx bug) — but it means the test does not exercise the code path the live app actually uses (i.e., the agent loop, system prompt injection via LocalAgentService, and tool dispatch). This is a deliberate trade-off worth acknowledging, but reviewers should be aware the test exercises OllamaInferenceEngine in isolation rather than end-to-end agent behavior.

[Nit] packages/agent/src/local_agent/tools.rs line 868 — Visibility widening without documentation

all_tool_definitions() was pub(crate) and is now pub. The function itself is fine, but the widening should carry a brief doc comment explaining the intended consumers. As it stands, any downstream crate can now call this — it becomes part of the public surface of nodespace-agent. A one-line /// Returns all tool definitions for the graph executor. Exposed for integration tests. (or similar) sets expectations for future callers.

[Nit] packages/agent/tests/ollama_integration.rs lines 239-251 — has_content predicate is duplicated

The has_content match block is identical in both test_ollama_inference_with_tools (lines 242-246) and test_ollama_inference_with_production_prompt (lines 319-323). Extracting it to a helper function (e.g., fn has_meaningful_content(chunks: &[StreamingChunk]) -> bool) would eliminate the duplication and make it a named concept. Per DRY, if the definition of "meaningful content" ever changes, it should change in one place.


Summary

All acceptance criteria are met. The one substantive concern — the 14 magic number — is an [Improvement] not a blocker, since the test is still correct today. The deviation from LocalAgentService in the new test is a deliberate design choice that is acceptable given the stated goal (reproducing the exact raw inference shape from the bug), but worth calling out for future authors.

Recommendation: APPROVE with the improvements noted above considered for a follow-up.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation: APPROVE — All acceptance criteria met. Improvements noted in the review comment are non-blocking suggestions for follow-up.

…ion-prompt test (closes #1446)

- `test_ollama_inference_with_tools`: replace weak no-Error assertion with a
  has_content check requiring at least one ToolCallStart or non-empty Token chunk;
  an empty response is no longer a passing outcome
- Add `test_ollama_inference_with_production_prompt`: sends the full ~7KB
  production system prompt via PromptAssembler::assemble_static plus all 14
  production tool definitions, asserting a non-empty response; mirrors the exact
  request shape that produced prompt_tokens=4095, completion_tokens=1 in the
  num_ctx bug (#1443)
- Expose `all_tool_definitions()` as `pub` (was `pub(crate)`) so integration
  tests can import the canonical 14-tool production set

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@malibio
malibio force-pushed the worktree-issue-1446-strengthen-ollama-test-assertions branch from 42dd9cd to 4eb3f09 Compare June 22, 2026 15:23
@malibio
malibio merged commit 58fe6a4 into main Jun 22, 2026
@malibio
malibio deleted the worktree-issue-1446-strengthen-ollama-test-assertions branch June 22, 2026 16:11
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.

Strengthen Ollama integration test assertions to reject empty responses

1 participant