From 7e34c3df04f07ac82b855f42b03d9c5133a98cd9 Mon Sep 17 00:00:00 2001 From: Mackinnon Buck Date: Mon, 17 Mar 2025 13:52:20 -0700 Subject: [PATCH 1/4] More robust version scrubbing --- .../AichatwebTemplatesTests.cs | 17 ++++++++++++++++- .../aichatweb/aichatweb.csproj | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs index 7953003cf63..a86fa44049b 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.AI.Templates.IntegrationTests; using Microsoft.Extensions.AI.Templates.Tests; @@ -31,6 +32,10 @@ public class AichatwebTemplatesTests : TestBase "**/Directory.Build.targets", ]; + private static readonly string[] _packagePrefixesWithJustBuiltVersionNumber = [ + "Microsoft.Extensions.AI", + ]; + private readonly ILogger _log; public AichatwebTemplatesTests(ITestOutputHelper log) @@ -71,7 +76,17 @@ public async Task BasicTest() filePath.EndsWith("aichatweb/aichatweb.csproj.in")) { content.ScrubByRegex("(.*)<\\/UserSecretsId>", "secret"); - content.ScrubByRegex("\"(\\d*\\.\\d*\\.\\d*)-(dev|ci)\"", "\"$1\""); + + foreach (var prefix in _packagePrefixesWithJustBuiltVersionNumber) + { + // Scrub references to just-built packages and use a fake version name. + // This allows the snapshots to remain the same regardless of where the repo is built (e.g., locally, public CI, internal CI). + const string VersionReplacement = "REPO_VERSION"; + var escapedPrefix = Regex.Escape(prefix); + var pattern = $""; + var replacement = $""; + content.ScrubByRegex(pattern, replacement); + } } if (filePath.EndsWith("aichatweb/Properties/launchSettings.json")) diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Basic.verified/aichatweb/aichatweb.csproj b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Basic.verified/aichatweb/aichatweb.csproj index a73d885e592..ba225feba02 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Basic.verified/aichatweb/aichatweb.csproj +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Basic.verified/aichatweb/aichatweb.csproj @@ -9,9 +9,9 @@ - + - + From 7077b33680b366949a48efb6d721b1d3b91a7031 Mon Sep 17 00:00:00 2001 From: Mackinnon Buck Date: Mon, 17 Mar 2025 15:04:49 -0700 Subject: [PATCH 2/4] Preserve version without suffix --- .../AichatwebTemplatesTests.cs | 7 +++---- .../aichatweb.Basic.verified/aichatweb/aichatweb.csproj | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs index a86fa44049b..ea13219fea0 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs @@ -79,12 +79,11 @@ public async Task BasicTest() foreach (var prefix in _packagePrefixesWithJustBuiltVersionNumber) { - // Scrub references to just-built packages and use a fake version name. + // Scrub references to just-built packages and remove the suffix, if it exists. // This allows the snapshots to remain the same regardless of where the repo is built (e.g., locally, public CI, internal CI). - const string VersionReplacement = "REPO_VERSION"; var escapedPrefix = Regex.Escape(prefix); - var pattern = $""; - var replacement = $""; + var pattern = $""; + var replacement = ""; content.ScrubByRegex(pattern, replacement); } } diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Basic.verified/aichatweb/aichatweb.csproj b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Basic.verified/aichatweb/aichatweb.csproj index ba225feba02..a73d885e592 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Basic.verified/aichatweb/aichatweb.csproj +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Basic.verified/aichatweb/aichatweb.csproj @@ -9,9 +9,9 @@ - + - + From bde41db9d8447b4d2493c513f08a2270500e989a Mon Sep 17 00:00:00 2001 From: Mackinnon Buck Date: Mon, 17 Mar 2025 15:35:56 -0700 Subject: [PATCH 3/4] Fix pt. 1: Hard-code pattern --- .../AichatwebTemplatesTests.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs index ea13219fea0..42bc3618ade 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs @@ -3,7 +3,6 @@ using System.IO; using System.Linq; -using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.AI.Templates.IntegrationTests; using Microsoft.Extensions.AI.Templates.Tests; @@ -32,10 +31,6 @@ public class AichatwebTemplatesTests : TestBase "**/Directory.Build.targets", ]; - private static readonly string[] _packagePrefixesWithJustBuiltVersionNumber = [ - "Microsoft.Extensions.AI", - ]; - private readonly ILogger _log; public AichatwebTemplatesTests(ITestOutputHelper log) @@ -77,15 +72,11 @@ public async Task BasicTest() { content.ScrubByRegex("(.*)<\\/UserSecretsId>", "secret"); - foreach (var prefix in _packagePrefixesWithJustBuiltVersionNumber) - { - // Scrub references to just-built packages and remove the suffix, if it exists. - // This allows the snapshots to remain the same regardless of where the repo is built (e.g., locally, public CI, internal CI). - var escapedPrefix = Regex.Escape(prefix); - var pattern = $""; - var replacement = ""; - content.ScrubByRegex(pattern, replacement); - } + // Scrub references to just-built packages and remove the suffix, if it exists. + // This allows the snapshots to remain the same regardless of where the repo is built (e.g., locally, public CI, internal CI). + var pattern = ""; + var replacement = ""; + content.ScrubByRegex(pattern, replacement); } if (filePath.EndsWith("aichatweb/Properties/launchSettings.json")) From 7cb07250a5ac4e946d6c2a8f0c8e7c7963d062cd Mon Sep 17 00:00:00 2001 From: Mackinnon Buck Date: Mon, 17 Mar 2025 15:37:58 -0700 Subject: [PATCH 4/4] Fix pt. 2: New regex --- .../AichatwebTemplatesTests.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs index 42bc3618ade..cd155f38da7 100644 --- a/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs +++ b/test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/AichatwebTemplatesTests.cs @@ -74,9 +74,8 @@ public async Task BasicTest() // Scrub references to just-built packages and remove the suffix, if it exists. // This allows the snapshots to remain the same regardless of where the repo is built (e.g., locally, public CI, internal CI). - var pattern = ""; - var replacement = ""; - content.ScrubByRegex(pattern, replacement); + var pattern = @"(?<=)"; + content.ScrubByRegex(pattern, replacement: "$1"); } if (filePath.EndsWith("aichatweb/Properties/launchSettings.json"))