using FluentAssertions; using Microsoft.Extensions.Options; using NovelSoftware.Application; using NovelSoftware.Application.Agent; using NovelSoftware.Infrastructure.Anthropic; namespace NovelSoftware.Tests; public class AnthropicClientTests { [Fact] public void Constructing_without_a_key_does_not_throw() { // The agent service takes this as a dependency and also serves read-only endpoints // (listing conversations, reading a transcript). Throwing at construction would // take those down on any install that has not configured a key yet. var construct = () => new AnthropicAgentModelClient(Options.Create(new AgentOptions())); construct.Should().NotThrow(); } [Fact] public async Task Sending_without_a_key_reports_a_configuration_problem() { var previous = Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY"); Environment.SetEnvironmentVariable("ANTHROPIC_API_KEY", null); try { var client = new AnthropicAgentModelClient(Options.Create(new AgentOptions())); var send = async () => await client.CompleteAsync("system", [], []); (await send.Should().ThrowAsync()) .WithMessage("*ANTHROPIC_API_KEY*"); } finally { Environment.SetEnvironmentVariable("ANTHROPIC_API_KEY", previous); } } }