Skip to content

fix(config): refuse to write a config rewrite that is not valid TOML - #4140

Merged
max-sixty merged 3 commits into
mainfrom
config-save-reparse-guard
Sep 16, 2026
Merged

max-sixty merged 3 commits into
mainfrom
config-save-reparse-guard

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

A config rewrite that breaks the TOML syntax leaves a file wt can't load: every later command skips user config with a warning, and commands that need project config fail, until the user hand-edits it. #4120 fixed one such rewrite (an inline table converted to [# comment\nmerge ]); this makes the next one fail instead of writing.

ensure_config_parses (src/config/mod.rs) parses the content before it's persisted, in both writers that rewrite a config file the user owns:

  • UserConfig::save_to checks just before write_atomically.
  • wt config update checks when it computes the migration (UpdateCandidate::new, which also replaces the two duplicated struct literals). The in-place update and --output both refuse it there, before the preview prompt.

On refusal the file on disk is unchanged. No rewrite produces invalid TOML today, so the error paths have no integration trigger; a unit test covers the check against the #4120 output shape.

🤖 Generated with Claude Code

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 3 commits September 16, 2026 10:50
A rewrite that breaks the TOML syntax leaves a config file every later command refuses to load, until the user hand-edits it. `UserConfig::save_to` and `wt config update` now parse the content they are about to write and fail with the file on disk unchanged. `wt config update` checks when it computes the migration, so the in-place update and `--output` both refuse it before the preview.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit da03501 into main Sep 16, 2026
38 checks passed
@max-sixty
max-sixty deleted the config-save-reparse-guard branch September 16, 2026 18:38
max-sixty added a commit that referenced this pull request Sep 16, 2026
Brings in #4141 (template variables migrate through MiniJinja's parser),
#4140 (refuse to write a config rewrite that is not valid TOML), #4145
(report ignored project-config keys from every worktree), #4139, #4137.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@max-sixty max-sixty mentioned this pull request Sep 16, 2026
max-sixty added a commit that referenced this pull request Sep 16, 2026
Version bump to 0.78.0 plus the changelog section for this release, a comment-preservation fix the release review turned up, a PTY test-filter fix, and merges of `main` (commits that landed during the review, including #4124, #4122, #4141, #4140 and #4145).

**Bump level**: minor. `cargo semver-checks` reports 2 breaking library changes — a new `leftover_branch` field on the `GitError::WorktreeCreationFailed` struct variant, and `DEPRECATED_TEMPLATE_VARS` removed. Pre-1.0, so a breaking change takes a minor bump.

## Comment-preservation fix

A config save — declining the commit-generation offer, say — dropped the trailing comment on every value it rewrote. That was already true in v0.77.0 for a line the save itself changed (`skip-commit-generation-prompt = false  # note` → `true`, reproduced on the v0.77.0 binary). #4080 widened it to lines the command never touched: retired template variables now migrate on every load, so the next unrelated save rewrote any line naming one. #4080's own PR said this "needs a call before merge" and merged without one.

- `replace_keeping_decor` keeps the value's decor (spacing after `=`, trailing comment) when `merge_tables` replaces a scalar. Comments *above* a line sit on the key and were never at risk.
- `main`'s #4120 independently reworked the inline-table arm and moved a key's leading comment onto the rewritten header, but documented that a trailing comment after the closing brace "is still dropped". `replace_inline_with_table` now carries it after the header's `]`, so both of its callers keep it.
- Tests: the existing comment-preservation test goes back to a retired name (the only fixture that exercises the replacement) and adds a comment on the mutated line; a new test snapshots and re-parses an inline `[projects]` entry. Each fails without its half of the fix.

Not fixed, and identical on v0.77.0: a save deletes an explicitly written *default* value (e.g. `skip-commit-generation-prompt = false  # note`) as a stale key, comment included.

## `--help` correction

#4104 moved the OpenCode plugin path to etcetera's `Xdg` strategy, which uses `$XDG_CONFIG_HOME` only when absolute — a deliberate, documented choice — but `wt config plugins opencode --help` still said install mirrors OpenCode's precedence. OpenCode reads a relative value as-is, so the help now says an empty `$OPENCODE_CONFIG_DIR` and an empty or relative `$XDG_CONFIG_HOME` are ignored.

## Data-loss surface review

Independent finders swept the full diff, including the five commits merged from `main`. Nothing holds the tag; candidates were adjudicated against v0.77.0 binaries:

- **Fixed in this release, reproduced on v0.77.0**: #4104 stops `wt config shell install` (with Nushell) deleting a `nushell/vendor/autoload/wt.nu` under the current directory when `$XDG_CONFIG_HOME` is empty or relative; #4120 stops a save or migration from writing an inline section's comment inside `[commit]` brackets, which made the config unparseable, and from dropping unknown keys.
- **`wt step prune --min-age` doesn't apply where no reflog exists** — pre-existing, proven by building the pre-#4077 binary. `git clone --bare` and `git fetch` into `refs/heads/*` write no reflog, so in the bare layout `tips-patterns.md` recommends every branch starts unprotected. Docstring corrected here; behavioral fix is follow-up.
- **`wt config update --output <path>` replaces any named file whole**, no existence check or prompt — pre-existing, follow-up.
- **`wt config shell install fish --yes` replaces a hand-written wrapper at the XDG path** — accepted ("ownership is the path", predates #3602), newly reachable only for users with `$XDG_CONFIG_HOME` set. The FAQ's delete inventory now cross-references it.
- **`--var <retired-name>` binds a name nothing references** after #4080 — inert, no shipped usage; follow-up.
- **#4135 migrates nothing**: an existing oh-my-pi hook stays put, `pi uninstall` points at `omp uninstall`. `PI_CODING_AGENT_DIR='~/x'` is used literally (Pi expands `~`) — creates a stray directory, deletes nothing; follow-up.

## Changelog

37 entries; each new or edited entry was re-verified against v0.77.0 until a pass came back clean (six passes in all). Passes caught, among others: the OpenCode `-x` recipe was wrong since 0.76.0, not 0.75.0; #4080's JSON reaches every hook, not just `pre-start`/`post-start`; a quoted git error string git never prints; a copy-button overlap that existed only inside this release; #4104's relative-`XDG_CONFIG_HOME` OpenCode change described as a fix when OpenCode reads that path as-is; and which commands a broken inline section stopped. **Fixed** leads with the data-loss entries.

## Open PRs checked against v0.77.0

- **#4124** fixed a bug new in this release, caused by #4080, and has landed and been merged in here. The hand-rolled template-variable scanner it extends is slated for removal; see its commit message.
- **#4112** — no data-loss regression vs v0.77.0; two small non-safety regressions from #4111 (an uncapped auto-staging file list, a narrow `Nothing to commit` refusal under `status.showUntrackedFiles = no`). Not merged, by decision.
- **#4122** (merged in) and **#4123** — pre-existing bugs, identical on v0.77.0.

## PTY filter fix

`test (macos)` failed once on a shell's failed-`setpgid` diagnostic that landed straight after the capture's trailing `\x1b[0m`, with no newline between, so #4136's line-anchored filter missed it. The filter now also matches right after an SGR escape and keeps the escape; its test gains that shape and fails on the old pattern.

## Validation

- `cargo run -- hook pre-merge --yes` — 4930 tests passed, 1 skipped; clippy, fmt, doc-sync, snapshot and lockfile checks green
- Nightly on the original cut-from tip (https://github.com/max-sixty/worktrunk/actions/runs/35060617020): green across `full-tests` on linux/macos/windows, `feature-powerset`, all `release-target`s, `nix-flake`, `minimal-versions`, `link-check`

> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)
max-sixty added a commit that referenced this pull request Sep 16, 2026
…nd ~ in PI_CODING_AGENT_DIR (#4151)

Two small fixes found while reviewing v0.78.0.

**A config save rewrote hook pipelines into another spelling, dropping
their comments.** A pipeline serializes in one spelling whatever the
file used: one step as its lone table, more as an inline array of
tables. So every user-config save (declining the commit-generation
offer, say) found an untouched pipeline "changed" and rewrote it:

- `[[post-start]]` blocks — the documented form — lost the comment above
them; a one-step pipeline became `[post-start]`, and a longer one
collapsed into an inline array moved to the top of the file.
- `post-start = [{ … }]` became a `[post-start]` table with the comment
above it rendered inside the brackets. Since #4140 the save refuses to
write TOML it can't read back, and prompts whose decline path ignores
the save error came back on every run.

`merge_tables` now re-spells the desired pipeline the way the file
writes it (`in_existing_spelling`) before comparing, and merges `[[…]]`
blocks block by block. An untouched pipeline stays byte-identical; a
step the load rewrote (template migration renaming `repo_root`) changes
alone, keeping its trailing comment.
`test_saving_config_mutation_keeps_each_pipeline_spelling_and_its_comments`
covers the inline array, one `[[post-switch]]` block, and two
`[[pre-start]]` blocks; it fails without the change.

**`wt config plugins pi install` ignored `~` in
`$PI_CODING_AGENT_DIR`.** Pi expands a leading `~` there (`getAgentDir`
→ `normalizePath`), so a quoted `PI_CODING_AGENT_DIR="~/x"` means a
directory under home; wt created a literal `~` directory under the cwd.
`pi_agent_dir` now uses `worktrunk::path::expand_tilde`, and
`test_pi_install_honors_agent_dir_override` covers the `~/…` case.
`omp.rs` is unchanged: oh-my-pi resolves the same variable with a plain
`path.resolve`.

> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

2 participants