Skip to content

Commit

Permalink
Spector coverage publish (#48000)
Browse files Browse the repository at this point in the history
* update new proj scaffolding

* rename cadl ranch to spector

* fixes after rename

* pr fb

* update format

* fix spacing

* pr fb

* fix spacing
  • Loading branch information
m-nash authored Jan 28, 2025
1 parent d6b2752 commit c247920
Show file tree
Hide file tree
Showing 430 changed files with 868 additions and 1,553 deletions.
2 changes: 1 addition & 1 deletion eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
</ItemGroup>

<ItemGroup Condition="'$(IsGeneratorLibrary)' == 'true'">
<PackageReference Update="Microsoft.Generator.CSharp.ClientModel" Version="1.0.0-alpha.20250123.2" />
<PackageReference Update="Microsoft.Generator.CSharp.ClientModel" Version="1.0.0-alpha.20250127.1" />
</ItemGroup>

<!--
Expand Down
31 changes: 16 additions & 15 deletions eng/packages/http-client-csharp/eng/scripts/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
param(
$filter,
[bool]$Stubbed = $true,
[bool]$LaunchOnly = $false
[bool]$LaunchOnly = $false,
[switch]$ForceNewProject = $false
)

Import-Module "$PSScriptRoot\Generation.psm1" -DisableNameChecking -Force;
Expand All @@ -20,14 +21,14 @@ if (-not $LaunchOnly) {
$unbrandedTypespecTestProject = Join-Path $testProjectsLocalDir "Basic-TypeSpec"
$unbrandedTypespecTestProject = $unbrandedTypespecTestProject

Invoke (Get-TspCommand "$unbrandedTypespecTestProject/Basic-TypeSpec.tsp" $unbrandedTypespecTestProject)
Invoke (Get-TspCommand "$unbrandedTypespecTestProject/Basic-TypeSpec.tsp" $unbrandedTypespecTestProject -forceNewProject $ForceNewProject)

# exit if the generation failed
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

Write-Host "Building UnbrandedTypeSpec" -ForegroundColor Cyan
Write-Host "Building BasicTypeSpec" -ForegroundColor Cyan
Invoke "dotnet build $packageRoot/generator/TestProjects/Local/Basic-TypeSpec/src/BasicTypeSpec.csproj"

# exit if the generation failed
Expand All @@ -39,7 +40,7 @@ if (-not $LaunchOnly) {

$specsDirectory = "$packageRoot/node_modules/@typespec/http-specs"
$azureSpecsDirectory = "$packageRoot/node_modules/@azure-tools/azure-http-specs"
$cadlRanchRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch'
$spectorRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'Spector'

function IsSpecDir {
param (
Expand Down Expand Up @@ -95,9 +96,9 @@ $azureAllowSpecs = @(
Join-Path 'http' 'resiliency' 'srv-driven'
)

$cadlRanchLaunchProjects = @{}
$spectorLaunchProjects = @{}

# Loop through all directories and subdirectories of the cadl ranch specs
# Loop through all directories and subdirectories of the spector specs
$directories = @(Get-ChildItem -Path "$specsDirectory/specs" -Directory -Recurse)
$directories += @(Get-ChildItem -Path "$azureSpecsDirectory/specs" -Directory -Recurse)
foreach ($directory in $directories) {
Expand Down Expand Up @@ -128,7 +129,7 @@ foreach ($directory in $directories) {
continue
}

$generationDir = $cadlRanchRoot
$generationDir = $spectorRoot
foreach ($folder in $folders) {
$generationDir = Join-Path $generationDir $folder
}
Expand All @@ -140,26 +141,26 @@ foreach ($directory in $directories) {

if ($folders.Contains("versioning")) {
Generate-Versioning $directory.FullName $generationDir -generateStub $stubbed
$cadlRanchLaunchProjects.Add($($folders -join "-") + "-v1", $("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v1")
$cadlRanchLaunchProjects.Add($($folders -join "-") + "-v2", $("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v2")
$spectorLaunchProjects.Add($($folders -join "-") + "-v1", $("TestProjects/Spector/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v1")
$spectorLaunchProjects.Add($($folders -join "-") + "-v2", $("TestProjects/Spector/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v2")
continue
}

# srv-driven contains two separate specs, for two separate clients. We need to generate both.
if ($folders.Contains("srv-driven")) {
Generate-Srv-Driven $directory.FullName $generationDir -generateStub $stubbed
$cadlRanchLaunchProjects.Add($($folders -join "-") + "-v1", $("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v1")
$cadlRanchLaunchProjects.Add($($folders -join "-") + "-v2", $("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v2")
$spectorLaunchProjects.Add($($folders -join "-") + "-v1", $("TestProjects/Spector/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v1")
$spectorLaunchProjects.Add($($folders -join "-") + "-v2", $("TestProjects/Spector/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v2")
continue
}

$cadlRanchLaunchProjects.Add(($folders -join "-"), ("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))"))
$spectorLaunchProjects.Add(($folders -join "-"), ("TestProjects/Spector/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))"))
if ($LaunchOnly) {
continue
}

Write-Host "Generating $subPath" -ForegroundColor Cyan
Invoke (Get-TspCommand $specFile $generationDir $stubbed)
Invoke (Get-TspCommand $specFile $generationDir $stubbed -forceNewProject $ForceNewProject)

# exit if the generation failed
if ($LASTEXITCODE -ne 0) {
Expand All @@ -181,7 +182,7 @@ if ($null -eq $filter) {
$launchSettings["profiles"]["Basic-TypeSpec"].Add("commandName", "Executable")
$launchSettings["profiles"]["Basic-TypeSpec"].Add("executablePath", "dotnet")

foreach ($kvp in $cadlRanchLaunchProjects.GetEnumerator()) {
foreach ($kvp in $spectorLaunchProjects.GetEnumerator()) {
$launchSettings["profiles"].Add($kvp.Key, @{})
$launchSettings["profiles"][$kvp.Key].Add("commandLineArgs", "`$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll `$(SolutionDir)/$($kvp.Value) -p AzureStubPlugin")
$launchSettings["profiles"][$kvp.Key].Add("commandName", "Executable")
Expand All @@ -207,5 +208,5 @@ if ($null -eq $filter) {
# Write the launch settings to the launchSettings.json file
$launchSettingsPath = Join-Path $solutionDir "Azure.Generator" "src" "Properties" "launchSettings.json"
# Write the settings to JSON and normalize line endings to Unix style (LF)
$sortedLaunchSettings | ConvertTo-Json | ForEach-Object { $_ -replace "`r`n", "`n" } | Set-Content $launchSettingsPath
$sortedLaunchSettings | ConvertTo-Json | ForEach-Object { ($_ -replace "`r`n", "`n") + "`n" } | Set-Content -NoNewline $launchSettingsPath
}
7 changes: 6 additions & 1 deletion eng/packages/http-client-csharp/eng/scripts/Generation.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function Get-TspCommand {
[string]$generationDir,
[bool]$generateStub = $false,
[string]$namespaceOverride = $null,
[string]$apiVersion = $null
[string]$apiVersion = $null,
[bool]$forceNewProject = $false
)
$command = "npx tsp compile $specFile"
$command += " --trace @azure-typespec/http-client-csharp"
Expand All @@ -49,6 +50,10 @@ function Get-TspCommand {
$command += " --option @azure-typespec/http-client-csharp.api-version=$apiVersion"
}

if ($forceNewProject) {
$command += " --option @azure-typespec/http-client-csharp.new-project=true"
}

return $command
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#Requires -Version 7.0

Import-Module "$PSScriptRoot\Generation.psm1" -DisableNameChecking -Force;
Import-Module "$PSScriptRoot\CadlRanch-Helper.psm1" -DisableNameChecking -Force;
Import-Module "$PSScriptRoot\Spector-Helper.psm1" -DisableNameChecking -Force;

$packageRoot = Resolve-Path (Join-Path $PSScriptRoot '..' '..')

Refresh-Build

$specsDirectory = Join-Path $packageRoot 'node_modules' '@typespec' 'http-specs' 'specs'
$azureSpecsDirectory = Join-Path $packageRoot 'node_modules' '@azure-tools' 'azure-http-specs' 'specs'
$cadlRanchRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch' 'http'
$directories = Get-ChildItem -Path "$cadlRanchRoot" -Directory -Recurse
$cadlRanchCsproj = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch.Tests' 'TestProjects.CadlRanch.Tests.csproj'
$spectorRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'Spector' 'http'
$directories = Get-ChildItem -Path "$spectorRoot" -Directory -Recurse
$spectorCsproj = Join-Path $packageRoot 'generator' 'TestProjects' 'Spector.Tests' 'TestProjects.Spector.Tests.csproj'

$coverageDir = Join-Path $packageRoot 'generator' 'artifacts' 'coverage'

Expand All @@ -26,7 +26,7 @@ foreach ($directory in $directories) {
}

$outputDir = $directory.FullName.Substring(0, $directory.FullName.IndexOf("src") - 1)
$subPath = $outputDir.Substring($cadlRanchRoot.Length + 1)
$subPath = $outputDir.Substring($spectorRoot.Length + 1)

Write-Host "Regenerating $subPath" -ForegroundColor Cyan

Expand Down Expand Up @@ -66,8 +66,8 @@ foreach ($directory in $directories) {
}

# test all
Write-Host "Generating CadlRanch coverage" -ForegroundColor Cyan
$command = "dotnet test $cadlRanchCsproj"
Write-Host "Generating Spector coverage" -ForegroundColor Cyan
$command = "dotnet test $spectorCsproj"
Invoke $command
# exit if the testing failed
if ($LASTEXITCODE -ne 0) {
Expand All @@ -81,7 +81,7 @@ foreach ($directory in $directories) {
}

$outputDir = $directory.FullName.Substring(0, $directory.FullName.IndexOf("src") - 1)
$subPath = $outputDir.Substring($cadlRanchRoot.Length + 1)
$subPath = $outputDir.Substring($spectorRoot.Length + 1)

Write-Host "Restoring $subPath" -ForegroundColor Cyan
$command = "git clean -xfd $outputDir"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
param($filter)

Import-Module "$PSScriptRoot\Generation.psm1" -DisableNameChecking -Force;
Import-Module "$PSScriptRoot\CadlRanch-Helper.psm1" -DisableNameChecking -Force;
Import-Module "$PSScriptRoot\Spector-Helper.psm1" -DisableNameChecking -Force;

$packageRoot = Resolve-Path (Join-Path $PSScriptRoot '..' '..')

Refresh-Build

$specsDirectory = Join-Path $packageRoot 'node_modules' '@typespec' 'http-specs' 'specs'
$azureSpecsDirectory = Join-Path $packageRoot 'node_modules' '@azure-tools' 'azure-http-specs' 'specs'
$cadlRanchRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch'
$cadlRanchRootHttp = Join-Path $cadlRanchRoot 'http'
$directories = Get-ChildItem -Path "$cadlRanchRootHttp" -Directory -Recurse
$cadlRanchCsproj = Join-Path $packageRoot 'generator' 'TestProjects' 'CadlRanch.Tests' 'TestProjects.CadlRanch.Tests.csproj'
$spectorRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'Spector'
$spectorRootHttp = Join-Path $spectorRoot 'http'
$directories = Get-ChildItem -Path "$spectorRootHttp" -Directory -Recurse
$spectorCsproj = Join-Path $packageRoot 'generator' 'TestProjects' 'Spector.Tests' 'TestProjects.Spector.Tests.csproj'

$coverageDir = Join-Path $packageRoot 'generator' 'artifacts' 'coverage'

Expand All @@ -28,15 +28,15 @@ foreach ($directory in $directories) {
}

$outputDir = $directory.FullName.Substring(0, $directory.FullName.IndexOf("src") - 1)
$subPath = $outputDir.Substring($cadlRanchRootHttp.Length + 1)
$subPath = $outputDir.Substring($spectorRootHttp.Length + 1)
$folders = $subPath.Split([System.IO.Path]::DirectorySeparatorChar)

if (-not (Compare-Paths $subPath $filter)) {
continue
}

$testPath = Join-Path "$cadlRanchRoot.Tests" "Http"
$testFilter = "TestProjects.CadlRanch.Tests.Http"
$testPath = Join-Path "$spectorRoot.Tests" "Http"
$testFilter = "TestProjects.Spector.Tests.Http"
foreach ($folder in $folders) {
$segment = "$(Get-Namespace $folder)"

Expand Down Expand Up @@ -87,7 +87,7 @@ foreach ($directory in $directories) {
}

Write-Host "Testing $subPath" -ForegroundColor Cyan
$command = "dotnet test $cadlRanchCsproj --filter `"FullyQualifiedName~$testFilter`""
$command = "dotnet test $spectorCsproj --filter `"FullyQualifiedName~$testFilter`""
Invoke $command
# exit if the testing failed
if ($LASTEXITCODE -ne 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ internal class AzureStubVisitor : ScmLibraryVisitor
if (!type.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Public) &&
!type.Name.StartsWith("Unknown", StringComparison.Ordinal) &&
!type.Name.Equals("MultiPartFormDataBinaryContent", StringComparison.Ordinal))
{
return null;
}

type.Update(xmlDocs: _emptyDocs);
return type;
Expand All @@ -48,7 +50,9 @@ internal class AzureStubVisitor : ScmLibraryVisitor
if (!IsCallingBaseCtor(constructor) &&
!IsEffectivelyPublic(constructor.Signature.Modifiers) &&
(constructor.EnclosingType is not ModelProvider model || model.DerivedModels.Count == 0))
{
return null;
}

constructor.Update(
bodyStatements: null,
Expand Down Expand Up @@ -76,7 +80,9 @@ private static bool IsCallingBaseCtor(ConstructorProvider constructor)
protected override MethodProvider? Visit(MethodProvider method)
{
if (method.Signature.ExplicitInterface is null && !IsEffectivelyPublic(method.Signature.Modifiers))
{
return null;
}

method.Signature.Update(modifiers: method.Signature.Modifiers & ~MethodSignatureModifiers.Async);

Expand All @@ -95,7 +101,9 @@ private static bool IsCallingBaseCtor(ConstructorProvider constructor)
protected override PropertyProvider? Visit(PropertyProvider property)
{
if (!property.IsDiscriminator && !IsEffectivelyPublic(property.Modifiers))
{
return null;
}

var propertyBody = new ExpressionPropertyBody(_throwNull, property.Body.HasSetter ? _throwNull : null);

Expand All @@ -109,10 +117,14 @@ private static bool IsCallingBaseCtor(ConstructorProvider constructor)
private bool IsEffectivelyPublic(MethodSignatureModifiers modifiers)
{
if (modifiers.HasFlag(MethodSignatureModifiers.Public))
{
return true;
}

if (modifiers.HasFlag(MethodSignatureModifiers.Protected) && !modifiers.HasFlag(MethodSignatureModifiers.Private))
{
return true;
}

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProjects.Local.Tests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Generator.StubLibrary", "Azure.Generator.StubLibrary\src\Azure.Generator.StubLibrary.csproj", "{CC2E7459-398A-60FA-5138-282707944E43}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProjects.CadlRanch.Tests", "TestProjects\CadlRanch.Tests\TestProjects.CadlRanch.Tests.csproj", "{FD729CC8-FAAC-B384-0328-6F590DCAA5AA}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProjects.Spector.Tests", "TestProjects\Spector.Tests\TestProjects.Spector.Tests.csproj", "{FD729CC8-FAAC-B384-0328-6F590DCAA5AA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Loading

0 comments on commit c247920

Please sign in to comment.