feat: retroactive image placeholder to prevent poisoning (#6774)

If an image can't be read by the API, it will poison the entire history,
preventing any new turn on the conversation.
This detect such cases and replace the image by a placeholder
This commit is contained in:
jif-oai
2025-12-03 11:35:56 +00:00
committed by GitHub
parent 42ae738f67
commit 51307eaf07
7 changed files with 171 additions and 8 deletions

View File

@@ -518,6 +518,32 @@ pub fn sse_response(body: String) -> ResponseTemplate {
.set_body_raw(body, "text/event-stream")
}
pub async fn mount_response_once(server: &MockServer, response: ResponseTemplate) -> ResponseMock {
let (mock, response_mock) = base_mock();
mock.respond_with(response)
.up_to_n_times(1)
.mount(server)
.await;
response_mock
}
pub async fn mount_response_once_match<M>(
server: &MockServer,
matcher: M,
response: ResponseTemplate,
) -> ResponseMock
where
M: wiremock::Match + Send + Sync + 'static,
{
let (mock, response_mock) = base_mock();
mock.and(matcher)
.respond_with(response)
.up_to_n_times(1)
.mount(server)
.await;
response_mock
}
fn base_mock() -> (MockBuilder, ResponseMock) {
let response_mock = ResponseMock::new();
let mock = Mock::given(method("POST"))