-
-
Notifications
You must be signed in to change notification settings - Fork 837
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
Conversation
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
Standardizes parameter validation in unit tests and enhances integration tests for Copy-DbaAgentProxy, Copy-DbaAgentSchedule, Copy-DbaAgentServer, Copy-DbaBackupDevice, Copy-DbaCredential, Copy-DbaCustomError, Copy-DbaDataCollector, and Copy-DbaDatabase. Adds more robust setup/teardown, uses dynamic variables, and improves test coverage for various scenarios and parameters.
Standardized the alignment and indentation of hashtable keys and values in multiple test scripts for consistency and readability. No functional changes were made to the test logic.
Updated Invoke-DbatoolsFormatter to use custom PSSA settings that preserve manually aligned hashtables and assignment operators. The script now only writes files if formatting changes are detected, reducing unnecessary file writes.
Added checks to skip directories and non-PowerShell files, improved error handling for file read/write operations, and ensured only valid content is processed. These changes enhance robustness and prevent errors when processing invalid or unreadable files.
Enhances the formatter to compare processed, formatted content rather than raw content, ensuring that only meaningful formatting changes trigger file writes. Also applies CBH (Comment-Based Help) fixes and whitespace normalization to both the original and formatted content for accurate comparison.
Simplifies the formatter by removing custom alignment-preserving settings and redundant code. Now uses a placeholder approach to preserve aligned assignments, streamlines file type checks, and only writes files if actual formatting changes are detected. Improves maintainability and reliability of the formatting process.
Enhanced Invoke-DbatoolsFormatter to display progress when formatting multiple files, including status updates for each file, error handling, and a summary of processed and updated files. This improves user feedback during batch operations.
Updated Invoke-DbatoolsFormatter to automatically restore multiple spaces before '=' signs after formatting. This ensures alignment and spacing in assignments is preserved, addressing formatting issues introduced by the code formatter.
Simplifies and improves the logic for detecting invisible-only changes (such as whitespace, line endings, and BOM) by normalizing and comparing content. Extracts formatting logic into a new helper function, reduces redundant file reads, and streamlines the main process loop for better maintainability and clarity.
Deleted the trailing newline at the end of several test files to maintain consistency in file formatting.
Introduces a PowerShell module to automatically detect and repair failing Pester tests in open pull requests using Claude AI. The script fetches PRs with AppVeyor failures, gathers failure details, compares with the development branch, and uses AI to suggest and optionally commit fixes. Includes supporting functions for AppVeyor failure extraction and test file repair.
Improves the Repair-PullRequestTest and Get-AppVeyorFailure functions to better handle multiple pull requests, support both pending and failed AppVeyor states, and provide more robust parsing and reporting of test failures. Adds support for processing all open PRs if none are specified, improves progress reporting, and enriches the returned failure objects with PR numbers for better traceability.
Adds detailed Write-Progress feedback to Repair-PullRequestTest for PR, file, and test-level operations. Refactors AppVeyor API calls for improved error handling and log parsing, and introduces Show-AppVeyorBuildStatus for a user-friendly, colorized TUI build status display. Improves parameter handling, code readability, and robustness throughout the module.
Adds checks for uncommitted changes, uses a cross-platform temp directory for working test files, and fetches context files from the development branch and command source. Suppresses git command output, improves error handling, and cleans up temp files after execution. These changes enhance reliability and provide more context for automated test repairs.
Updated the default AI model to 'claude-sonnet-4-20250514' and enhanced the repair process by providing more detailed context messages for test failures. Improved logic for locating command source files and switched to using Invoke-AITool for test file repairs, passing relevant context files and messages to Claude.
Enhances detection and verification of the current branch throughout the Repair-PullRequestTest function. Adds explicit checks, verbose logging, and error handling to ensure the script reliably returns to the original branch after processing pull requests and during branch switches, reducing the risk of ending in an unexpected git state.
Invoke-AITool.ps1 now captures output from the 'claude' process using Start-Process with redirected output, addressing encoding issues. Repair-PullRequestTest.ps1 updates git commands to use the --quiet flag for less verbose output and redirects output to null for cleaner logs.
Refactored Invoke-AITool.ps1 to use PowerShell's call operator for executing 'claude', improving output encoding and error capture. Enhanced Repair-PullRequestTest.ps1 to inline command code for reference by extracting script blocks or relevant file content, providing better context for repairs.
Moved the inclusion of command scriptblock content and working test file content to later in the repair message construction for better context. Also removed an unnecessary context file from the Claude invocation parameters.
Updated several test scripts to use $global: variables for shared state, improving reliability and consistency across test blocks. Added error handling in cleanup steps, adjusted assertions for accuracy, and improved test setup for login existence and permission checks.
Deleted the Repair-Error.ps1, Repair-SmallThing.ps1, and Repair-TestFile.ps1 scripts from the .aitools/module directory. These scripts provided AI-assisted repair functionality for dbatools test files and error handling, but are no longer needed or have been deprecated.
This reverts commit fac0a78.
Added a guideline to the migration checklist advising not to invent new integration tests if they do not already exist, clarifying migration policy.
Repair-PullRequestTest.ps1 now replaces failing Pester test files with working versions from the development branch and runs Update-PesterTest for migration, instead of using AI-based fixes. The Update-PesterTest.ps1 script now supports skipping dbatools module import if already loaded, improving performance and avoiding redundant imports during batch operations.
Refactored Repair-PullRequestTest.ps1 to replace test files sequentially and then run Update-PesterTest in parallel using Start-Job, improving performance for multiple files. Enhanced branch checkout commands to use --force for reliability, and added more robust error handling and progress reporting throughout the process.
Added a step to collect successfully processed files and run Invoke-DbatoolsFormatter after all Update-PesterTest parallel jobs complete. This ensures code formatting is applied before committing changes.
Replaced usage of $script:ModulePath with $PSScriptRoot for resolving file paths, improving reliability and consistency. Enhanced dbatools module import logic to handle path resolution failures gracefully and search recursively if needed.
Standardized and improved parameter validation in test scripts for Copy-DbaAgentSchedule, Copy-DbaAgentServer, Copy-DbaDbAssembly, Copy-DbaLogin, and Copy-DbaXESession. Replaced hardcoded command names and parameter lists with dynamic variables, unified the approach to parameter comparison, and enhanced test setup/teardown logic for integration tests. This improves maintainability and consistency across the test suite.
Updated Copy-DbaLogin integration tests to use PowerShell splatting for command parameters, improving readability and maintainability. This change standardizes parameter passing and makes it easier to modify or extend test cases in the future.
Eliminated all dbatools and dbatools.library import and installation logic from Invoke-AutoFix.ps1, Repair-PullRequestTest.ps1, and Update-PesterTest.ps1. These scripts now assume required test file paths are provided and no longer attempt dynamic module discovery or import, simplifying execution and reducing external dependencies.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Standardizes parameter validation in unit tests and enhances integration tests for Copy-DbaAgentProxy, Copy-DbaAgentSchedule, Copy-DbaAgentServer, Copy-DbaBackupDevice, Copy-DbaCredential, Copy-DbaCustomError, Copy-DbaDataCollector, and Copy-DbaDatabase. Adds more robust setup/teardown, uses dynamic variables, and improves test coverage for various scenarios and parameters.
COPY-DBALOGIN HAD TO BE REVERTED