From 96e963d70c4426fb3e54ec3d9f7f7e4834d9693a Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Tue, 15 Jul 2025 17:44:11 -0700 Subject: [PATCH 1/2] Description should be empty when it is missing in ModuleFile --- .../ModuleFileMarkdownReader.cs | 10 +- .../Pester/ImportMarkdownModuleFile.Tests.ps1 | 8 +- test/Pester/MeasurePlatyPSMarkdown.Tests.ps1 | 4 +- ...ystemCenter.ServiceManagementAutomation.md | 131 ++++++++++++++++++ 4 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 test/Pester/assets/Microsoft.SystemCenter.ServiceManagementAutomation.md diff --git a/src/MarkdownReader/ModuleFileMarkdownReader.cs b/src/MarkdownReader/ModuleFileMarkdownReader.cs index ca5e5f33..57677c5c 100644 --- a/src/MarkdownReader/ModuleFileMarkdownReader.cs +++ b/src/MarkdownReader/ModuleFileMarkdownReader.cs @@ -181,10 +181,18 @@ internal static string GetModuleFileDescriptionFromMarkdown(ParsedMarkdownConten var nextHeader = md.FindHeader(nextHeaderLevel, ""); if (nextHeader == -1) { - nextHeaderLevel = 3; + md.CurrentIndex--; // Back up to the description header + return string.Empty; } string descriptionString = MarkdownConverter.GetLinesTillNextHeader(md, nextHeaderLevel, index); + + if (string.Equals(descriptionString.Trim(), "## Description", StringComparison.OrdinalIgnoreCase)) + { + diagnostics.Add(new DiagnosticMessage(DiagnosticMessageSource.ModuleFileDescription, "No description found", DiagnosticSeverity.Warning, "GetModuleFileDescription", md.Ast[index].Line)); + return string.Empty; + } + diagnostics.Add(new DiagnosticMessage(DiagnosticMessageSource.ModuleFileDescription, "Module description found", DiagnosticSeverity.Information, "GetModuleFileDescription", md.Ast[index].Line)); return descriptionString.Trim(); } diff --git a/test/Pester/ImportMarkdownModuleFile.Tests.ps1 b/test/Pester/ImportMarkdownModuleFile.Tests.ps1 index 1c52f660..d790b3d2 100644 --- a/test/Pester/ImportMarkdownModuleFile.Tests.ps1 +++ b/test/Pester/ImportMarkdownModuleFile.Tests.ps1 @@ -9,7 +9,7 @@ Describe "Import-ModuleFile tests" { Context "File creation" { It "Should be able to read module files" { $results = $modFiles.FullName | Import-MarkdownModuleFile - $results.Count | Should -Be 14 + $results.Count | Should -Be 15 } It "Should produce the correct type of object" { @@ -87,6 +87,12 @@ Describe "Import-ModuleFile tests" { $mf0.CommandGroups[0].Commands[$offset].Description | Should -Be $Description } + + It "Should be able to parse even if description is missing" { + $mf = Import-MarkdownModuleFile "${PSScriptRoot}/assets/Microsoft.SystemCenter.ServiceManagementAutomation.md" + $mf.Description | Should -Be "" + $mf.CommandGroups.Count | Should -Be 1 + } } Context "Metadata content" { diff --git a/test/Pester/MeasurePlatyPSMarkdown.Tests.ps1 b/test/Pester/MeasurePlatyPSMarkdown.Tests.ps1 index 96c6f0ae..9bc9a328 100644 --- a/test/Pester/MeasurePlatyPSMarkdown.Tests.ps1 +++ b/test/Pester/MeasurePlatyPSMarkdown.Tests.ps1 @@ -14,8 +14,8 @@ Describe "Export-MarkdownModuleFile" { It "Should identify all the '' assets" -TestCases @( @{ fileType = "unknown"; expectedCount = 2 } @{ fileType = "CommandHelp"; expectedCount = 41 } - @{ fileType = "ModuleFile"; expectedCount = 15 } - @{ fileType = "V1Schema"; expectedCount = 51 } + @{ fileType = "ModuleFile"; expectedCount = 16 } + @{ fileType = "V1Schema"; expectedCount = 52 } @{ fileType = "V2Schema"; expectedCount = 5 } ) { param ($fileType, $expectedCount) diff --git a/test/Pester/assets/Microsoft.SystemCenter.ServiceManagementAutomation.md b/test/Pester/assets/Microsoft.SystemCenter.ServiceManagementAutomation.md new file mode 100644 index 00000000..7479b96a --- /dev/null +++ b/test/Pester/assets/Microsoft.SystemCenter.ServiceManagementAutomation.md @@ -0,0 +1,131 @@ +--- +Download Help Link: +Help Version: 5.0.0.0 +Locale: en-US +Module Guid: 03F356FB-485D-41BC-B7FE-7F573ECC186F +Module Name: Microsoft.SystemCenter.ServiceManagementAutomation +--- + +# Microsoft.SystemCenter.ServiceManagementAutomation Module +## Description + +## Microsoft.SystemCenter.ServiceManagementAutomation Cmdlets +### [Edit-SmaRunbook](Edit-SmaRunbook.md) +Updates the draft field of a runbook. + +### [Get-SmaAdminConfiguration](Get-SmaAdminConfiguration.md) +Gets the SMA administration configuration. + +### [Get-SmaCertificate](Get-SmaCertificate.md) +Gets a certificate. + +### [Get-SmaConnection](Get-SmaConnection.md) +Gets an SMA connection. + +### [Get-SmaConnectionField](Get-SmaConnectionField.md) +Gets an SMA connection field. + +### [Get-SmaConnectionType](Get-SmaConnectionType.md) +Gets all SMA connection types. + +### [Get-SmaCredential](Get-SmaCredential.md) +Gets SMA credentials. + +### [Get-SmaJob](Get-SmaJob.md) +Gets a runbook job. + +### [Get-SmaJobOutput](Get-SmaJobOutput.md) +Gets the output of a SMA job. + +### [Get-SmaLicense](Get-SmaLicense.md) +Gets an SMA license. + +### [Get-SmaModule](Get-SmaModule.md) +Gets a module from SMA. + +### [Get-SmaRunbook](Get-SmaRunbook.md) +Gets an SMA runbook. + +### [Get-SmaRunbookDefinition](Get-SmaRunbookDefinition.md) +Gets a runbook definition. + +### [Get-SmaRunbookWorkerDeployment](Get-SmaRunbookWorkerDeployment.md) +Gets all runbook workers in the SMA deployment. + +### [Get-SmaSchedule](Get-SmaSchedule.md) +Gets an SMA schedule. + +### [Get-SmaVariable](Get-SmaVariable.md) +Gets an SMA variable. + +### [Import-SmaModule](Import-SmaModule.md) +Imports a module into SMA. + +### [Import-SmaRunbook](Import-SmaRunbook.md) +Imports a runbook into SMA. + +### [New-SmaConnection](New-SmaConnection.md) +Creates a connection instance in SMA. + +### [New-SmaRunbookWorkerDeployment](New-SmaRunbookWorkerDeployment.md) +Changes the runbook worker deployment in SMA. + +### [Publish-SmaRunbook](Publish-SmaRunbook.md) +Publishes a runbook in SMA. + +### [Remove-SmaCertificate](Remove-SmaCertificate.md) +Deletes a certificate from SMA. + +### [Remove-SmaConnection](Remove-SmaConnection.md) +Deletes a connection from SMA. + +### [Remove-SmaCredential](Remove-SmaCredential.md) +Deletes a credential from SMA. + +### [Remove-SmaModule](Remove-SmaModule.md) +Deletes a module from SMA. + +### [Remove-SmaRunbook](Remove-SmaRunbook.md) +Removes a runbook from SMA. + +### [Remove-SmaSchedule](Remove-SmaSchedule.md) +Deletes a schedule from SMA. + +### [Remove-SmaVariable](Remove-SmaVariable.md) +Deletes a variable from SMA. + +### [Resume-SmaJob](Resume-SmaJob.md) +Resumes a SMA job. + +### [Set-SmaAdminConfiguration](Set-SmaAdminConfiguration.md) +Modifies administrative configuration settings in SMA. + +### [Set-SmaCertificate](Set-SmaCertificate.md) +Creates or updates a certificate in SMA. + +### [Set-SmaConnectionFieldValue](Set-SmaConnectionFieldValue.md) +Modifies a connection field value for a connection object in SMA. + +### [Set-SmaCredential](Set-SmaCredential.md) +Creates or updates a credential in SMA. + +### [Set-SmaLicense](Set-SmaLicense.md) +Updates the SMA product key. + +### [Set-SmaRunbookConfiguration](Set-SmaRunbookConfiguration.md) +Modifies the configuration of a runbook. + +### [Set-SmaSchedule](Set-SmaSchedule.md) +Creates or modifies a schedule in SMA. + +### [Set-SmaVariable](Set-SmaVariable.md) +Creates or modifies a variable in SMA. + +### [Start-SmaRunbook](Start-SmaRunbook.md) +Starts a runbook job. + +### [Stop-SmaJob](Stop-SmaJob.md) +Stops a SMA job. + +### [Suspend-SmaJob](Suspend-SmaJob.md) +Suspends an SMA job. From 26669095b0978e13c388afaffc89546fa71386ac Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Tue, 15 Jul 2025 17:48:09 -0700 Subject: [PATCH 2/2] Remove unecessary change --- src/MarkdownReader/ModuleFileMarkdownReader.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/MarkdownReader/ModuleFileMarkdownReader.cs b/src/MarkdownReader/ModuleFileMarkdownReader.cs index 57677c5c..6028d6b1 100644 --- a/src/MarkdownReader/ModuleFileMarkdownReader.cs +++ b/src/MarkdownReader/ModuleFileMarkdownReader.cs @@ -186,13 +186,6 @@ internal static string GetModuleFileDescriptionFromMarkdown(ParsedMarkdownConten } string descriptionString = MarkdownConverter.GetLinesTillNextHeader(md, nextHeaderLevel, index); - - if (string.Equals(descriptionString.Trim(), "## Description", StringComparison.OrdinalIgnoreCase)) - { - diagnostics.Add(new DiagnosticMessage(DiagnosticMessageSource.ModuleFileDescription, "No description found", DiagnosticSeverity.Warning, "GetModuleFileDescription", md.Ast[index].Line)); - return string.Empty; - } - diagnostics.Add(new DiagnosticMessage(DiagnosticMessageSource.ModuleFileDescription, "Module description found", DiagnosticSeverity.Information, "GetModuleFileDescription", md.Ast[index].Line)); return descriptionString.Trim(); }