Skip to content

Refactor and enhance Pester tests batch #9762

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

Merged
merged 124 commits into from
Aug 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
8608521
Refactor and expand Copy-Dba* integration tests
potatoqualitee Aug 9, 2025
021cea4
Align splatting hashtable formatting in test scripts
potatoqualitee Aug 9, 2025
1f17830
Enhance formatter to preserve alignment and avoid unnecessary writes
potatoqualitee Aug 9, 2025
b07ac96
Improve file handling in Invoke-DbatoolsFormatter
potatoqualitee Aug 9, 2025
4b4c3b5
Improve formatting comparison in Invoke-DbatoolsFormatter
potatoqualitee Aug 9, 2025
d768d14
Merge branch 'formatfix' into b1
potatoqualitee Aug 9, 2025
05eb897
Refactor Invoke-DbatoolsFormatter for improved formatting
potatoqualitee Aug 9, 2025
21da25c
Add progress reporting to Invoke-DbatoolsFormatter
potatoqualitee Aug 9, 2025
2028a61
Merge branch 'formatfix' into b1
potatoqualitee Aug 9, 2025
380a3fe
skip invisible only
potatoqualitee Aug 9, 2025
eb17342
Preserve spaces before equals in formatter output
potatoqualitee Aug 9, 2025
f3a7cfc
Refactor formatter to improve invisible change detection
potatoqualitee Aug 9, 2025
e826197
Merge branch 'formatfix' into b1
potatoqualitee Aug 9, 2025
565e6a9
Remove trailing newline from test files
potatoqualitee Aug 9, 2025
0594e54
Add Repair-PullRequestTest for automated PR test fixes
potatoqualitee Aug 9, 2025
1389d27
Enhance AppVeyor failure detection and PR handling
potatoqualitee Aug 9, 2025
e95eea8
Enhance PR test repair with progress and AppVeyor TUI
potatoqualitee Aug 9, 2025
2ac6d19
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
fbd059f
Improve PR test repair with temp files and error handling
potatoqualitee Aug 9, 2025
fb3d269
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
8aa690c
Improve PR test repair with better context and Claude 4
potatoqualitee Aug 9, 2025
cff65b0
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
a8ae5e8
Improve branch handling in Repair-PullRequestTest
potatoqualitee Aug 9, 2025
c2c71e8
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
8f00e3d
Update pr.psm1
potatoqualitee Aug 9, 2025
59a0cef
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
4dd905f
Update pr.psm1
potatoqualitee Aug 9, 2025
1f07586
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
de4e2a2
Update pr.psm1
potatoqualitee Aug 9, 2025
f9e63d6
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
c868f55
Update pr.psm1
potatoqualitee Aug 9, 2025
262f465
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
8f7c1a5
Update pr.psm1
potatoqualitee Aug 9, 2025
aa2de87
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
1f11fe6
new
potatoqualitee Aug 9, 2025
1e936fe
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
586e13f
a
potatoqualitee Aug 9, 2025
365e309
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
cb010cd
Update pr.psm1
potatoqualitee Aug 9, 2025
41eddb5
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
e8ec5f7
Update aitools.psm1
potatoqualitee Aug 9, 2025
cc2a805
Update pr.psm1
potatoqualitee Aug 9, 2025
7032647
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
2670064
Update pr.psm1
potatoqualitee Aug 9, 2025
0edcad0
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
4019229
Update pr.psm1
potatoqualitee Aug 9, 2025
b436726
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
85dfef1
Update pr.psm1
potatoqualitee Aug 9, 2025
cdbed01
Merge branch 'tools' into b1
potatoqualitee Aug 9, 2025
74f802e
Update appveyor.pester.ps1
potatoqualitee Aug 9, 2025
ab23cb9
Add .aitools/module directory before renaming files
potatoqualitee Aug 9, 2025
2f382d0
Refactor aitools module structure and file naming
potatoqualitee Aug 9, 2025
cc3b815
Refactor module path handling and function imports
potatoqualitee Aug 9, 2025
689393c
Update prompt file paths in Update-PesterTest.ps1
potatoqualitee Aug 9, 2025
c9218ac
Refactor and enhance AI tool integration scripts
potatoqualitee Aug 9, 2025
763c629
Refactor job failure functions and remove inline docs
potatoqualitee Aug 9, 2025
c6b04a4
Refactor module path usage for consistency
potatoqualitee Aug 9, 2025
b67630c
Move prompt files to module directory
potatoqualitee Aug 9, 2025
98977e4
Update Get-TestArtifact.ps1
potatoqualitee Aug 9, 2025
bab45d4
Add Get-TestArtifactContent and enhance artifact retrieval
potatoqualitee Aug 9, 2025
d37d16d
Improve artifact retrieval and test failure reporting
potatoqualitee Aug 9, 2025
ffcc7a5
Enhance test failure reporting and remove unused script
potatoqualitee Aug 9, 2025
5b4a2d2
Refactor test failure extraction and remove formatter
potatoqualitee Aug 9, 2025
c5b7388
works finally
potatoqualitee Aug 9, 2025
6ce184d
Remove unused AppVeyor failure analysis scripts
potatoqualitee Aug 9, 2025
d9a37ee
Align aitools.psd1 formatting and indentation
potatoqualitee Aug 9, 2025
845cea3
Process all failed tests in PR test repair script
potatoqualitee Aug 9, 2025
584acfe
WORKS Minor improvements to Repair-PullRequestTest verbose output
potatoqualitee Aug 9, 2025
cff05aa
Focus test repair on changed files in PR
potatoqualitee Aug 9, 2025
a4e2d91
Improve test failure filtering and verbose output
potatoqualitee Aug 9, 2025
77de4af
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 9, 2025
dd84e83
WORKS
potatoqualitee Aug 9, 2025
4b03777
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 9, 2025
842665d
Improve input handling in AutoFix and PesterTest scripts
potatoqualitee Aug 9, 2025
fd32d29
Use global variables in integration test scripts
potatoqualitee Aug 9, 2025
eee01af
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 9, 2025
9fec993
Refactor and improve Pester tests for dbatools commands
potatoqualitee Aug 9, 2025
a4c2cc5
Deduplicate and fix test failures across all PRs
potatoqualitee Aug 10, 2025
17da193
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 10, 2025
91f7011
Use global variables in integration test setup
potatoqualitee Aug 10, 2025
8193d8a
Add ultra-verbose error extraction to test runner
potatoqualitee Aug 10, 2025
1d798a5
Add ultra-verbose error extraction to test runner
potatoqualitee Aug 10, 2025
894dd06
Update Invoke-AITool.ps1
potatoqualitee Aug 10, 2025
879b9fa
Update appveyor.pester.ps1
potatoqualitee Aug 10, 2025
3ce1558
Merge branch 'b1' of https://github.com/dataplat/dbatools into b1
potatoqualitee Aug 10, 2025
7f30f5c
Revert "Update appveyor.pester.ps1"
potatoqualitee Aug 10, 2025
858372b
Refactor test scripts to use $PSItem and improve error extraction
potatoqualitee Aug 10, 2025
5dd2965
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 10, 2025
9e5fb0d
Refactor repair prompt handling and update prompt files
potatoqualitee Aug 10, 2025
161cfac
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 10, 2025
e1846c8
Update Get-AppVeyorFailure.ps1
potatoqualitee Aug 10, 2025
57b9443
Update Invoke-AITool.ps1
potatoqualitee Aug 10, 2025
3d3320d
Update Invoke-AITool.ps1
potatoqualitee Aug 10, 2025
2062b82
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 10, 2025
3dee30f
Add BuildNumber parameter to AppVeyor failure tools
potatoqualitee Aug 10, 2025
e903fe3
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 10, 2025
b59a1bc
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 10, 2025
a22862f
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 10, 2025
568cedb
Improve process output handling and quiet git commands
potatoqualitee Aug 10, 2025
4aeb2e9
Improve error handling and code extraction in AI tools
potatoqualitee Aug 10, 2025
c8eae96
Update repair.md
potatoqualitee Aug 10, 2025
8249d98
a
potatoqualitee Aug 10, 2025
140eec5
Reorder and update repair message construction logic
potatoqualitee Aug 10, 2025
ede925f
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 10, 2025
5ed60a6
Update Repair-PullRequestTest.ps1
potatoqualitee Aug 10, 2025
fac0a78
Refactor integration tests to use global variables
potatoqualitee Aug 10, 2025
d88ed2c
Remove Repair-Error, Repair-SmallThing, and Repair-TestFile scripts
potatoqualitee Aug 10, 2025
1dfb99c
Revert "Refactor integration tests to use global variables"
potatoqualitee Aug 10, 2025
70123e8
Add migration policy note on integration tests
potatoqualitee Aug 10, 2025
35207aa
Refactor PR test repair to use working versions and update
potatoqualitee Aug 10, 2025
1369724
Parallelize Update-PesterTest and improve file handling
potatoqualitee Aug 10, 2025
1686015
Run formatter on processed files after parallel jobs
potatoqualitee Aug 10, 2025
0af56b1
old
potatoqualitee Aug 10, 2025
4887f51
Update Copy-DbaXESession.Tests.ps1
potatoqualitee Aug 10, 2025
cdcac59
Update Copy-DbaXESession.Tests.ps1
potatoqualitee Aug 10, 2025
b14c9dd
Update module paths to use PSScriptRoot for consistency
potatoqualitee Aug 10, 2025
e808dbe
Update Update-PesterTest.ps1
potatoqualitee Aug 10, 2025
4825111
Refactor parameter validation in Copy-Dba* test scripts
potatoqualitee Aug 10, 2025
ca13973
Refactor tests to use splatting for command parameters
potatoqualitee Aug 10, 2025
f881322
Remove dbatools import logic from AI tool scripts
potatoqualitee Aug 10, 2025
8a3e5ec
Update Copy-DbaLogin.Tests.ps1
potatoqualitee Aug 10, 2025
5b33444
cant do this automatically
potatoqualitee Aug 10, 2025
b401c4b
v4
potatoqualitee Aug 10, 2025
af09dd5
do Copy-DbaLogin
potatoqualitee Aug 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,999 changes: 0 additions & 1,999 deletions .aitools/aitools.psm1

This file was deleted.

172 changes: 172 additions & 0 deletions .aitools/module/Get-AppVeyorFailure.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
function Get-AppVeyorFailure {
<#
.SYNOPSIS
Retrieves test failure information from AppVeyor builds.

.DESCRIPTION
This function fetches test failure details from AppVeyor builds, either by specifying
pull request numbers or a specific build number. It extracts failed test information
from build artifacts and returns detailed failure data for analysis.

.PARAMETER PullRequest
Array of pull request numbers to process. If not specified and no BuildNumber is provided,
processes all open pull requests with AppVeyor failures.

.PARAMETER BuildNumber
Specific AppVeyor build number to target instead of automatically detecting from PR checks.
When specified, retrieves failures directly from this build number, ignoring PR-based detection.

.NOTES
Tags: Testing, AppVeyor, CI, PullRequest
Author: dbatools team
Requires: AppVeyor API access, gh CLI

.EXAMPLE
PS C:\> Get-AppVeyorFailure
Retrieves test failures from all open pull requests with AppVeyor failures.

.EXAMPLE
PS C:\> Get-AppVeyorFailure -PullRequest 9234
Retrieves test failures from AppVeyor builds associated with PR #9234.

.EXAMPLE
PS C:\> Get-AppVeyorFailure -PullRequest 9234, 9235
Retrieves test failures from AppVeyor builds associated with PRs #9234 and #9235.

.EXAMPLE
PS C:\> Get-AppVeyorFailure -BuildNumber 12345
Retrieves test failures directly from AppVeyor build #12345, bypassing PR detection.
#>
[CmdletBinding()]
param (
[int[]]$PullRequest,

[int]$BuildNumber
)

# If BuildNumber is specified, use it directly instead of looking up PR checks
if ($BuildNumber) {
Write-Progress -Activity "Get-AppVeyorFailure" -Status "Fetching build details for build #$BuildNumber..." -PercentComplete 0
Write-Verbose "Using specified build number: $BuildNumber"

try {
$apiParams = @{
Endpoint = "projects/dataplat/dbatools/builds/$BuildNumber"
}
$build = Invoke-AppVeyorApi @apiParams

if (-not $build -or -not $build.build -or -not $build.build.jobs) {
Write-Verbose "No build data or jobs found for build $BuildNumber"
Write-Progress -Activity "Get-AppVeyorFailure" -Completed
return
}

$failedJobs = $build.build.jobs | Where-Object Status -eq "failed"

if (-not $failedJobs) {
Write-Verbose "No failed jobs found in build $BuildNumber"
Write-Progress -Activity "Get-AppVeyorFailure" -Completed
return
}

$totalJobs = $failedJobs.Count
$currentJob = 0

foreach ($job in $failedJobs) {
$currentJob++
$jobProgress = [math]::Round(($currentJob / $totalJobs) * 100)
Write-Progress -Activity "Getting job failure information" -Status "Processing failed job $currentJob of $totalJobs for build #$BuildNumber" -PercentComplete $jobProgress -CurrentOperation "Job: $($job.name)"
Write-Verbose "Processing failed job: $($job.name) (ID: $($job.jobId))"
(Get-TestArtifact -JobId $job.jobid).Content.Failures
}
} catch {
Write-Verbose "Failed to fetch AppVeyor build details for build ${BuildNumber}: $_"
}

Write-Progress -Activity "Get-AppVeyorFailure" -Completed
return
}

# Original logic for PR-based build detection
if (-not $PullRequest) {
Write-Progress -Activity "Get-AppVeyorFailure" -Status "Fetching open pull requests..." -PercentComplete 0
Write-Verbose "No pull request numbers specified, getting all open PRs..."
$prsJson = gh pr list --state open --json "number,title,headRefName,state,statusCheckRollup"
if (-not $prsJson) {
Write-Progress -Activity "Get-AppVeyorFailure" -Completed
Write-Warning "No open pull requests found"
return
}
$openPRs = $prsJson | ConvertFrom-Json
$PullRequest = $openPRs | ForEach-Object { $_.number }
Write-Verbose "Found $($PullRequest.Count) open PRs: $($PullRequest -join ',')"
}

$totalPRs = $PullRequest.Count
$currentPR = 0

foreach ($prNumber in $PullRequest) {
$currentPR++
$prPercentComplete = [math]::Round(($currentPR / $totalPRs) * 100)
Write-Progress -Activity "Getting PR build information" -Status "Processing PR #$prNumber ($currentPR of $totalPRs)" -PercentComplete $prPercentComplete
Write-Verbose "Fetching AppVeyor build information for PR #$prNumber"

$checksJson = gh pr checks $prNumber --json "name,state,link" 2>$null
if (-not $checksJson) {
Write-Verbose "Could not fetch checks for PR #$prNumber"
continue
}

$checks = $checksJson | ConvertFrom-Json
$appveyorCheck = $checks | Where-Object { $_.name -like "*AppVeyor*" -and $_.state -match "PENDING|FAILURE" }

if (-not $appveyorCheck) {
Write-Verbose "No failing or pending AppVeyor builds found for PR #$prNumber"
continue
}

if ($appveyorCheck.link -match '/project/[^/]+/[^/]+/builds/(\d+)') {
$buildId = $Matches[1]
} else {
Write-Verbose "Could not parse AppVeyor build ID from URL: $($appveyorCheck.link)"
continue
}

try {
Write-Progress -Activity "Getting build details" -Status "Fetching build details for PR #$prNumber" -PercentComplete $prPercentComplete
Write-Verbose "Fetching build details for build ID: $buildId"

$apiParams = @{
Endpoint = "projects/dataplat/dbatools/builds/$buildId"
}
$build = Invoke-AppVeyorApi @apiParams

if (-not $build -or -not $build.build -or -not $build.build.jobs) {
Write-Verbose "No build data or jobs found for build $buildId"
continue
}

$failedJobs = $build.build.jobs | Where-Object Status -eq "failed"

if (-not $failedJobs) {
Write-Verbose "No failed jobs found in build $buildId"
continue
}

$totalJobs = $failedJobs.Count
$currentJob = 0

foreach ($job in $failedJobs) {
$currentJob++
Write-Progress -Activity "Getting job failure information" -Status "Processing failed job $currentJob of $totalJobs for PR #$prNumber" -PercentComplete $prPercentComplete -CurrentOperation "Job: $($job.name)"
Write-Verbose "Processing failed job: $($job.name) (ID: $($job.jobId))"
(Get-TestArtifact -JobId $job.jobid).Content.Failures
}
} catch {
Write-Verbose "Failed to fetch AppVeyor build details for build ${buildId}: $_"
continue
}
}

Write-Progress -Activity "Get-AppVeyorFailure" -Completed
}
81 changes: 81 additions & 0 deletions .aitools/module/Get-TestArtifact.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
function Get-TestArtifact {
<#
.SYNOPSIS
Gets test artifacts from an AppVeyor job.

.DESCRIPTION
Retrieves test failure summary artifacts from an AppVeyor job.

.PARAMETER JobId
The AppVeyor job ID to get artifacts from.

.NOTES
Tags: AppVeyor, Testing, Artifacts
Author: dbatools team
Requires: APPVEYOR_API_TOKEN environment variable
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[string[]]$JobId
)

function Get-JsonFromContent {
param([Parameter(ValueFromPipeline)]$InputObject)
process {
if ($null -eq $InputObject) { return $null }

# AppVeyor often returns PSCustomObject with .Content (string) and .Created
$raw = if ($InputObject -is [string] -or $InputObject -is [byte[]]) {
$InputObject
} elseif ($InputObject.PSObject.Properties.Name -contains 'Content') {
$InputObject.Content
} else {
[string]$InputObject
}

$s = if ($raw -is [byte[]]) { [Text.Encoding]::UTF8.GetString($raw) } else { [string]$raw }
$s = $s.TrimStart([char]0xFEFF) # strip BOM
if ($s -notmatch '^\s*[\{\[]') {
throw "Artifact body is not JSON. Starts with: '$($s.Substring(0,1))'."
}
$s | ConvertFrom-Json -Depth 50
}
}

foreach ($id in $JobId) {
Write-Verbose ("Fetching artifacts for job {0}" -f $id)
$list = Invoke-AppVeyorApi "buildjobs/$id/artifacts"
if (-not $list) { Write-Warning ("No artifacts for job {0}" -f $id); continue }

$targets = $list | Where-Object { $_.fileName -match 'TestFailureSummary.*\.json' }
if (-not $targets) {
continue
}

foreach ($art in $targets) {
$resp = Invoke-AppVeyorApi "buildjobs/$id/artifacts/$($art.fileName)"

$parsed = $null
$rawOut = $null
$created = if ($resp.PSObject.Properties.Name -contains 'Created') { $resp.Created } else { $art.created }

try {
$parsed = $resp | Get-JsonFromContent
} catch {
$rawOut = if ($resp.PSObject.Properties.Name -contains 'Content') { [string]$resp.Content } else { [string]$resp }
Write-Warning ("Failed to parse {0} in job {1}: {2}" -f $art.fileName, $id, $_.Exception.Message)
}

[pscustomobject]@{
JobId = $id
FileName = $art.fileName
Type = $art.type
Size = $art.size
Created = $created
Content = $parsed
Raw = $rawOut
}
}
}
}
Loading
Loading