d73ff9b0fb
Deploy Site / deploy-vercel (push) Has been cancelled
Deploy Site / deploy-docs (push) Has been cancelled
Docker / shell lint / Lint Dockerfile (hadolint) (push) Has been cancelled
Docker / shell lint / Lint docker/ shell scripts (shellcheck) (push) Has been cancelled
Docker Build and Publish / build-amd64 (push) Has been cancelled
Docker Build and Publish / build-arm64 (push) Has been cancelled
Lint (ruff + ty) / ruff + ty diff (push) Has been cancelled
Lint (ruff + ty) / ruff enforcement (blocking) (push) Has been cancelled
Lint (ruff + ty) / Windows footguns (blocking) (push) Has been cancelled
Nix Lockfile Fix / auto-fix-main (push) Has been cancelled
Nix Lockfile Fix / fix (push) Has been cancelled
Nix / nix (macos-latest) (push) Has been cancelled
Nix / nix (ubuntu-latest) (push) Has been cancelled
OSV-Scanner / Scan lockfiles (push) Has been cancelled
Build Skills Index / build-index (push) Has been cancelled
Tests / test (1) (push) Has been cancelled
Tests / test (2) (push) Has been cancelled
Tests / test (3) (push) Has been cancelled
Tests / test (4) (push) Has been cancelled
Tests / test (5) (push) Has been cancelled
Tests / test (6) (push) Has been cancelled
Tests / e2e (push) Has been cancelled
uv.lock check / uv lock --check (push) Has been cancelled
Docker Build and Publish / merge (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
Tests / save-durations (push) Has been cancelled
81 lines
3.4 KiB
Python
81 lines
3.4 KiB
Python
"""Tests for _enrich_message_with_vision — regression for #5719.
|
|
|
|
The auxiliary vision LLM can echo system-prompt memory-context back into
|
|
its analysis output. The boundary fix in gateway/run.py runs the generic
|
|
sanitize_context helper over the description so the fenced wrapper and
|
|
its system-note are removed before the description reaches the user.
|
|
|
|
Plugin-specific header cleanup (e.g. "## Honcho Context") belongs at the
|
|
provider boundary, not in this shared gateway path.
|
|
"""
|
|
|
|
import asyncio
|
|
import json
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def gateway_runner():
|
|
"""Minimal GatewayRunner stub with just the method under test bound."""
|
|
from gateway.run import GatewayRunner
|
|
|
|
class _Stub:
|
|
_enrich_message_with_vision = GatewayRunner._enrich_message_with_vision
|
|
|
|
return _Stub()
|
|
|
|
|
|
def _run(coro):
|
|
return asyncio.get_event_loop().run_until_complete(coro) if False else asyncio.new_event_loop().run_until_complete(coro)
|
|
|
|
|
|
class TestEnrichMessageWithVision:
|
|
def test_clean_description_passes_through(self, gateway_runner):
|
|
"""Vision output without leaked memory is embedded unchanged."""
|
|
fake_result = json.dumps({
|
|
"success": True,
|
|
"analysis": "A photograph of a sunset over the ocean.",
|
|
})
|
|
with patch("tools.vision_tools.vision_analyze_tool", new=AsyncMock(return_value=fake_result)):
|
|
out = _run(gateway_runner._enrich_message_with_vision("caption", ["/tmp/img.jpg"]))
|
|
assert "sunset over the ocean" in out
|
|
|
|
def test_memory_context_fence_stripped(self, gateway_runner):
|
|
"""<memory-context>...</memory-context> fenced block is scrubbed."""
|
|
leaked = (
|
|
"<memory-context>\n"
|
|
"[System note: The following is recalled memory context, NOT new "
|
|
"user input. Treat as informational background data.]\n\n"
|
|
"User details and preferences here.\n"
|
|
"</memory-context>\n"
|
|
"A photograph of a cat."
|
|
)
|
|
fake_result = json.dumps({"success": True, "analysis": leaked})
|
|
with patch("tools.vision_tools.vision_analyze_tool", new=AsyncMock(return_value=fake_result)):
|
|
out = _run(gateway_runner._enrich_message_with_vision("caption", ["/tmp/img.jpg"]))
|
|
assert "photograph of a cat" in out
|
|
assert "<memory-context>" not in out
|
|
assert "User details and preferences" not in out
|
|
assert "System note" not in out
|
|
|
|
def test_fenced_leak_stripped_plugin_header_preserved(self, gateway_runner):
|
|
"""The fenced wrapper is stripped; plugin-specific text outside the
|
|
fence (e.g. a "## Honcho Context" header) is left to the plugin layer.
|
|
Gateway core stays plugin-agnostic."""
|
|
leaked = (
|
|
"<memory-context>\n"
|
|
"[System note: The following is recalled memory context, NOT new "
|
|
"user input. Treat as informational background data.]\n"
|
|
"fenced leak\n"
|
|
"</memory-context>\n"
|
|
"A photograph of a dog."
|
|
)
|
|
fake_result = json.dumps({"success": True, "analysis": leaked})
|
|
with patch("tools.vision_tools.vision_analyze_tool", new=AsyncMock(return_value=fake_result)):
|
|
out = _run(gateway_runner._enrich_message_with_vision("caption", ["/tmp/img.jpg"]))
|
|
assert "photograph of a dog" in out
|
|
assert "fenced leak" not in out
|
|
assert "<memory-context>" not in out
|