BeforeAll { Import-Module "$PSScriptRoot/../src/Adapters.psm1" -Force } Describe 'Application configuration adapters' { It 'merges only declared INI keys and preserves other values' { $target = Join-Path $TestDrive 'nextcloud.cfg' $overlay = Join-Path $TestDrive 'overlay.ini' "[General]`nexisting=keep`nchunkSize=10`n`n[Account0]`nauthToken=secret" | Set-Content $target "[General]`nchunkSize=20`nnewValue=yes" | Set-Content $overlay $desired = Read-IniValues -Path $overlay $merged = Merge-IniFile -Target $target -Desired $desired $merged | Should -Match 'existing=keep' $merged | Should -Match 'chunkSize=20' $merged | Should -Match 'newValue=yes' $merged | Should -Match 'authToken=secret' } It 'treats a comment-only INI overlay as a no-op' { $source = Join-Path $TestDrive 'empty.ini' '# Add managed keys here.' | Set-Content $source $config = [pscustomobject]@{ name = 'safe'; mode = 'ini-overlay' } (Get-AdapterPlan -Config $config -Source $source -Target (Join-Path $TestDrive 'target.ini') -Record $null).action | Should -Be 'None' } It 'validates hosts entries and replaces only its named block' { $source = Join-Path $TestDrive 'hosts.entries' $target = Join-Path $TestDrive 'hosts' "127.0.0.1 before.example`n# ignored" | Set-Content $source "10.0.0.1 outside.example`n`n# BEGIN CONFIG CENTRAL: managed-hosts`n127.0.0.1 old.example`n# END CONFIG CENTRAL: managed-hosts" | Set-Content $target $lines = Get-HostsDeclaration -Path $source $content = Set-HostsBlockContent -Target $target -Name managed-hosts -Lines $lines $content | Should -Match '10.0.0.1 outside.example' $content | Should -Match '127.0.0.1 before.example' $content | Should -Not -Match 'old.example' } It 'rejects invalid hosts addresses' { $source = Join-Path $TestDrive 'bad-hosts.entries' 'not-an-address example.test' | Set-Content $source { Get-HostsDeclaration -Path $source } | Should -Throw '*Invalid hosts entry*' } It 'accepts constrained registry declarations and rejects escaping paths' { $valid = Join-Path $TestDrive 'registry.json' '{"schemaVersion":1,"values":[{"path":"Settings","name":"RememberFilePos","type":"DWord","value":1}]}' | Set-Content $valid (Read-RegistryDeclaration -Path $valid).values.Count | Should -Be 1 $invalid = Join-Path $TestDrive 'invalid-registry.json' '{"schemaVersion":1,"values":[{"path":"..\\Other","name":"Value","type":"String","value":"x"}]}' | Set-Content $invalid { Read-RegistryDeclaration -Path $invalid } | Should -Throw '*Unsafe registry subpath*' } }