forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'microsoft:main' into update-modelid
- Loading branch information
Showing
149 changed files
with
5,194 additions
and
1,618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
param ( | ||
[string]$JsonReportPath, | ||
[double]$CoverageThreshold | ||
) | ||
|
||
$jsonContent = Get-Content $JsonReportPath -Raw | ConvertFrom-Json | ||
$coverageBelowThreshold = $false | ||
|
||
function Get-FormattedValue($number) { | ||
$formattedNumber = "{0:N1}" -f $number | ||
$icon = if ($number -ge $CoverageThreshold) { '✅' } else { '❌' } | ||
|
||
return "$formattedNumber% $icon" | ||
} | ||
|
||
$lineCoverage = $jsonContent.summary.linecoverage | ||
$branchCoverage = $jsonContent.summary.branchcoverage | ||
|
||
if ($lineCoverage -lt $CoverageThreshold -or $branchCoverage -lt $CoverageThreshold) { | ||
$coverageBelowThreshold = $true | ||
} | ||
|
||
$totalTableData = [PSCustomObject]@{ | ||
'Metric' = 'Total Coverage' | ||
'Line Coverage' = Get-FormattedValue $lineCoverage | ||
'Branch Coverage' = Get-FormattedValue $branchCoverage | ||
} | ||
|
||
$totalTableData | Format-Table -AutoSize | ||
|
||
$assemblyTableData = @() | ||
|
||
foreach ($assembly in $jsonContent.coverage.assemblies) { | ||
$assemblyName = $assembly.name | ||
$assemblyLineCoverage = $assembly.coverage | ||
$assemblyBranchCoverage = $assembly.branchcoverage | ||
|
||
if ($assemblyLineCoverage -lt $CoverageThreshold -or $assemblyBranchCoverage -lt $CoverageThreshold) { | ||
$coverageBelowThreshold = $true | ||
} | ||
|
||
$assemblyTableData += [PSCustomObject]@{ | ||
'Assembly Name' = $assemblyName | ||
'Line' = Get-FormattedValue $assemblyLineCoverage | ||
'Branch' = Get-FormattedValue $assemblyBranchCoverage | ||
} | ||
} | ||
|
||
$assemblyTableData | Format-Table -AutoSize | ||
|
||
if ($coverageBelowThreshold) { | ||
Write-Host "Code coverage is lower than defined threshold: $CoverageThreshold. Stopping the task." | ||
exit 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# This script is for local use to analyze code coverage in more detail using HTML report. | ||
|
||
Param( | ||
[switch]$ProdPackagesOnly = $false | ||
) | ||
|
||
# Generate a timestamp for the current date and time | ||
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss" | ||
|
||
# Define paths | ||
$scriptPath = Get-Item -Path $PSScriptRoot | ||
$coverageOutputPath = Join-Path $scriptPath "TestResults\Coverage\$timestamp" | ||
$reportOutputPath = Join-Path $scriptPath "TestResults\Reports\$timestamp" | ||
|
||
# Create output directories | ||
New-Item -ItemType Directory -Force -Path $coverageOutputPath | ||
New-Item -ItemType Directory -Force -Path $reportOutputPath | ||
|
||
# Find tests for projects ending with 'UnitTests.csproj' | ||
$testProjects = Get-ChildItem $scriptPath -Filter "*UnitTests.csproj" -Recurse | ||
|
||
foreach ($project in $testProjects) { | ||
$testProjectPath = $project.FullName | ||
Write-Host "Running tests for project: $($testProjectPath)" | ||
|
||
# Run tests | ||
dotnet test $testProjectPath ` | ||
--collect:"XPlat Code Coverage" ` | ||
--results-directory:$coverageOutputPath ` | ||
|
||
} | ||
|
||
# Install required tools | ||
& dotnet tool install -g coverlet.console | ||
& dotnet tool install -g dotnet-reportgenerator-globaltool | ||
|
||
# Generate HTML report | ||
if ($ProdPackagesOnly) { | ||
$assemblies = @( | ||
"+Microsoft.SemanticKernel.Abstractions", | ||
"+Microsoft.SemanticKernel.Core", | ||
"+Microsoft.SemanticKernel.PromptTemplates.Handlebars", | ||
"+Microsoft.SemanticKernel.Connectors.OpenAI", | ||
"+Microsoft.SemanticKernel.Yaml" | ||
) | ||
|
||
$assemblyFilters = $assemblies -join ";" | ||
|
||
# Generate report for production assemblies only | ||
& reportgenerator -reports:"$coverageOutputPath/**/coverage.cobertura.xml" -targetdir:$reportOutputPath -reporttypes:Html -assemblyfilters:$assemblyFilters | ||
} | ||
else { | ||
& reportgenerator -reports:"$coverageOutputPath/**/coverage.cobertura.xml" -targetdir:$reportOutputPath -reporttypes:Html | ||
} | ||
|
||
Write-Host "Code coverage report generated at: $reportOutputPath" | ||
|
||
# Open report | ||
$reportIndexHtml = Join-Path $reportOutputPath "index.html" | ||
Invoke-Item -Path $reportIndexHtml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.Extensions.Configuration; | ||
using RepoUtils; | ||
using Xunit.Abstractions; | ||
|
||
namespace Examples; | ||
|
||
public abstract class BaseTest | ||
{ | ||
protected ITestOutputHelper Output { get; } | ||
|
||
protected BaseTest(ITestOutputHelper output) | ||
{ | ||
this.Output = output; | ||
LoadUserSecrets(); | ||
} | ||
|
||
private static void LoadUserSecrets() | ||
{ | ||
IConfigurationRoot configRoot = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.Development.json", true) | ||
.AddEnvironmentVariables() | ||
.AddUserSecrets<Env>() | ||
.Build(); | ||
|
||
TestConfiguration.Initialize(configRoot); | ||
} | ||
|
||
/// <summary> | ||
/// This method can be substituted by Console.WriteLine when used in Console apps. | ||
/// </summary> | ||
/// <param name="target">Target object to write</param> | ||
protected void WriteLine(object? target = null) | ||
{ | ||
this.Output.WriteLine(target ?? string.Empty); | ||
} | ||
|
||
/// <summary> | ||
/// Current interface ITestOutputHelper does not have a Write method. This extension method adds it to make it analogous to Console.Write when used in Console apps. | ||
/// </summary> | ||
/// <param name="target">Target object to write</param> | ||
protected void Write(object? target = null) | ||
{ | ||
this.Output.WriteLine(target ?? string.Empty); | ||
} | ||
} |
18 changes: 13 additions & 5 deletions
18
dotnet/samples/KernelSyntaxExamples/Example01_MethodFunctions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.SemanticKernel.Plugins.Core; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
public static class Example01_MethodFunctions | ||
namespace Examples; | ||
|
||
public class Example01_MethodFunctions : BaseTest | ||
{ | ||
public static Task RunAsync() | ||
[Fact] | ||
public Task RunAsync() | ||
{ | ||
Console.WriteLine("======== Functions ========"); | ||
this.WriteLine("======== Functions ========"); | ||
|
||
// Load native plugin | ||
var text = new TextPlugin(); | ||
|
||
// Use function without kernel | ||
var result = text.Uppercase("ciao!"); | ||
|
||
Console.WriteLine(result); | ||
this.WriteLine(result); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public Example01_MethodFunctions(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.