Skip to content

fix(config): migrate by editing the text, so it stops deleting every comment - #515

Merged
sandstream merged 1 commit into
mainfrom
fix/513-migrate-keeps-comments
Aug 21, 2026
Merged

sandstream merged 1 commit into
mainfrom
fix/513-migrate-keeps-comments

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Closes #513.

Measured, on kit's own config

The v0 → v1 step's entire job is to stamp version = 1:

$ kit config migrate --dry-run
Changes:
  + version = 1                    ← the whole preview

$ kit config migrate && git diff --stat .kit.toml
 .kit.toml | 36 ++++++++++++++++++++----------------

comment lines before: 8      after: 0

The parsed data was identical apart from version, so the backup-and-re-validate safety path passed and nothing flagged the loss. What went with it was policy reasoning — why those scanners are declared, why the refs are aqua:-scheme-qualified (bare names are untriageable and the gate blocks them), where the scanner tokens resolve from, and an inline comment documenting the accepted values of environment.

The fix

Add-only migrations are applied as a text edit. The key is inserted above the first table — top-level keys must precede it, or TOML scopes them into that table — and everything else is left byte-for-byte:

$ cat .kit.toml            # after `kit config migrate`
# why these tools matter
# and a second line

version = 1

[tools]
node = "22"   # inline note

Anything more structural refuses rather than guesses. patchConfigText returns null for a changed value, a removal, or a nested addition, because a line insert cannot express those. The caller then falls back to serialising — and while comments exist, that is refused:

this migration cannot be applied as a text edit, and re-serialising would delete 8 comment line(s) from .kit.toml. Re-run with --allow-comment-loss to accept that (the original is kept at .kit.toml.backup), or apply the change by hand.

The dry run says which path it would take, since that was the sharper half of the defect: a preview showing a one-line change before a thirty-six-line rewrite is worse than no preview.

Would migrate v0 -> v1 (1 step(s)). Nothing written (--dry-run).
Applied as a text edit: comments and formatting are preserved.

Tests

src/config-migrate-text.test.ts — 7:

  • the insert lands above the first table, every original line survives, the comment count is unchanged, and the parsed result carries the intended value
  • a file with no table at all appends instead
  • patchConfigText returns null for a changed value, a removal, a nested addition, and an empty diff — so a future migration cannot be silently mis-applied by a text edit
  • countCommentLines counts full-line and inline comments
  • compiled CLI: the v0 → v1 stamp keeps every comment; --dry-run states the path and writes nothing; --check still exits 1 on a stale config without touching the file

Verification

  • npm test: 4446 tests, 0 fail, 0 skipped (macOS, non-root)
  • kit self-audit: 16 rules, 0 fail, 0 warn · eslint src: 0 errors · prettier --check clean
  • Flag surface regenerated (--allow-comment-loss), and the flag is documented in docs/COMMANDS.md — flags are not caught by the undocumented commands rule, so that one is discipline

🤖 Generated with Claude Code

…comment

`kit config migrate` re-serialised .kit.toml from the parsed object, so every
comment in the file was deleted. Measured on kit's own config, on the v0 -> v1
step whose entire job is to stamp `version = 1`: 8 comment lines became 0, and a
one-line change produced a 36-line diff. The parsed data was identical, so the
backup-and-re-validate path passed and flagged nothing — and neither did the dry
run, which previewed `+ version = 1` and said nothing about the rewrite.

What was lost was policy reasoning: why those scanners are declared, why the refs
are aqua:-scheme-qualified (bare names are untriageable and the gate blocks them),
where the scanner tokens resolve from, and an inline comment documenting the
accepted values of `environment`. .kit.toml is where a repo declares its policy,
and kit's argument is that policy should be reviewable.

An add-only migration is now applied as a TEXT EDIT: the key is inserted above
the first table (top-level keys must precede it, or TOML scopes them into that
table) and the rest of the file is untouched. patchConfigText returns null for
anything more structural — a changed value, a removal, a nested addition — rather
than being forced through an edit that cannot express it; the run then refuses
while comments exist unless --allow-comment-loss is passed, naming how many lines
are at stake.

--dry-run now says which path it would take: "Applied as a text edit: comments and
formatting are preserved", or the count that would be deleted. A preview that
omits the destructive half of a change is worse than no preview.

Closes #513

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit 4593bfe into main Aug 21, 2026
19 checks passed
@sandstream
sandstream deleted the fix/513-migrate-keeps-comments branch August 21, 2026 11:33
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.

kit config migrate deletes every comment in .kit.toml, and the dry run does not say so

1 participant