[TestCase(32_000, true, 500, ChatCompressionOffer.OFFERED, TestName = "Compressing makes room for an ordinary message")]
[TestCase(32_000, true, 25_000, ChatCompressionOffer.MESSAGE_TOO_LONG, TestName = "A message which fills the window itself goes along unchanged")]
[TestCase(32_000, false, 500, ChatCompressionOffer.NOTHING_TO_SUMMARIZE, TestName = "The last exchange alone holds nothing to summarize")]
[TestCase(8_192, false, 316_000, ChatCompressionOffer.MESSAGE_TOO_LONG, TestName = "A message too long for the model is named before an empty chat")]
[TestCase(ConversationSummaryBudget.MIN_CONTEXT_WINDOW - 1, true, 10, ChatCompressionOffer.WINDOW_TOO_SMALL, TestName = "A model below the minimum writes no summary")]
Assert.That(ChatCompressionService.OfferBeforeCounting(contextWindow,contextWindow,hasSomethingToSummarize,messageTokens,ChatCompressionOptions.DEFAULT),Is.EqualTo(expected),"Here, the model of the chat writes the summary itself.");
Assert.That(ChatCompressionService.OfferBeforeCounting(ContextWindow.UNKNOWN,ContextWindow.Of(32_000),true,500,ChatCompressionOptions.DEFAULT),Is.EqualTo(ChatCompressionOffer.NONE),"Without a window, AI Studio does not ask before sending at all.");
Assert.That(ChatCompressionService.OfferBeforeCounting(smallChatWindow,smallChatWindow,true,500,ChatCompressionOptions.DEFAULT),Is.EqualTo(ChatCompressionOffer.WINDOW_TOO_SMALL),"Alone, the small model cannot write a summary.");
Assert.That(ChatCompressionService.OfferBeforeCounting(smallChatWindow,ContextWindow.Of(128_000),true,500,ChatCompressionOptions.DEFAULT),Is.EqualTo(ChatCompressionOffer.OFFERED),"A model with a large window writes the summary, and the small model continues with it.");
Assert.That(ChatCompressionService.OfferBeforeCounting(ContextWindow.Of(32_000),null,true,500,ChatCompressionOptions.DEFAULT),Is.EqualTo(ChatCompressionOffer.WINDOW_TOO_SMALL),"When no model may write the summary, the notice says which window it needs.");
// The writer would keep 8,192 tokens for the summary, the chat only 2,500, and 6,900 + 2,500 stays below 9,500:
Assert.That(ChatCompressionService.OfferBeforeCounting(chatWindow,ContextWindow.Of(128_000),true,6_900,ChatCompressionOptions.DEFAULT),Is.EqualTo(ChatCompressionOffer.OFFERED),"The room for the summary follows the smaller of both windows.");
Assert.That(ChatCompressionService.KeepsTooMuch(window,tokensWithMessage,summarizedTokens,tokensForTheSummary,ChatCompressionOptions.DEFAULT.ShareToAsk),Is.EqualTo(expected),"Compressing takes off only the summarized messages and adds the room for the summary.");
Assert.That(ChatCompressionService.KeepsTooMuch(32_000,31_000,16_000,8_000,0.95),Is.False,"At 95 percent, the compressed chat stays below the share.");
Assert.That(ChatCompressionService.KeepsTooMuch(32_000,31_000,16_000,8_000,0.5),Is.True,"At 50 percent, the same chat would reach the share again right away.");
Assert.That(ChatCompressionService.OfferBeforeCounting(window,window,true,23_000,ChatCompressionOptions.DEFAULT),Is.EqualTo(ChatCompressionOffer.MESSAGE_TOO_LONG),"A message and a summary of 8,000 tokens fill the window.");
Assert.That(ChatCompressionService.OfferBeforeCounting(window,window,true,23_000,options),Is.EqualTo(ChatCompressionOffer.OFFERED),"With a summary of at most 1,024 tokens, the message fits.");