fix(ai): request structured JSON for queued strategies

This commit is contained in:
cesnimda
2026-10-29 13:03:57 +01:00
parent 994bf8f8bb
commit caa0c6a2ef
8 changed files with 69 additions and 6 deletions
@@ -71,6 +71,22 @@ public sealed class CvAiEvaluationTests
Assert.Null(await service.GenerateSectionWithMetadataAsync("Improve", "Source", AiGenerationOutputMode.CvBlocksJson));
}
[Fact]
public async Task Structured_generation_has_an_explicit_mode_and_cannot_reuse_text_cache()
{
var handler = new CaptureHandler();
var factory = new Mock<IHttpClientFactory>();
factory.Setup(value => value.CreateClient("ai-service")).Returns(new HttpClient(handler) { BaseAddress = new Uri("http://localhost") });
using var cache = new MemoryCache(new MemoryCacheOptions());
var service = new SummarizerService(factory.Object, cache);
await service.GenerateSectionWithMetadataAsync("Return JSON.", "Fictional source.");
Assert.NotNull(await service.GenerateSectionWithMetadataAsync("Return JSON.", "Fictional source.", AiGenerationOutputMode.StructuredJson));
Assert.Equal(2, handler.RequestCount);
using var body = JsonDocument.Parse(handler.Body!);
Assert.Equal("structured_json", body.RootElement.GetProperty("output_mode").GetString());
Assert.Null(await ((ISummarizerService)new OlderSummarizer()).GenerateSectionWithMetadataAsync("Return JSON.", "Source", AiGenerationOutputMode.StructuredJson));
}
private sealed class CaptureHandler : HttpMessageHandler
{
public string? Path { get; private set; }