Skip to content

Conversation

RussKie
Copy link
Contributor

@RussKie RussKie commented Mar 12, 2025

Leveraging template testing infra for a basic test of the AI template. More tests can be added later.
During a test the template is getting installed locally and then a new app is created, which is then gets snapshot-verified using Verify tooling.

| [2025-03-14T00:13:58] TestRun Information: > dotnet new install D:\Development\dotnet-extensions\src\ProjectTemplates\Microsoft.Extensions.AI.Templates\src\ChatWithCustomData --debug:custom-hive C:\Users\user\AppData\Local\Temp\hkgl3nh4.eq4\home
| [2025-03-14T00:13:58] TestRun Information: The following template packages will be installed:
|                                               D:\Development\dotnet-extensions\src\ProjectTemplates\Microsoft.Extensions.AI.Templates\src\ChatWithCustomData
|                                            Success: D:\Development\dotnet-extensions\src\ProjectTemplates\Microsoft.Extensions.AI.Templates\src\ChatWithCustomData installed the following templates:
|                                            Template Name    Short Name  Language  Tags         
|                                            ---------------  ----------  --------  -------------
|                                            AI Chat Web App  aichatweb   [C#]      Common/AI/Web
| [2025-03-14T00:13:59] TestRun Information: > dotnet new aichatweb -n aichatweb -o aichatweb --debug:custom-hive C:\Users\user\AppData\Local\Temp\hkgl3nh4.eq4\home --no-update-check
| [2025-03-14T00:13:59] TestRun Information: The template "AI Chat Web App" was created successfully.

For the local devex, it is very much worth installing Verify DiffEngineTray to approve all incoming snapshots (for the initial iteration).
It is also possible that git block staging the snapshot files due to line ending issues, and git config core.safecrlf false could be used as a jailbreak card.

Microsoft Reviewers: Open in CodeFlow

@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Mar 12, 2025
@RussKie RussKie force-pushed the test_templates branch 2 times, most recently from a71ffcc to 00ef90e Compare March 12, 2025 23:15
@RussKie RussKie marked this pull request as ready for review March 12, 2025 23:55
@RussKie RussKie requested a review from a team as a code owner March 12, 2025 23:55
@RussKie
Copy link
Contributor Author

RussKie commented Mar 12, 2025

I'm surprised it worked, but it did.

@RussKie RussKie added area-ai-templates Microsoft.Extensions.AI.Templates and removed area-ai Microsoft.Extensions.AI libraries labels Mar 13, 2025
@RussKie RussKie requested review from a team as code owners March 13, 2025 03:32
Copy link
Member

@MackinnonBuck MackinnonBuck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just a few questions.

Comment on lines +10 to +36
<ItemGroup>
<!--#if (IsOllama)
<PackageReference Include="OllamaSharp" Version="${OllamaSharpVersion}" />
#elif (IsGHModels)
<PackageReference Include="OpenAI" Version="${OpenAIVersion}" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="${MicrosoftExtensionsAIVersion}" />
#elif (IsAzureAiFoundry)
<PackageReference Include="Azure.AI.Projects" Version="${AzureAIProjectsVersion}" />
<PackageReference Include="Azure.AI.OpenAI" Version="${AzureAIOpenAIVersion}" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="${MicrosoftExtensionsAIVersion}" />
#else -->
<PackageReference Include="Azure.AI.OpenAI" Version="${AzureAIOpenAIVersion}" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="${MicrosoftExtensionsAIVersion}" />
<!--#endif -->
<!--#if (UseManagedIdentity) -->
<PackageReference Include="Azure.Identity" Version="${AzureIdentityVersion}" />
<!--#endif -->
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.AI" Version="${MicrosoftExtensionsAIVersion}" />
<PackageReference Include="Microsoft.SemanticKernel.Core" Version="${MicrosoftSemanticKernelCoreVersion}" />
<PackageReference Include="PdfPig" Version="${PdfPigVersion}" />
<PackageReference Include="System.Linq.Async" Version="${SystemLinqAsyncVersion}" />
<!--#if (UseAzureAISearch)
<PackageReference Include="Azure.Search.Documents" Version="${AzureSearchDocumentsVersion}" />
<PackageReference Include="Microsoft.SemanticKernel.Connectors.AzureAISearch" Version="${MicrosoftSemanticKernelConnectorsAzureAISearchVersion}" />
#endif -->
</ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the .in file included in the snapshot? Does this mean that the .in file gets included in the generated project?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question which I can't answer :)
I guess it does...

Copy link
Contributor Author

@RussKie RussKie Mar 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MackinnonBuck - yes, the *.in file is included in the generated content.

I followed the steps the test performs:

PS D:\Development> dotnet new install D:\Development\dotnet-extensions\src\ProjectTemplates\Microsoft.Extensions.AI.Templates\src\ChatWithCustomData --debug:custom-hive C:\Users\user\AppData\Local\Temp\hkgl3nh4.eq4\home

The following template packages will be installed:
   D:\Development\dotnet-extensions\src\ProjectTemplates\Microsoft.Extensions.AI.Templates\src\ChatWithCustomData

Success: D:\Development\dotnet-extensions\src\ProjectTemplates\Microsoft.Extensions.AI.Templates\src\ChatWithCustomData installed the following templates:
Template Name    Short Name  Language  Tags
---------------  ----------  --------  -------------
AI Chat Web App  aichatweb   [C#]      Common/AI/Web

PS D:\Development> pushd C:\Users\user\AppData\Local\Temp\TemplateEngine.Tests\test

PS C:\Users\user\AppData\Local\Temp\TemplateEngine.Tests\test> dotnet new aichatweb -n aichatweb -o aichatweb --debug:custom-hive C:\Users\user\AppData\Local\Temp\hkgl3nh4.eq4\home --no-update-check

The template "AI Chat Web App" was created successfully.

PS C:\Users\user\AppData\Local\Temp\TemplateEngine.Tests\test> ls .\aichatweb\


    Directory: C:\Users\user\AppData\Local\Temp\TemplateEngine.Tests\test\aichatweb


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        14/03/2025  11:17 AM                Components
d-----        14/03/2025  11:17 AM                Properties
d-----        14/03/2025  11:17 AM                Services
d-----        14/03/2025  11:17 AM                wwwroot
-a----        14/03/2025  11:17 AM            889 aichatweb.csproj
-a----        14/03/2025  11:17 AM           2053 aichatweb.csproj.in
-a----        14/03/2025  11:17 AM            178 appsettings.Development.json
-a----        14/03/2025  11:17 AM            202 appsettings.json
-a----        14/03/2025  11:17 AM           2678 Program.cs
-a----        14/03/2025  11:17 AM           1194 README.md

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's probably because the test is looking at files directly inside the repo and treating them as template content. This ignores any preprocessing of such content that happens as part of building the Microsoft.Extensions.AI.Templates project (for example, here).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to block the PR on it, but it might be good to figure out how to fix that for the future. Maybe the Microsfot.Extensions.AI.Templates project copies its content to an output folder at build time, and then that's what gets used by the tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, your comment didn't show up for me until I refreshed the page. If you produce a NuGet package from Microsfot.Extensions.AI.Templates, I'm guessing there's no .in file there, right? That's what I've seen from my local testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct - no *.in files in the nupkg
Screenshot 2025-03-14 114635

@RussKie RussKie enabled auto-merge (squash) March 14, 2025 00:24
@RussKie RussKie merged commit 0794cd9 into dotnet:main Mar 14, 2025
6 checks passed
@RussKie RussKie deleted the test_templates branch March 14, 2025 01:00
peterwald pushed a commit to peterwald/extensions that referenced this pull request Mar 14, 2025
Leveraging [template testing infra](https://github.com/dotnet/templating/wiki/Templates-Testing-Tooling) for a basic test of the AI template. More tests can be added later.
During a test the template is getting installed locally and then a new app is created, which is then gets snapshot-verified using Verify tooling.

For the local devex, it is very much worth installing [Verify DiffEngineTray](https://github.com/VerifyTests/DiffEngine/blob/main/docs/tray.md) to approve all incoming snapshots (for the initial iteration).
It is also possible that git block staging the snapshot files due to line ending issues, and "git config core.safecrlf false" could be used as a way to work around this.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-ai-templates Microsoft.Extensions.AI.Templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants