using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Novelly.Api.Agent; using Novelly.Api.Common; namespace Novelly.Api.Tests; [TestFixture] public class AnthropicClientTests { [Test] 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. Assert.That( () => new AnthropicAgentModelClient(Options.Create(new AgentOptions()), NullLogger.Instance), Throws.Nothing); [Test] public void 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()), NullLogger.Instance); Assert.That( async () => await client.CompleteAsync("system", [], []), Throws.TypeOf().With.Message.Contains("ANTHROPIC_API_KEY")); } finally { Environment.SetEnvironmentVariable("ANTHROPIC_API_KEY", previous); } } }