-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Set up spector tests generation for http-client-csharp-mgmt #54206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
8
commits into
main
Choose a base branch
from
copilot/setup-spector-tests-http-client-mgmt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+51,852
−1
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1203f1f
Initial plan
Copilot e1a9701
Set up spector tests generation for http-client-csharp-mgmt
Copilot 9f002db
Fix extra space in Test-Spector.ps1
Copilot 02a7753
Address review feedback: rename csproj, remove Directory.Build.props,…
Copilot 9cf5891
Add spector generated code and verification tests for resource-manage…
Copilot ca9c2ff
Skip method-subscription-id generation due to long file paths in CI
Copilot e04b06d
Revert changes to Generation.psm1
Copilot a646e35
Update Spector generation to use AzureStubGenerator
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
115 changes: 115 additions & 0 deletions
115
eng/packages/http-client-csharp-mgmt/eng/scripts/Spector-Helper.psm1
This file contains hidden or 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,115 @@ | ||
| $repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..') | ||
|
|
||
| # These are specs that are not yet building correctly with the management generator | ||
| # Add specs here as needed when they fail to build | ||
| $failingSpecs = @( | ||
| # method-subscription-id: Skipped due to "Some file paths are too long" error in CI | ||
| "http/azure/resource-manager/method-subscription-id" | ||
| ) | ||
|
|
||
| function Capitalize-FirstLetter { | ||
| param ( | ||
| [string]$inputString | ||
| ) | ||
|
|
||
| if ([string]::IsNullOrEmpty($inputString)) { | ||
| return $inputString | ||
| } | ||
|
|
||
| $firstChar = $inputString[0].ToString().ToUpper() | ||
| $restOfString = $inputString.Substring(1) | ||
|
|
||
| return $firstChar + $restOfString | ||
| } | ||
|
|
||
| function Get-Namespace { | ||
| param ( | ||
| [string]$dir | ||
| ) | ||
|
|
||
| $words = $dir.Split('-') | ||
| $namespace = "" | ||
| foreach ($word in $words) { | ||
| $namespace += Capitalize-FirstLetter $word | ||
| } | ||
| return $namespace | ||
| } | ||
|
|
||
| function IsValidSpecDir { | ||
| param ( | ||
| [string]$fullPath | ||
| ) | ||
| if (-not(Test-Path "$fullPath/main.tsp")){ | ||
| return $false; | ||
| } | ||
|
|
||
| $subPath = Get-SubPath $fullPath | ||
|
|
||
| if ($failingSpecs.Contains($subPath)) { | ||
| Write-Host "Skipping $subPath" -ForegroundColor Yellow | ||
| return $false | ||
| } | ||
|
|
||
| return $true | ||
| } | ||
|
|
||
| function Get-Azure-Specs-Directory { | ||
| $packageRoot = Resolve-Path (Join-Path $PSScriptRoot '..' '..') | ||
| return Join-Path $packageRoot 'node_modules' '@azure-tools' 'azure-http-specs' | ||
| } | ||
|
|
||
| function Get-Sorted-Specs { | ||
| $azureSpecsDirectory = Get-Azure-Specs-Directory | ||
|
|
||
| # Only get azure resource-manager specs | ||
| $resourceManagerPath = Join-Path $azureSpecsDirectory "specs" "azure" "resource-manager" | ||
| $directories = @(Get-ChildItem -Path $resourceManagerPath -Directory -Recurse) | ||
|
|
||
| $sep = [System.IO.Path]::DirectorySeparatorChar | ||
| $pattern = "${sep}specs${sep}" | ||
|
|
||
| return $directories | Where-Object { IsValidSpecDir $_.FullName } | ForEach-Object { | ||
|
|
||
| # Pick client.tsp if it exists, otherwise main.tsp | ||
| $specFile = Join-Path $_.FullName "client.tsp" | ||
| if (-not (Test-Path $specFile)) { | ||
| $specFile = Join-Path $_.FullName "main.tsp" | ||
| } | ||
|
|
||
| # Extract the relative path after "specs/" and normalize slashes | ||
| $relativePath = ($specFile -replace '[\\\/]', '/').Substring($_.FullName.IndexOf($pattern) + $pattern.Length) | ||
|
|
||
| # Remove the filename to get just the directory path | ||
| $dirPath = $relativePath -replace '/[^/]+\.tsp$', '' | ||
|
|
||
| # Produce an object with the path for sorting | ||
| [PSCustomObject]@{ | ||
| SpecFile = $specFile | ||
| DirPath = $dirPath | ||
| } | ||
| } | Sort-Object -Property @{Expression = { $_.DirPath -replace '/', '!' }; Ascending = $true} | ForEach-Object { $_.SpecFile } | ||
| } | ||
|
|
||
| function Get-SubPath { | ||
| param ( | ||
| [string]$fullPath | ||
| ) | ||
| $azureSpecsDirectory = Get-Azure-Specs-Directory | ||
|
|
||
| $subPath = $fullPath.Substring($azureSpecsDirectory.Length + 1) | ||
|
|
||
| # Keep consistent with the previous folder name because 'http' makes more sense then current 'specs' | ||
| $subPath = $subPath -replace '^specs', 'http' | ||
|
|
||
| # also strip off the spec file name if present | ||
| $leaf = Split-Path -Leaf $subPath | ||
| if ($leaf -like '*.tsp') { | ||
| return (Split-Path $subPath) | ||
| } | ||
|
|
||
| return $subPath | ||
| } | ||
|
|
||
| Export-ModuleMember -Function "Get-Namespace" | ||
| Export-ModuleMember -Function "Get-Sorted-Specs" | ||
| Export-ModuleMember -Function "Get-SubPath" | ||
82 changes: 82 additions & 0 deletions
82
eng/packages/http-client-csharp-mgmt/eng/scripts/Test-Spector.ps1
This file contains hidden or 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,82 @@ | ||||||
| #Requires -Version 7.0 | ||||||
|
|
||||||
| param($filter) | ||||||
|
|
||||||
| Import-Module "$PSScriptRoot\Generation.psm1" -DisableNameChecking -Force; | ||||||
| Import-Module "$PSScriptRoot\Spector-Helper.psm1" -DisableNameChecking -Force; | ||||||
|
|
||||||
| $packageRoot = Resolve-Path (Join-Path $PSScriptRoot '..' '..') | ||||||
|
|
||||||
| Refresh-Mgmt-Build | ||||||
|
|
||||||
| $spectorRoot = Join-Path $packageRoot 'generator' 'TestProjects' 'Spector' | ||||||
| $spectorCsproj = Join-Path $packageRoot 'generator' 'TestProjects' 'Spector.Tests' 'Azure.Generator.Spector.Tests.csproj' | ||||||
|
|
||||||
| $coverageDir = Join-Path $packageRoot 'generator' 'artifacts' 'coverage' | ||||||
|
|
||||||
| if (-not (Test-Path $coverageDir)) { | ||||||
| New-Item -ItemType Directory -Path $coverageDir | Out-Null | ||||||
| } | ||||||
|
|
||||||
| foreach ($specFile in Get-Sorted-Specs) { | ||||||
| $subPath = Get-SubPath $specFile | ||||||
|
|
||||||
| # skip the HTTP root folder when computing the namespace filter | ||||||
| $folders = $subPath.Split([System.IO.Path]::DirectorySeparatorChar) | Select-Object -Skip 1 | ||||||
|
|
||||||
| if (-not (Compare-Paths $subPath $filter)) { | ||||||
| continue | ||||||
| } | ||||||
|
|
||||||
| $testPath = Join-Path "$spectorRoot.Tests" "Http" | ||||||
| $testFilter = "TestProjects.Spector.Tests.Http" | ||||||
| foreach ($folder in $folders) { | ||||||
| $segment = "$(Get-Namespace $folder)" | ||||||
|
|
||||||
| # the test directory names match the test namespace names, but the source directory names will not have the leading underscore | ||||||
| # so check to see if the filter should contain a leading underscore by comparing with the test directory | ||||||
| if (-not (Test-Path (Join-Path $testPath $segment))) { | ||||||
| $testFilter += "._$segment" | ||||||
| $testPath = Join-Path $testPath "_$segment" | ||||||
| } | ||||||
| else{ | ||||||
|
||||||
| else{ | |
| else { |
25 changes: 25 additions & 0 deletions
25
...lient-csharp-mgmt/generator/Azure.Generator.Management/src/Properties/launchSettings.json
This file contains hidden or 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
54 changes: 54 additions & 0 deletions
54
...ent-csharp-mgmt/generator/TestProjects/Spector.Tests/Azure.Generator.Spector.Tests.csproj
This file contains hidden or 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 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>net9.0</TargetFrameworks> | ||
| <RequiredTargetFrameworks>net9.0</RequiredTargetFrameworks> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" /> | ||
| <PackageReference Include="NUnit" /> | ||
| <PackageReference Include="NUnit3TestAdapter" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\Azure.Generator.Management\test\Common\Azure.Generator.Management.Tests.Common.csproj" /> | ||
| <!-- Some generated projects have build issues - commenting out for now --> | ||
| <!-- <ProjectReference Include="..\Spector\http\azure\resource-manager\common-properties\src\Azure.ResourceManager.CommonProperties.csproj" /> --> | ||
| <ProjectReference Include="..\Spector\http\azure\resource-manager\large-header\src\Azure.ResourceManager.LargeHeader.csproj" /> | ||
| <!-- method-subscription-id: Skipped due to "Some file paths are too long" error in CI --> | ||
| <!-- <ProjectReference Include="..\Spector\http\azure\resource-manager\method-subscription-id\src\Azure.ResourceManager.MethodSubscriptionId.csproj" /> --> | ||
| <!-- <ProjectReference Include="..\Spector\http\azure\resource-manager\non-resource\src\Azure.ResourceManager.NonResource.csproj" /> --> | ||
| <ProjectReference Include="..\Spector\http\azure\resource-manager\operation-templates\src\Azure.ResourceManager.OperationTemplates.csproj" /> | ||
| <!-- <ProjectReference Include="..\Spector\http\azure\resource-manager\resources\src\Azure.ResourceManager.Resources.csproj" /> --> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <AssemblyAttribute Include="TestProjects.Spector.Tests.BuildProperties"> | ||
| <_Parameter1>$(RepoRoot)</_Parameter1> | ||
| <_Parameter2>$(RepoRoot)\eng\packages\http-client-csharp-mgmt\generator\artifacts</_Parameter2> | ||
| </AssemblyAttribute> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Include shared code from Azure.Core --> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\AzureKeyCredentialPolicy.cs" LinkBase="Shared/Core" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\RawRequestUriBuilder.cs" LinkBase="Shared/Core" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\AppContextSwitchHelper.cs" LinkBase="Shared/Core" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\ClientDiagnostics.cs" LinkBase="Shared/Core" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\DiagnosticScopeFactory.cs" LinkBase="Shared/Core" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\DiagnosticScope.cs" LinkBase="Shared/Core" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\HttpMessageSanitizer.cs" LinkBase="Shared/Core" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core.TestFramework\src\ProcessTracker.cs" LinkBase="Shared/TestFramework" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\TypeFormatters.cs" LinkBase="Shared/Core" /> | ||
| <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\sdk\core\Azure.Core\src\Shared\RequestHeaderExtensions.cs" LinkBase="Shared/Core" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Update="Http\**\TestData\**\*.json"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
IndexOfwithout checking if the pattern exists first could result in -1 + pattern.Length if pattern is not found, causing an invalid substring index.