Skip to content

fix(config): make migrate-config --in-place idempotent#3110

Merged
bug-ops merged 1 commit intomainfrom
3095-migrate-config-in-place
Apr 17, 2026
Merged

fix(config): make migrate-config --in-place idempotent#3110
bug-ops merged 1 commit intomainfrom
3095-migrate-config-in-place

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Apr 17, 2026

Summary

  • Replace toml_edit::contains_key() idempotency guards with toml_src.contains() raw-string checks in all affected migration functions — the old approach silently failed because TOML comments are invisible to the parser
  • Replace append_comment_to_table_suffix / toml_edit decor manipulation with format!("{raw}{comment}") direct string appends to fix the decor round-trip bug (trailing comments re-attributed to next section's prefix on re-parse)
  • Add insert_after_section() helper so migrate_otel_filter comment is inserted within [telemetry] rather than at end of file
  • Add 8 idempotency tests covering all fixed migration functions

Test plan

  • cargo nextest run -p zeph-config --lib — 262/262 pass
  • Run migration twice on a minimal config, confirm second run reports "0 entries added" and file is unchanged
  • Confirm no section-header comment fusion ([agent]# ...) on second run

Fixes #3095

@github-actions github-actions Bot added rust Rust code changes bug Something isn't working size/L Large PR (201-500 lines) labels Apr 17, 2026
Replace toml_edit::contains_key() idempotency guards with raw-string
toml_src.contains() checks in all affected migration functions. The
contains_key approach silently failed because commented-out entries are
invisible to the TOML parser — the guard always passed on second run,
causing duplicated section-header comments and duplicated commented keys.

Replace append_comment_to_table_suffix / toml_edit decor manipulation
with format!("{raw}{comment}") direct string appends to avoid the decor
round-trip bug where toml_edit attributes trailing comments to the next
section's prefix on re-parse.

Add insert_after_section() helper for migrate_otel_filter so its comment
is inserted within [telemetry] rather than appended to end of file.

Add 8 idempotency tests covering all fixed migration functions; second
run now reports 0 entries added and leaves the file unchanged.

Fixes #3095
@bug-ops bug-ops force-pushed the 3095-migrate-config-in-place branch from e29aaf2 to 441f205 Compare April 17, 2026 15:19
@bug-ops bug-ops enabled auto-merge (squash) April 17, 2026 15:19
@bug-ops bug-ops merged commit fa238c0 into main Apr 17, 2026
32 checks passed
@bug-ops bug-ops deleted the 3095-migrate-config-in-place branch April 17, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rust Rust code changes size/L Large PR (201-500 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate-config --in-place not idempotent: second run duplicates section headers and keys

1 participant