diff --git a/scripts/lib/manifest.ps1 b/scripts/lib/manifest.ps1 index 78b7bf2..6bf7d23 100644 --- a/scripts/lib/manifest.ps1 +++ b/scripts/lib/manifest.ps1 @@ -86,6 +86,17 @@ function Sync-ManagedDestination { if ($relative -eq 'config.toml' -and (Test-Path -LiteralPath $target)) { $localConfig = [System.IO.File]::ReadAllText($target) $pluginTables = [regex]::Matches($localConfig, '(?m)^[ \t]*\[(?:plugins|marketplaces)(?:\.|\])[\s\S]*?(?=^[ \t]*\[|\z)') + $rootConfig = [regex]::Split($localConfig, '(?m)^[ \t]*\[', 2)[0] + $localSettings = [regex]::Matches($rootConfig, '(?m)^[ \t]*(?:model|reasoning_effort)[ \t]*=.*$') + if ($localSettings.Count -gt 0) { + $content = [System.Text.Encoding]::UTF8.GetString($newBytes).TrimEnd([char[]]"`r`n") + foreach ($setting in $localSettings) { + $name = ([regex]::Match($setting.Value, '^[ \t]*([^ \t=]+)')).Groups[1].Value + $content = [regex]::Replace($content, "(?m)^[ \t]*$([regex]::Escape($name))[ \t]*=.*(?:\r?\n|$)", '') + } + $preservedSettings = ($localSettings | ForEach-Object { $_.Value.TrimEnd([char[]]"`r`n") }) -join "`n" + $newBytes = [System.Text.Encoding]::UTF8.GetBytes("$content`n$preservedSettings`n") + } if ($pluginTables.Count -gt 0) { $content = [System.Text.Encoding]::UTF8.GetString($newBytes).TrimEnd([char[]]"`r`n") if ($content -match '(?m)^[ \t]*\[(?:plugins|marketplaces)(?:\.|\])') { diff --git a/scripts/lib/manifest.sh b/scripts/lib/manifest.sh index 458cec5..ca395cf 100755 --- a/scripts/lib/manifest.sh +++ b/scripts/lib/manifest.sh @@ -84,7 +84,21 @@ sync_managed_destination() { new_hash=$(sha256_of_file "$source_file") fi if [ "$relative" = config.toml ] && [ -f "$target" ]; then - local plugin_tables + local plugin_tables local_settings setting_name + local_settings=$(awk ' + /^[ \t]*\[/ { exit } + /^[ \t]*(model|reasoning_effort)[ \t]*=/ { print } + ' "$target") + if [ -n "$local_settings" ]; then + while IFS= read -r setting; do + setting_name=${setting%%=*} + setting_name=${setting_name//[[:space:]]/} + content=$(printf '%s\n' "$content" | sed "/^[[:space:]]*$setting_name[[:space:]]*=/d") + done <<< "$local_settings" + content="$content"$'\n'"$local_settings"$'\n' + needs_sub=true + new_hash=$(sha256_of_string "$content") + fi plugin_tables=$(awk ' /^[ \t]*\[/ { preserve = ($0 ~ /^[ \t]*\[(plugins|marketplaces)(\.|\])/) } preserve { print } diff --git a/scripts/test-managed-install.ps1 b/scripts/test-managed-install.ps1 index 1712805..0c4dd79 100644 --- a/scripts/test-managed-install.ps1 +++ b/scripts/test-managed-install.ps1 @@ -54,15 +54,15 @@ try { [plugins."disabled@market"] enabled = false '@ - [System.IO.File]::WriteAllText((Join-Path $source 'config.toml'), "model = 'new'`n") - [System.IO.File]::WriteAllText($configPath, "model = 'old'`n$pluginState`n[other]`nvalue = true`n") + [System.IO.File]::WriteAllText((Join-Path $source 'config.toml'), "model = 'new'`nreasoning_effort = 'low'`n") + [System.IO.File]::WriteAllText($configPath, "model = 'old'`nreasoning_effort = 'high'`n$pluginState`n[other]`nvalue = true`n") $originalConfig = [System.IO.File]::ReadAllText($configPath) $null = Sync-ManagedDestination -Source $source -Destination $destination -Stamp 'plugins-dry' -DryRun if ([System.IO.File]::ReadAllText($configPath) -ne $originalConfig) { throw 'Dry run must preserve plugin configuration.' } $null = Sync-ManagedDestination -Source $source -Destination $destination -Stamp 'plugins' $mergedConfig = [System.IO.File]::ReadAllText($configPath) - if (-not $mergedConfig.Contains($pluginState)) { throw 'Updating config.toml must preserve local marketplace and plugin tables, including disabled plugins.' } - if (-not $mergedConfig.Contains("model = 'new'") -or $mergedConfig.Contains('[other]')) { throw 'Managed configuration must still be updated.' } + if (-not ($mergedConfig -replace "`r`n", "`n").Contains(($pluginState -replace "`r`n", "`n"))) { throw 'Updating config.toml must preserve local marketplace and plugin tables, including disabled plugins.' } + if (-not $mergedConfig.Contains("model = 'old'") -or -not $mergedConfig.Contains("reasoning_effort = 'high'") -or $mergedConfig.Contains("model = 'new'") -or $mergedConfig.Contains("reasoning_effort = 'low'") -or $mergedConfig.Contains('[other]')) { throw 'Updating config.toml must preserve local model and reasoning effort while updating managed configuration.' } if ([System.IO.File]::ReadAllText((Join-Path $destination 'backups/plugins/config.toml')) -ne $originalConfig) { throw 'Original plugin configuration must be backed up.' } $null = Sync-ManagedDestination -Source $source -Destination $destination -Stamp 'plugins-repeat' if ([System.IO.File]::ReadAllText($configPath) -ne $mergedConfig -or (Test-Path (Join-Path $destination 'backups/plugins-repeat'))) { throw 'Preserving plugin configuration must be idempotent.' } diff --git a/scripts/test-managed-install.sh b/scripts/test-managed-install.sh index 8aea35e..a3bcbd1 100755 --- a/scripts/test-managed-install.sh +++ b/scripts/test-managed-install.sh @@ -58,15 +58,17 @@ plugin_state=' [marketplaces.ponytail] enabled = true [plugins."disabled@market"] enabled = false' -printf "model = 'new'\n" > "$source_dir/config.toml" -printf "model = 'old'\n%s\n[other]\nvalue = true\n" "$plugin_state" > "$destination/config.toml" +printf "model = 'new'\nreasoning_effort = 'low'\n" > "$source_dir/config.toml" +printf "model = 'old'\nreasoning_effort = 'high'\n%s\n[other]\nvalue = true\n" "$plugin_state" > "$destination/config.toml" original_config=$(cat "$destination/config.toml") sync_managed_destination "$source_dir" "$destination" plugins-dry "" "" "" true > /dev/null [ "$(cat "$destination/config.toml")" = "$original_config" ] || { printf 'Dry run changed plugin configuration.\n' >&2; exit 1; } sync_managed_destination "$source_dir" "$destination" plugins "" "" "" false > /dev/null merged_config=$(cat "$destination/config.toml") -[[ "$merged_config" == *"$plugin_state"* ]] || { printf 'Updating config.toml must preserve local marketplace and plugin tables, including disabled plugins.\n' >&2; exit 1; } -[[ "$merged_config" == *"model = 'new'"* && "$merged_config" != *'[other]'* ]] || { printf 'Managed configuration must still be updated.\n' >&2; exit 1; } +merged_config_normalized=${merged_config//$'\r'/} +plugin_state_normalized=${plugin_state//$'\r'/} +[[ "$merged_config_normalized" == *"$plugin_state_normalized"* ]] || { printf 'Updating config.toml must preserve local marketplace and plugin tables, including disabled plugins.\n' >&2; exit 1; } +[[ "$merged_config" == *"model = 'old'"* && "$merged_config" == *"reasoning_effort = 'high'"* && "$merged_config" != *"model = 'new'"* && "$merged_config" != *"reasoning_effort = 'low'"* && "$merged_config" != *'[other]'* ]] || { printf 'Updating config.toml must preserve local model and reasoning effort while updating managed configuration.\n' >&2; exit 1; } [ "$(cat "$destination/backups/plugins/config.toml")" = "$original_config" ] || { printf 'Original plugin configuration must be backed up.\n' >&2; exit 1; } sync_managed_destination "$source_dir" "$destination" plugins-repeat "" "" "" false > /dev/null [ "$(cat "$destination/config.toml")" = "$merged_config" ] && [ ! -d "$destination/backups/plugins-repeat" ] || { printf 'Preserving plugin configuration must be idempotent.\n' >&2; exit 1; }