From b557696d7d95b2bf7558e747c924e88010f30fc8 Mon Sep 17 00:00:00 2001 From: Waldek Mastykarz Date: Wed, 21 Oct 2026 15:54:45 +0200 Subject: [PATCH] Fix TypeSpecGeneratorPlugin log messages to mention TypeSpec TypeSpecGeneratorPlugin logged "Writing OpenAPI spec" / "Created OpenAPI spec file" when writing .tsp files. Log messages now refer to TypeSpec files, and the integration test asserts the messages. Closes #1975 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4afa2bd8-e47d-4362-b7fd-412d95af4216 --- .../GenerationPluginsIntegrationTests.cs | 24 ++++++++++++++++++- .../Generation/TypeSpecGeneratorPlugin.cs | 4 ++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/DevProxy.Integration.Tests/GenerationPluginsIntegrationTests.cs b/DevProxy.Integration.Tests/GenerationPluginsIntegrationTests.cs index f9b0bfe05..39a32a450 100644 --- a/DevProxy.Integration.Tests/GenerationPluginsIntegrationTests.cs +++ b/DevProxy.Integration.Tests/GenerationPluginsIntegrationTests.cs @@ -11,6 +11,7 @@ using DevProxy.Abstractions.Proxy.Http; using DevProxy.Abstractions.Utils; using DevProxy.Plugins.Generation; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Xunit; @@ -217,9 +218,10 @@ public async Task OpenApiSpecGenerator_WritesSpec() [Fact] public async Task TypeSpecGenerator_WritesSpec() { + var logger = new MessageCapturingLogger(); var plugin = new TypeSpecGeneratorPlugin( TestDefaults.HttpClient, - NullLogger.Instance, + logger, Watch, new DisabledLanguageModelClient(), new TestProxyConfiguration(), @@ -233,10 +235,30 @@ public async Task TypeSpecGenerator_WritesSpec() ((Dictionary)args.GlobalData[ProxyUtils.ReportsKey])[plugin.Name]); Assert.NotEmpty(report); Assert.NotEmpty(dir.GetFiles("*.tsp")); + Assert.Contains(logger.Messages, m => m.StartsWith("Writing TypeSpec file to ", StringComparison.Ordinal)); + Assert.Contains(logger.Messages, m => m.StartsWith("Created TypeSpec file ", StringComparison.Ordinal)); + Assert.DoesNotContain(logger.Messages, m => m.Contains("OpenAPI", StringComparison.Ordinal)); } finally { dir.Delete(recursive: true); } } + + private sealed class MessageCapturingLogger : ILogger + { + public List Messages { get; } = []; + + public IDisposable? BeginScope(TState state) where TState : notnull => null; + + public bool IsEnabled(LogLevel logLevel) => true; + + public void Log( + LogLevel logLevel, + EventId eventId, + TState state, + Exception? exception, + Func formatter) => + Messages.Add(formatter(state, exception)); + } } diff --git a/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs b/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs index a89cb747e..5731ac562 100644 --- a/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs +++ b/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs @@ -115,12 +115,12 @@ request.Method is null || cancellationToken.ThrowIfCancellationRequested(); var fileName = $"{typeSpecFile.Name}-{DateTime.Now:yyyyMMddHHmmss}.tsp"; - Logger.LogDebug("Writing OpenAPI spec to {FileName}...", fileName); + Logger.LogDebug("Writing TypeSpec file to {FileName}...", fileName); await File.WriteAllTextAsync(fileName, typeSpecFile.ToString(), cancellationToken); generatedTypeSpecFiles.Add(typeSpecFile.Service.Servers.First().Url, fileName); - Logger.LogInformation("Created OpenAPI spec file {FileName}", fileName); + Logger.LogInformation("Created TypeSpec file {FileName}", fileName); } StoreReport(new TypeSpecGeneratorPluginReport(