Files
llm-pii-poc/tests/PiiRedaction.Core.Tests/Integration/LlmBoundaryTests.cs

53 lines
1.9 KiB
C#
Raw Permalink Normal View History

using FluentAssertions;
using PiiRedaction.Core.Abstractions;
using PiiRedaction.Core.Models;
using PiiRedaction.Core.Tests.TestSupport;
using PiiRedaction.Infrastructure.Llm;
namespace PiiRedaction.Core.Tests.Integration;
[TestFixture]
public sealed class LlmBoundaryTests
{
[Test]
public async Task SendPromptAsync_DoesNotTransmitOriginalPii()
{
var capturingClient = new CapturingChatClient();
ILlmPromptService service = new MockLlmPromptService(capturingClient);
const string sanitized = "Customer <PERSON_1> with email <EMAIL_1>.";
await service.SendPromptAsync(sanitized);
capturingClient.LastUserMessage.Should().Be(sanitized);
capturingClient.LastUserMessage.Should().NotContain("ravi.kumar@gmail.com");
capturingClient.LastUserMessage.Should().NotContain("Ravi Kumar");
}
[Test]
public async Task SendPromptAsync_AfterSanitization_OnlyPlaceholdersReachLlm()
{
var capturingClient = new CapturingChatClient();
var sanitizer = ProductionPipelineFactory.Create().Sanitizer;
ILlmPromptService service = new MockLlmPromptService(capturingClient);
const string prompt = "Email ravi.kumar@gmail.com please.";
var result = sanitizer.Sanitize(new SanitizationRequest(prompt));
result.SanitizedPrompt.Should().Contain("<EMAIL_1>");
await service.SendPromptAsync(result.SanitizedPrompt);
capturingClient.LastUserMessage.Should().Contain("<EMAIL_1>");
capturingClient.LastUserMessage.Should().NotContain("ravi.kumar@gmail.com");
}
[TestCase(null)]
[TestCase("")]
[TestCase(" ")]
public void SendPromptAsync_InvalidSanitizedPrompt_ThrowsArgumentException(string? prompt)
{
ILlmPromptService service = new MockLlmPromptService(new MockChatClient());
var action = async () => await service.SendPromptAsync(prompt!);
action.Should().ThrowAsync<ArgumentException>();
}
}