BeforeAll { Import-Module "$PSScriptRoot/../src/State.psm1" -Force Import-Module "$PSScriptRoot/../src/Repository.psm1" -Force } Describe 'Repository synchronization' { It 'rejects unsafe branch names before fetching' { { Resolve-RemoteRevision -RepositoryRoot $TestDrive -Settings @{ branch = '../main' } } | Should -Throw '*Unsafe branch*' } It 'refuses a dirty checkout' { InModuleScope Repository -Parameters @{ Working = $TestDrive } { Mock Test-RepositoryDirty { $true } { Resolve-RemoteRevision -RepositoryRoot $Working -Settings @{ branch = 'main' } } | Should -Throw '*local changes*' } } It 'reports fetch failures with recovery guidance' { InModuleScope Repository -Parameters @{ Working = $TestDrive } { Mock Test-RepositoryDirty { $false } Mock Invoke-Git { throw 'credential rejected' } { Resolve-RemoteRevision -RepositoryRoot $Working -Settings @{ branch = 'main' } } | Should -Throw '*network access and Git credentials*' } } It 'stages the selected commit without changing the checkout' -Skip:(-not $IsWindows) { $repo = Join-Path $TestDrive 'repo' New-Item -ItemType Directory $repo | Out-Null & git.exe -C $repo init | Out-Null & git.exe -C $repo config user.email 'test@example.invalid' & git.exe -C $repo config user.name 'Config Central Test' 'first' | Set-Content "$repo/cc.ps1" & git.exe -C $repo add cc.ps1 & git.exe -C $repo commit -m first | Out-Null $revision = (& git.exe -C $repo rev-parse HEAD).Trim() $paths = Get-ConfigCentralPaths -DataRoot (Join-Path $TestDrive 'data') Initialize-ConfigCentralData $paths $snapshot = New-RepositorySnapshot -RepositoryRoot $repo -Revision $revision -Paths $paths (Get-Content "$snapshot/cc.ps1" -Raw).Trim() | Should -Be 'first' (& git.exe -C $repo status --porcelain) | Should -BeNullOrEmpty } }