Skip to content

chore(config): write predbat_config.json one setting per line - #5422

Merged
springfall2008 merged 2 commits into
mainfrom
chore/format-config-json
Oct 12, 2026
Merged

springfall2008 merged 2 commits into
mainfrom
chore/format-config-json

Conversation

@chalfontchubby

@chalfontchubby chalfontchubby commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Opened by Claude on Rik's behalf.

Summary

predbat_config.json was written as a single line, so changing one setting showed as the whole file changing when the file is kept in git or compared between two saves. It is now written with json.dump(..., indent=2) and a trailing newline: one setting per line, in the same CONFIG_ITEMS order as before.

It is still plain JSON, so load_current_config() reads it exactly as before, and an existing single-line file still loads. The first save after upgrading rewrites it in the new layout.

Changes

  • apps/predbat/userinterface.py: save_current_config() indents the JSON and ends the file with a newline.
  • apps/predbat/tests/test_config_json_format.py (new): the saved file is exactly json.dumps(settings, indent=2) plus a newline, a setting sits on its own line, the file loads back to the same value, and every setting on the shared test fixture is restored afterwards.
  • apps/predbat/unit_test.py: registers the test.

Test plan

  • ./run_all --test config_json_format --test new_install_detection
  • ./run_all --quick
  • coverage/run_pre_commit

🤖 Generated with Claude Code

The settings file was a single line, so a change to one setting showed as the whole file changing when the file
is kept in git or compared. It is now written with json.dump(indent=2) and a trailing newline, in the same
CONFIG_ITEMS order as before. It is still plain JSON, so loading is unchanged; a test checks the layout and that
the file loads back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The formatting change is covered by regression tests and preserves compatibility.

Review effort: Lite
Findings: None

What changed in this PR

Formats predbat_config.json with readable indentation and a trailing newline while preserving loading behavior.

Changes:

  • Writes formatted JSON configuration.
  • Adds formatting and round-trip tests.
  • Registers the new test.
File Description
apps/​predbat/​userinterface.py Writes formatted configuration JSON.
apps/​predbat/​unit_test.py Registers the new test.
apps/​predbat/​tests/​test_config_json_format.py Tests formatting and loading.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…test

load_current_config() rewrites every saved CONFIG_ITEMS value on the shared PredBat fixture, but the test only
put load_scaling back. Any value that does not survive a JSON round-trip unchanged (a tuple read back as a
list, for example) would then leak into later tests, the order-dependent pollution seen in #5079. Snapshot all
values before the save and restore them in the finally block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

All reviewed changes are covered by regression tests with no unresolved issues.

0 open findings

🧠 Review effort: Lite

@springfall2008
springfall2008 merged commit 02c34d8 into main Oct 12, 2026
3 checks passed
@springfall2008
springfall2008 deleted the chore/format-config-json branch October 12, 2026 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants