From f8b4aa0937417da64c18a8220ad784d7758e7854 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 19 Oct 2026 13:46:15 +0200 Subject: [PATCH] Force web config updates by default with backups --- README.md | 6 +++--- TASKS.md | 1 + docs/advanced_commands.md | 7 ++++--- tests/UpdateConfigs.Tests.ps1 | 8 ++++++-- update-configs.ps1 | 4 ++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6333508..14e3d9b 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,9 @@ This downloads the latest configs and updater code from your saved repository branch and applies them to your saved machine profile. No menu, manual Git pull, or software installation. Temporary downloads are removed afterward. -Unchanged configs are skipped and replacements are backed up. Local edits are -reported as conflicts instead of being silently lost; see -[replacing local edits](docs/advanced_commands.md#web-config-updater). +Unchanged configs are skipped. Local settings are backed up and replaced with +the repository versions by default. To preserve local edits instead, see +[advanced update options](docs/advanced_commands.md#web-config-updater). Windows may request administrator approval for settings such as the hosts file. ## Collect settings from a computer diff --git a/TASKS.md b/TASKS.md index efc3451..87bf429 100644 --- a/TASKS.md +++ b/TASKS.md @@ -126,3 +126,4 @@ open until it is run on disposable machines with the required account setups. - [x] Rename the bundled default machine to beffroi-laptop and document switching existing setups. - [x] Use PowerShell 7-compatible ACL application for elevation requests; add Windows-only permission regression tests (Windows execution pending). - [x] Retry an upgrade with an install when WinGet reports no matching installed package, preserving scope and testing bounded retries. +- [x] Make web config updates force replacement with backups by default, with an explicit opt-out. diff --git a/docs/advanced_commands.md b/docs/advanced_commands.md index 7eaedf4..d6a4309 100644 --- a/docs/advanced_commands.md +++ b/docs/advanced_commands.md @@ -103,11 +103,12 @@ Existing state, locks, backups, and logs are reused. An administrator prompt may still be required for machine settings such as hosts. Close managed applications first so they do not overwrite deployed settings on exit. -Local changes remain conflicts. To deliberately back them up and replace them -with the online versions: +The web updater defaults to `-ForceConfigs`: local settings are backed up and +replaced with the online versions. To preserve local edits and report conflicts +instead, explicitly disable force: ```powershell -& ([scriptblock]::Create((irm 'https://proxy.dandaedre.com/gitea/Beffroi/config-central/raw/branch/main/update-configs.ps1'))) -ForceConfigs +& ([scriptblock]::Create((irm 'https://proxy.dandaedre.com/gitea/Beffroi/config-central/raw/branch/main/update-configs.ps1'))) -ForceConfigs:$false ``` A failed download makes no deployment changes. Partial deployment failures are diff --git a/tests/UpdateConfigs.Tests.ps1 b/tests/UpdateConfigs.Tests.ps1 index bd0f584..c8d3404 100644 --- a/tests/UpdateConfigs.Tests.ps1 +++ b/tests/UpdateConfigs.Tests.ps1 @@ -35,16 +35,20 @@ Describe 'Web config updater' { Invoke-ConfigUpdate -DataRoot $TestDrive $script:childArguments | Should -Contain '-ConfigsOnly' $script:childArguments | Should -Contain ('a' * 40) - $script:childArguments | Should -Not -Contain '-ForceConfigs' + $script:childArguments | Should -Contain '-ForceConfigs' @(Get-ChildItem $TestDrive -Directory -Filter 'config-central-update-*').Count | Should -Be 0 } + It 'allows explicitly preserving local edits' { + Invoke-ConfigUpdate -DataRoot $TestDrive -ForceConfigs:$false + $script:childArguments | Should -Not -Contain '-ForceConfigs' + } It 'does not apply after a failed download' { $script:gitFailure = $true { Invoke-ConfigUpdate -DataRoot $TestDrive } | Should -Throw '*download failed*' Should -Invoke pwsh.exe -Times 0 @(Get-ChildItem $TestDrive -Directory -Filter 'config-central-update-*').Count | Should -Be 0 } - It 'surfaces partial failures and forwards only an explicit force request' { + It 'surfaces partial failures while forcing config deployment' { $script:applyFailure = $true { Invoke-ConfigUpdate -DataRoot $TestDrive -ForceConfigs } | Should -Throw '*exit 5*' $script:childArguments | Should -Contain '-ForceConfigs' diff --git a/update-configs.ps1 b/update-configs.ps1 index 2194fc8..27de689 100644 --- a/update-configs.ps1 +++ b/update-configs.ps1 @@ -1,11 +1,11 @@ #requires -Version 5.1 [CmdletBinding()] param( - [switch]$ForceConfigs + [switch]$ForceConfigs = $true ) function Invoke-ConfigUpdate { - param([string]$DataRoot, [switch]$ForceConfigs) + param([string]$DataRoot, [switch]$ForceConfigs = $true) $settingsPath = Join-Path $DataRoot 'settings.json' if (-not (Test-Path -LiteralPath $settingsPath -PathType Leaf)) { throw 'Run install.ps1 once on this computer before updating configs.'