Skip to content

fix: ensure root KV are properly inserted at the top of the document#171

Merged
DecimalTurn merged 10 commits into
latestfrom
dev-rkv
Apr 29, 2026
Merged

fix: ensure root KV are properly inserted at the top of the document#171
DecimalTurn merged 10 commits into
latestfrom
dev-rkv

Conversation

@DecimalTurn
Copy link
Copy Markdown
Owner

@DecimalTurn DecimalTurn commented Apr 27, 2026

Fixes #170

Copy link
Copy Markdown

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

Fixes incorrect placement of newly-added root-level key/value pairs so they’re inserted into TOML’s implicit root table (before the first [table] / [[array-of-tables]] header), addressing issue #170.

Changes:

  • Clamp insertion index for new root-level KeyValue nodes to the end of the implicit root table scope (before the first table/AoT header).
  • Adjust writer line-offset logic when prepending into a non-empty document to correctly shift existing content down.
  • Add regression tests for root key/value placement relative to tables and AoT sections.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/writer.ts Adds special-case handling for inserting at the start of a non-empty document so existing nodes are shifted correctly.
src/patch.ts Ensures root-level key/values are inserted before the first explicit table/AoT section rather than appended at the document end.
src/__tests__/patch.test.ts Adds coverage for root key/value placement before sections/AoTs (and includes one currently skipped inline-table scenario).

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

Comment thread src/__tests__/patch.test.ts Outdated
Comment thread src/__tests__/patch.test.ts Outdated
@DecimalTurn DecimalTurn marked this pull request as ready for review April 29, 2026 18:09
@DecimalTurn DecimalTurn merged commit 7c16fc6 into latest Apr 29, 2026
5 checks passed
@DecimalTurn DecimalTurn deleted the dev-rkv branch April 29, 2026 23:41
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.

New key-value insertions at root are added at the end of the document instead of the top (the implicit root table)

2 participants