From 3300bedd38be43c406df4c6d1ad7e98eefd088b3 Mon Sep 17 00:00:00 2001 From: jacobyoby Date: Tue, 8 Sep 2026 01:08:33 -0700 Subject: [PATCH 1/2] fix(wizard): keep inventory output distinct --- examples/New-NetworkDiagram.ps1 | 35 ++++++++++++++++++++++++++++++--- tests/NetDiagram.Tests.ps1 | 30 ++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/examples/New-NetworkDiagram.ps1 b/examples/New-NetworkDiagram.ps1 index e20d7d2..50b102f 100644 --- a/examples/New-NetworkDiagram.ps1 +++ b/examples/New-NetworkDiagram.ps1 @@ -101,7 +101,35 @@ function Get-SubnetScanTarget { return $hostValues.ToArray() } -# Allow the Pester suite to dot-source this script for the CIDR helper functions above +function Get-InventoryOutputPath { + param([Parameter(Mandatory)][string]$DiagramPath) + + if ([string]::IsNullOrWhiteSpace($DiagramPath)) { + throw 'Diagram output path cannot be empty.' + } + + $fileName = [System.IO.Path]::GetFileNameWithoutExtension($DiagramPath) + if ([string]::IsNullOrWhiteSpace($fileName)) { + throw "Diagram output path must include a file name: $DiagramPath" + } + + $directory = [System.IO.Path]::GetDirectoryName($DiagramPath) + $inventoryFileName = "$fileName-inventory.json" + $inventoryPath = if ([string]::IsNullOrEmpty($directory)) { + $inventoryFileName + } + else { + [System.IO.Path]::Combine($directory, $inventoryFileName) + } + + if ([System.IO.Path]::GetFullPath($inventoryPath) -eq [System.IO.Path]::GetFullPath($DiagramPath)) { + throw 'Diagram and inventory output paths must be different.' + } + + return $inventoryPath +} + +# Allow the Pester suite to dot-source this script for the pure helper functions above # without launching the interactive wizard (which performs a live network scan). if ($MyInvocation.InvocationName -eq '.') { return } @@ -483,6 +511,7 @@ $topology = [pscustomobject]@{ # Step 5: Generate diagram Write-Host "`n[5/5] Generating your network diagram..." -ForegroundColor Yellow +$inventoryPath = Get-InventoryOutputPath -DiagramPath $OutputPath $topology | Export-DrawIO -OutFile $OutputPath if (Test-Path $OutputPath) { @@ -490,8 +519,8 @@ if (Test-Path $OutputPath) { Write-Host " ✓ Created: $OutputPath ($fileSize bytes)" -ForegroundColor Green } -# Save inventory for future use -$inventoryPath = $OutputPath -replace '\.drawio$', '-inventory.json' +# Save inventory for future use. Every accepted diagram extension produces a +# distinct sibling inventory file. $inventoryData = @{ knownDevices = @($nodes | ForEach-Object { @{ diff --git a/tests/NetDiagram.Tests.ps1 b/tests/NetDiagram.Tests.ps1 index e321402..a5343bb 100644 --- a/tests/NetDiagram.Tests.ps1 +++ b/tests/NetDiagram.Tests.ps1 @@ -637,3 +637,33 @@ Describe 'Quick-start wizard CIDR math (#4 regression)' { $targets.Count | Should -Be 0 } } + +Describe 'Quick-start wizard output paths (#9 regression)' { + BeforeAll { + $exampleScript = Join-Path $PSScriptRoot '..' 'examples' 'New-NetworkDiagram.ps1' + . $exampleScript + } + + It 'Derives a sibling inventory path for a drawio diagram' { + Get-InventoryOutputPath -DiagramPath './office.drawio' | + Should -Be (Join-Path '.' 'office-inventory.json') + } + + It 'Keeps an XML diagram and its inventory distinct' { + $diagramPath = Join-Path $TestDrive 'office.xml' + $inventoryPath = Get-InventoryOutputPath -DiagramPath $diagramPath + + $inventoryPath | Should -Be (Join-Path $TestDrive 'office-inventory.json') + [System.IO.Path]::GetFullPath($inventoryPath) | + Should -Not -Be ([System.IO.Path]::GetFullPath($diagramPath)) + } + + It 'Keeps an extensionless diagram and its inventory distinct' { + $diagramPath = Join-Path $TestDrive 'office' + $inventoryPath = Get-InventoryOutputPath -DiagramPath $diagramPath + + $inventoryPath | Should -Be (Join-Path $TestDrive 'office-inventory.json') + [System.IO.Path]::GetFullPath($inventoryPath) | + Should -Not -Be ([System.IO.Path]::GetFullPath($diagramPath)) + } +} From 18679b05daff95e6e1b45bfa6fb5c91e02ff12df Mon Sep 17 00:00:00 2001 From: Jacobrakai <45674026+jacobyoby@users.noreply.github.com> Date: Tue, 8 Sep 2026 18:28:26 +0000 Subject: [PATCH 2/2] ci: retrigger Actions for PR #23