Skip to content

Commit 6c2998d

Browse files
authored
removed legacy code coverage (#17)
* removed legacy code coverage * code coverage and standards * test environment based * override testroot * soft fail
1 parent 16341d3 commit 6c2998d

35 files changed

Lines changed: 188 additions & 144 deletions
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
####################################################################################
2+
# To execute
3+
# 1. In powershell, set security policy for this script:
4+
# Set-ExecutionPolicy Unrestricted -Scope Process -Force
5+
# 2. Change directory to the script folder:
6+
# CD src (wherever your script is)
7+
# 3. In powershell, run script:
8+
# .\Get-CodeCoverage.ps1 -TestProjectFilter '*Tests*.csproj'
9+
# This script uses native .NET 10 code coverage (Microsoft.Testing.Platform)
10+
# Note: Due to MSTest 4.1.0 incompatibility with 'dotnet test' on .NET 10, this runs tests as executables
11+
####################################################################################
12+
13+
Param(
14+
[string]$TestProjectFilter = '*Tests*.csproj',
15+
[string]$Configuration = 'Release',
16+
[string]$TestRootPath = ''
17+
)
18+
####################################################################################
19+
if ($IsWindows) {Set-ExecutionPolicy Unrestricted -Scope Process -Force}
20+
$VerbosePreference = 'SilentlyContinue' # 'Continue'
21+
####################################################################################
22+
23+
function Resolve-TestRootPath {
24+
param(
25+
[Parameter(Mandatory = $true)]
26+
[System.IO.DirectoryInfo]$ScriptDir,
27+
[Parameter(Mandatory = $false)]
28+
[string]$OverridePath
29+
)
30+
31+
if (-not [string]::IsNullOrWhiteSpace($OverridePath)) {
32+
return Get-Item -Path (Resolve-Path -Path $OverridePath)
33+
}
34+
35+
$current = $ScriptDir
36+
while ($null -ne $current) {
37+
$srcCandidate = Join-Path $current.FullName 'src'
38+
if (Test-Path -Path $srcCandidate) {
39+
return Get-Item -Path $srcCandidate
40+
}
41+
42+
$current = $current.Parent
43+
}
44+
45+
return $ScriptDir
46+
}
47+
48+
# Install required tools
49+
& dotnet tool install -g dotnet-reportgenerator-globaltool
50+
& dotnet tool install -g dotnet-coverage
51+
52+
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
53+
$scriptPath = Get-Item -Path $PSScriptRoot
54+
$testRootPath = Resolve-TestRootPath -ScriptDir $scriptPath -OverridePath $TestRootPath
55+
$reportOutputPath = Join-Path $testRootPath "TestResults\Reports\$timestamp"
56+
57+
New-Item -ItemType Directory -Force -Path $reportOutputPath
58+
59+
# Find test projects
60+
$testProjects = Get-ChildItem $testRootPath -Filter $TestProjectFilter -Recurse
61+
Write-Host "Found $($testProjects.Count) test projects."
62+
63+
foreach ($project in $testProjects) {
64+
$testProjectPath = $project.FullName
65+
Write-Host "Running tests with coverage for project: $($project.BaseName)"
66+
67+
Write-Host "Building test project: $($project.BaseName)"
68+
& dotnet build $testProjectPath --configuration $Configuration
69+
70+
# Use 'dotnet run' instead of 'dotnet test' for MSTest runner projects
71+
# This bypasses the VSTest target that's incompatible with .NET 10 SDK
72+
Push-Location $project.DirectoryName
73+
& dotnet run --configuration $Configuration --no-build -- --coverage
74+
Pop-Location
75+
}
76+
77+
# Collect all coverage files (Microsoft.Testing.Platform outputs .coverage files)
78+
$coverageFiles = Get-ChildItem -Path $testRootPath -Filter "*.coverage" -Recurse | Select-Object -ExpandProperty FullName
79+
80+
if ($coverageFiles.Count -eq 0) {
81+
Write-Warning "No coverage files found. Make sure your test projects have code coverage enabled."
82+
exit 0
83+
}
84+
85+
Write-Host "Found $($coverageFiles.Count) coverage file(s)"
86+
87+
# Convert binary .coverage files to XML format
88+
$coverageXmlFiles = @()
89+
foreach ($coverageFile in $coverageFiles) {
90+
$xmlFile = $coverageFile -replace '\.coverage$', '.cobertura.xml'
91+
Write-Host "Converting $coverageFile to XML format..."
92+
& dotnet-coverage merge $coverageFile --output $xmlFile --output-format cobertura
93+
if (Test-Path $xmlFile) {
94+
$coverageXmlFiles += $xmlFile
95+
}
96+
}
97+
98+
if ($coverageXmlFiles.Count -eq 0) {
99+
Write-Warning "No XML coverage files were generated."
100+
exit 0
101+
}
102+
103+
Write-Host "Generated $($coverageXmlFiles.Count) XML coverage file(s)"
104+
105+
# Generate HTML report
106+
$coverageFilesArg = ($coverageXmlFiles -join ";")
107+
& reportgenerator -reports:$coverageFilesArg -targetdir:$reportOutputPath -reporttypes:Html
108+
109+
Write-Host "Code coverage report generated at: $reportOutputPath"
110+
111+
$reportIndexHtml = Join-Path $reportOutputPath "index.html"
112+
if (Test-Path $reportIndexHtml) {
113+
Invoke-Item -Path $reportIndexHtml
114+
}
115+
else {
116+
Write-Warning "Report index.html not found at: $reportIndexHtml"
117+
}

.github/workflows/gtc-agent-standalone-web-api-sql.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,21 @@ jobs:
154154
with:
155155
name: ${{ env.MIGRATION_ARTIFACT_NAME }}
156156
path: ${{ env.MIGRATION_ARTIFACT_PATH }}
157+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
157158

158159
- name: Test
160+
run: |
161+
cd ${{ env.SRC_PATH }}/${{ env.TEST_PATH }}
162+
dotnet run --configuration ${{ env.CONFIGURATION }} --no-build
163+
shell: pwsh
164+
165+
- name: Copy test results
166+
if: ${{ always() }}
159167
run: |
160168
mkdir -p TestResults-${{ matrix.DOTNET_VERSION }}
161-
dotnet test ${{ env.SRC_PATH }}/${{ env.TEST_PATH }}/${{ env.TEST_PROJECT }} --configuration ${{ env.CONFIGURATION }} --results-directory TestResults-${{ matrix.DOTNET_VERSION }} --collect:"Code Coverage" --verbosity normal
169+
if (Test-Path "${{ env.SRC_PATH }}/${{ env.TEST_PATH }}/bin/Release/net10.0/TestResults") {
170+
Copy-Item -Path "${{ env.SRC_PATH }}/${{ env.TEST_PATH }}/bin/Release/net10.0/TestResults/*" -Destination "TestResults-${{ matrix.DOTNET_VERSION }}" -Recurse -Force
171+
}
162172
shell: pwsh
163173

164174
- name: Upload test results
@@ -178,6 +188,7 @@ jobs:
178188
with:
179189
name: ${{ env.API_ARTIFACT_NAME }}
180190
path: ${{ env.API_ARTIFACT_OUTPUT }}/**
191+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
181192

182193
- name: Pack Blazor artifact
183194
run: |
@@ -189,16 +200,18 @@ jobs:
189200
with:
190201
name: ${{ env.WEB_ARTIFACT_NAME }}
191202
path: ${{ env.WEB_ARTIFACT_OUTPUT }}/**
203+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
192204

193205
- name: Perform CodeQL Analysis
194206
uses: github/codeql-action/analyze@v4
195207
if: ${{ !github.event.repository.private }}
196208

197209
- name: Run Coverage Script
198210
run: |
199-
pwsh ${{ env.SRC_PATH }}/Get-CodeCoverage.ps1 `
211+
pwsh ${{ env.SCRIPTS_PATH }}/ci/Get-CodeCoverage.ps1 `
200212
-TestProjectFilter '${{ env.TEST_PROJECT }}' `
201-
-ProdPackagesOnly
213+
-Configuration '${{ env.CONFIGURATION }}' `
214+
-TestRootPath '${{ env.SRC_PATH }}'
202215
shell: pwsh
203216

204217
- name: Upload Coverage Report

src/.github/copilot-instructions.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/Core.Application/Abstractions/IAgentFrameworkContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Goodtocode.AgentFramework.Core.Application.Abstractions;
77
public interface IAgentFrameworkContext
88
{
99
DbSet<ChatMessageEntity> ChatMessages { get; }
10-
DbSet<ChatSessionEntity> ChatSessions {get; }
10+
DbSet<ChatSessionEntity> ChatSessions { get; }
1111
DbSet<ActorEntity> Actors { get; }
1212

1313
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);

src/Core.Application/Actor/SaveMyActorCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public async Task<ActorDto> Handle(SaveMyActorCommand request, CancellationToken
2929
}
3030
else
3131
{
32-
actor = ActorEntity.Create(Guid.NewGuid(), request?.FirstName, request?.LastName, request?.Email);
32+
actor = ActorEntity.Create(Guid.NewGuid(), request?.FirstName, request?.LastName, request?.Email);
3333
_context.Actors.Add(actor);
3434
}
3535

src/Core.Application/ChatCompletion/CreateMyChatMessageCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@ private static void GuardAgainstUnauthorizedUser(ChatSessionEntity chatSession,
108108
private static void GuardAgainstNullAgentResponse(ChatMessage? response)
109109
{
110110
if (response == null)
111-
throw new CustomValidationException([new("ChatMessage","Agent response cannot be null")]);
111+
throw new CustomValidationException([new("ChatMessage", "Agent response cannot be null")]);
112112
}
113113
}

src/Core.Application/ChatCompletion/CreateMyChatSessionCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ public async Task<ChatSessionDto> Handle(CreateMyChatSessionCommand request, Can
3030
GuardAgainstEmptyUser(request?.UserContext);
3131

3232
var actor = await _context.Actors
33-
.FirstOrDefaultAsync(a => a.OwnerId == request!.UserContext!.OwnerId
33+
.FirstOrDefaultAsync(a => a.OwnerId == request!.UserContext!.OwnerId
3434
&& a.TenantId == request.UserContext.TenantId, cancellationToken);
35-
35+
3636
if (actor == null)
3737
{
3838
actor = ActorEntity.Create(
3939
Guid.NewGuid(),
40-
request?.UserContext?.FirstName,
41-
request?.UserContext?.LastName,
40+
request?.UserContext?.FirstName,
41+
request?.UserContext?.LastName,
4242
request?.UserContext?.Email
4343
);
4444
_context.Actors.Add(actor);

src/Core.Application/ChatCompletion/CreateMyChatSessionCommandValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class CreateMyChatSessionCommandValidator : Validator<CreateMyChatSessionCommand>
44
{
55
public CreateMyChatSessionCommandValidator()
6-
{
6+
{
77
RuleFor(x => x.Message)
88
.NotEmpty("Message is required");
99

src/Core.Application/ChatCompletion/GetMyChatMessagesPaginatedQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task<PaginatedList<ChatMessageDto>> Handle(GetMyChatMessagesPaginat
2222
{
2323
GuardAgainstEmptyUser(request?.UserContext);
2424

25-
var userContext = request!.UserContext!;
25+
var userContext = request!.UserContext!;
2626

2727
var returnData = await _context.ChatMessages
2828
.Where(x => x.ChatSession != null && x.ChatSession.OwnerId == userContext.OwnerId)

src/Core.Application/ChatCompletion/GetMyChatSessionsQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public async Task<ICollection<ChatSessionDto>> Handle(GetMyChatSessionsQuery req
2121

2222
var startDate = request?.StartDate;
2323
var endDate = request?.EndDate;
24-
var userContext = request?.UserContext;
24+
var userContext = request?.UserContext;
2525

2626
var returnData = await _context.ChatSessions
2727
.Where(x => userContext != null && x.OwnerId == userContext.OwnerId)

0 commit comments

Comments
 (0)