Skip to content

Comments

Sync dev to main#128

Closed
tis24dev wants to merge 2 commits intomainfrom
dev
Closed

Sync dev to main#128
tis24dev wants to merge 2 commits intomainfrom
dev

Conversation

@tis24dev
Copy link
Owner

@tis24dev tis24dev commented Feb 2, 2026

Introduce a machine-readable config-upgrade mode (--upgrade-config-json) and wire automatic configuration upgrades into the binary upgrade flow. The upgrade command now attempts to run the newly installed binary to merge template changes into backup.env (adding missing keys while preserving existing values).

Implemented robust parsing and rendering for multi-line (block) env values, refactored value parsing into helpers (parseEnvValues, splitKeyValueRaw, renderEnvValue, findClosingQuoteLine) and updated computeConfigUpgrade to preserve block entries and multiple values per key. Added tests covering block preservation and missing-block detection.

printUpgradeFooter now reports detailed config-upgrade results or errors, and installer/help text was updated to reflect the behavior change. Error handling for the JSON mode and subprocess invocation was added to ensure clear diagnostics.

Introduce a machine-readable config-upgrade mode (--upgrade-config-json) and wire automatic configuration upgrades into the binary upgrade flow. The upgrade command now attempts to run the newly installed binary to merge template changes into backup.env (adding missing keys while preserving existing values).

Implemented robust parsing and rendering for multi-line (block) env values, refactored value parsing into helpers (parseEnvValues, splitKeyValueRaw, renderEnvValue, findClosingQuoteLine) and updated computeConfigUpgrade to preserve block entries and multiple values per key. Added tests covering block preservation and missing-block detection.

printUpgradeFooter now reports detailed config-upgrade results or errors, and installer/help text was updated to reflect the behavior change. Error handling for the JSON mode and subprocess invocation was added to ensure clear diagnostics.
Copilot AI review requested due to automatic review settings February 2, 2026 23:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces automated configuration upgrades during binary upgrades by adding a --upgrade-config-json flag and integrating it into the upgrade workflow. The upgrade command now automatically merges template changes into backup.env by adding missing keys while preserving existing values.

Changes:

  • Added --upgrade-config-json flag for machine-readable config upgrade output
  • Implemented robust parsing and rendering for multi-line (block) environment values
  • Integrated automatic config upgrade into binary upgrade flow
  • Updated help text and installer messages to reflect new upgrade behavior

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/config/upgrade_test.go Added tests for block value preservation and missing block key detection
internal/config/upgrade.go Refactored value parsing with helpers to support block values and multiple values per key
internal/cli/args.go Added UpgradeConfigJSON flag and updated upgrade description
cmd/proxsave/upgrade.go Integrated config upgrade subprocess call and enhanced upgrade footer reporting
cmd/proxsave/main.go Added JSON mode handler and updated incompatibility checks and help text
cmd/proxsave/install.go Updated help text to reflect new upgrade behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 193 to 194
if !strings.Contains(content, "CUSTOM_BACKUP_PATHS=\"\n/etc/custom.conf\n\"\n") &&
!strings.Contains(content, "CUSTOM_BACKUP_PATHS=\"\r\n/etc/custom.conf\r\n\"\r\n") {
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test checks for both Unix and Windows line endings, but the logic could be clearer. Consider extracting the line ending normalization into a test helper function to avoid repeating this pattern.

Copilot uses AI. Check for mistakes.
userValues[key] = append(userValues[key], value)
userValues, userKeyOrder, err := parseEnvValues(originalLines)
if err != nil {
return result, "", originalContent, err
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error returned from parseEnvValues is passed through without additional context. Consider wrapping it with context about which config file failed to parse, e.g., fmt.Errorf(\"failed to parse config %s: %w\", configPath, err).

Suggested change
return result, "", originalContent, err
return result, "", originalContent, fmt.Errorf("failed to parse config %s: %w", configPath, err)

Copilot uses AI. Check for mistakes.
blockLines := make([]string, 0)
blockEnd, err := findClosingQuoteLine(lines, i+1)
if err != nil {
return nil, nil, fmt.Errorf("unterminated multi-line value for %s", key)
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message could be more helpful by indicating the approximate line number where the unterminated block was detected, which would help users locate the issue in large config files.

Suggested change
return nil, nil, fmt.Errorf("unterminated multi-line value for %s", key)
return nil, nil, fmt.Errorf("unterminated multi-line value for %s starting at line %d", key, i+1)

Copilot uses AI. Check for mistakes.
Comment on lines 651 to 652
if len(preview) > 4000 {
preview = preview[:4000] + "…"
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 4000 for truncating preview output should be extracted as a named constant (e.g., maxPreviewLength) to make the code more maintainable and self-documenting.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 80.51948% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/config/upgrade.go 79.72% 8 Missing and 7 partials ⚠️

📢 Thoughts on this report? Let us know!

Make the upgrade UX and diagnostics clearer: update the interactive prompt to inform users a backup will be created and backup.env may be updated; extract maxUpgradeConfigJSONPreviewLength constant and use it when truncating invalid JSON preview. Improve error messages to include the config path when parsing fails and the starting line number for unterminated multi-line values. Update tests to normalize CRLF vs LF so assertions are deterministic across platforms.
@tis24dev tis24dev closed this Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant