From 1ad10c50f4c968efb8ec843bf9372d833c504d66 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 17 Oct 2026 08:01:21 +0200 Subject: [PATCH] Show managed config locations --- TASKS.md | 1 + cc.ps1 | 2 +- src/Configs.psm1 | 32 +++++++++++++++++++++++++++++++- src/Core.psm1 | 11 +++++++++-- tests/Configs.Tests.ps1 | 12 ++++++++++++ tools/check_powershell.py | 2 +- 6 files changed, 55 insertions(+), 5 deletions(-) diff --git a/TASKS.md b/TASKS.md index 19a7d52..5527721 100644 --- a/TASKS.md +++ b/TASKS.md @@ -102,6 +102,7 @@ open until it is run on disposable machines with the required account setups. ## Requested desktop configuration +- [x] Show each managed config's repository source and resolved computer path. - [x] Add the requested WinGet packages: XnView MP, Zoom, Nextcloud Desktop, Notepad++, HandBrake, GIMP, Krita, LibreOffice, Waterfox, and Shotcut. - [x] Add a safe registry-value adapter for MPC-HC settings. diff --git a/cc.ps1 b/cc.ps1 index 1f60c8e..12b066e 100644 --- a/cc.ps1 +++ b/cc.ps1 @@ -1,6 +1,6 @@ [CmdletBinding()] param( - [Parameter(Position = 0)][ValidateSet('doctor', 'plan', 'apply', 'sync', 'status', 'restore', 'schedule', 'unschedule', 'menu')][string]$Command = 'menu', + [Parameter(Position = 0)][ValidateSet('doctor', 'plan', 'apply', 'sync', 'status', 'configs', 'restore', 'schedule', 'unschedule', 'menu')][string]$Command = 'menu', [string]$Machine, [string]$Config, [switch]$ConfigsOnly, diff --git a/src/Configs.psm1 b/src/Configs.psm1 index f86193b..226926b 100644 --- a/src/Configs.psm1 +++ b/src/Configs.psm1 @@ -82,6 +82,36 @@ function Get-ConfigPlan { return @($plan) } +function Get-ConfigLocations { + param( + [Parameter(Mandatory)]$Configs, + [Parameter(Mandatory)][string]$RepositoryRoot, + [Parameter(Mandatory)]$Settings, + [string]$Name + ) + $pathMap = Get-UserPathMap -Settings $Settings + $selected = @($Configs) + if (-not [string]::IsNullOrWhiteSpace($Name)) { + $selected = @($selected | Where-Object { $_.name -eq $Name }) + if ($selected.Count -eq 0) { throw "Unknown config '$Name'." } + } + + $locations = [System.Collections.Generic.List[object]]::new() + foreach ($config in $selected) { + $source = Resolve-ConfigSource -RepositoryRoot $RepositoryRoot -Source $config.source + $target = if ($config.mode -eq 'registry') { [string]$config.target } else { Resolve-ConfigTarget -Target $config.target -PathMap $pathMap } + $targetExists = [bool](Test-Path -LiteralPath $target -ErrorAction SilentlyContinue) + $locations.Add([pscustomobject]@{ + kind = 'config'; name = [string]$config.name + status = if ($targetExists) { 'Present' } else { 'Missing' } + message = "Repository: $source | Computer: $target" + mode = [string]$config.mode; source = $source; target = $target + sourceExists = $true; targetExists = $targetExists + }) + } + return @($locations) +} + function Backup-ConfigTarget { param($Operation, $Paths) if (-not (Test-Path -LiteralPath $Operation.target -PathType Leaf)) { return $null } @@ -163,4 +193,4 @@ function Restore-ConfigBackup { [pscustomobject]@{ name = $Name; status = 'Restored'; message = "Restored $($backup.FullName)" } } -Export-ModuleMember -Function Get-UserPathMap, Resolve-ConfigTarget, Resolve-ConfigSource, Get-FileHashValue, Get-ConfigPlan, Invoke-ConfigOperation, Restore-ConfigBackup +Export-ModuleMember -Function Get-UserPathMap, Resolve-ConfigTarget, Resolve-ConfigSource, Get-FileHashValue, Get-ConfigPlan, Get-ConfigLocations, Invoke-ConfigOperation, Restore-ConfigBackup diff --git a/src/Core.psm1 b/src/Core.psm1 index 838516e..d6c2a36 100644 --- a/src/Core.psm1 +++ b/src/Core.psm1 @@ -132,6 +132,13 @@ function Invoke-ConfigCentral { [string]$Revision ) if ($Command -eq 'doctor') { return Invoke-Doctor -Machine $Machine -RepositoryRoot $RepositoryRoot -Paths $Paths } + if ($Command -eq 'configs') { + $settings = Read-JsonState -Path $Paths.Settings -Default ([ordered]@{}) + $effective = Resolve-MachineManifest -RepositoryRoot $RepositoryRoot -Machine $Machine + $result = New-BaseResult 'configs' + $result.operations = @(Get-ConfigLocations -Configs $effective.configs -RepositoryRoot $RepositoryRoot -Settings $settings -Name $Config) + return [pscustomobject]$result + } if ($Command -eq 'restore') { if ([string]::IsNullOrWhiteSpace($Config)) { throw 'restore requires -Config NAME.' } $state = Read-JsonState -Path $Paths.State -Default ([ordered]@{}) @@ -183,9 +190,9 @@ function Write-ConfigCentralResult { function Show-ConfigCentralMenu { param([string]$Machine, [string]$DataRoot, [string]$RepositoryRoot) Write-Host 'Config Central' - Write-Host '1. Plan 2. Sync 3. Status 4. Doctor 5. Schedule Q. Quit' + Write-Host '1. Plan 2. Sync 3. Status 4. Doctor 5. Schedule 6. Config paths Q. Quit' $choice = Read-Host 'Select' - $command = switch ($choice.ToUpperInvariant()) { '1' { 'plan' } '2' { 'sync' } '3' { 'status' } '4' { 'doctor' } '5' { 'schedule' } 'Q' { return } default { throw "Unknown menu choice '$choice'." } } + $command = switch ($choice.ToUpperInvariant()) { '1' { 'plan' } '2' { 'sync' } '3' { 'status' } '4' { 'doctor' } '5' { 'schedule' } '6' { 'configs' } 'Q' { return } default { throw "Unknown menu choice '$choice'." } } $arguments = @($command, '-RepositoryRoot', $RepositoryRoot) if ($Machine) { $arguments += @('-Machine', $Machine) } if ($DataRoot) { $arguments += @('-DataRoot', $DataRoot) } diff --git a/tests/Configs.Tests.ps1 b/tests/Configs.Tests.ps1 index ebd143e..f065bb8 100644 --- a/tests/Configs.Tests.ps1 +++ b/tests/Configs.Tests.ps1 @@ -59,6 +59,18 @@ Describe 'Configuration deployment' { Test-Path -LiteralPath $configs[0].target | Should -BeTrue } + It 'reports repository and computer config locations without changing them' { + New-Item -ItemType Directory (Split-Path -Parent $destination) -Force | Out-Null + 'computer value' | Set-Content $destination -NoNewline + $locations = Get-ConfigLocations -Configs $configs -RepositoryRoot $repo -Settings $settings -Name sample + $locations.Count | Should -Be 1 + $locations[0].source | Should -Be (Join-Path $repo 'configs/config.txt') + $locations[0].target | Should -Be $destination + $locations[0].targetExists | Should -BeTrue + (Get-Content -LiteralPath $destination -Raw) | Should -Be 'computer value' + { Get-ConfigLocations -Configs $configs -RepositoryRoot $repo -Settings $settings -Name missing } | Should -Throw "*Unknown config 'missing'*" + } + It 'refuses unsafe automatic restoration of registry and hosts backups' { $registryState = @{ configs = @{ 'mpc-hc-settings' = @{ mode = 'registry'; target = 'HKCU:\Software\MPC-HC\MPC-HC' } } } { Restore-ConfigBackup -Name mpc-hc-settings -Paths $paths -State $registryState } | Should -Throw '*not supported for registry*' diff --git a/tools/check_powershell.py b/tools/check_powershell.py index 027d17e..d16bef9 100644 --- a/tools/check_powershell.py +++ b/tools/check_powershell.py @@ -91,7 +91,7 @@ def main() -> int: except json.JSONDecodeError as exc: errors.append(f"{path.relative_to(ROOT)}: {exc}") - required_cli_markers = ("doctor", "plan", "apply", "sync", "status", "restore", "schedule", "unschedule", "menu") + required_cli_markers = ("doctor", "plan", "apply", "sync", "status", "configs", "restore", "schedule", "unschedule", "menu") cli = (ROOT / "cc.ps1").read_text(encoding="utf-8-sig") for marker in required_cli_markers: if not re.search(rf"['\"]{re.escape(marker)}['\"]", cli):