Skip to content

fix: Resolve bugs with patching of tables split across dotted keys and headers - #340

Merged
DecimalTurn merged 18 commits into
latestfrom
fix-335
Nov 16, 2026
Merged

DecimalTurn merged 18 commits into
latestfrom
fix-335

Conversation

@DecimalTurn

Copy link
Copy Markdown
Owner

Closes #335

patch() could produce invalid TOML or retain deleted data when a table's path was split between dotted keys and explicit headers. Nested inline-table paths could also leave conflicting dotted keys behind.

This change:

  • Replaces header-defined sub-tables in the correct dotted-key or array-of-tables entry.
  • Removes descendant table and array-of-tables sections when their parent is deleted without affecting sibling entries.
  • Rewrites nested dotted paths inside inline tables without leaving conflicting keys or changing other array elements.
  • Extra: Keep nested sub-table replacements scoped to the selected array-of-tables entry and prevent table redefinition

Emit a scalar replacement as a dotted row in the existing explicit parent when dotted siblings already define the intermediate table. This avoids creating a conflicting child header.
When a removal path prefix-matches a dotted key inside a table, also remove document-level headers under that prefix. This prevents array-of-table children from recreating deleted data.
Resolve a prefix-matched InlineItem to its structural container, allowing replacement logic to remove sibling dotted rows before writing the collapsed key.
Record the clean seed sweep and document fuzz5 coverage boundaries.
Add targeted fuzz6 coverage for dotted keys, AOT deletions, and inline-table replacements.
Copilot AI balanced review requested due to automatic review settings November 15, 2026 04:41
@DecimalTurn DecimalTurn changed the title fix: resolve bugs with patching of tables split across dotted keys and headers fix: Resolve bugs with patching of tables split across dotted keys and headers Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Benchmark comparison

Each workload measured this branch against latest on the same runner.

Parse Benchmark Results

Time per iteration. Lower is better. Change is throughput vs. reference: + is faster, - is slower.

📖 Parse, smol-toml spec example (toml-spec-example.toml)

Library Performance Slowdown Change
🥇 smol-toml@1.9.1 (Date) 6.85 µs/iter 1x
🥈 smol-toml@1.9.1 (Temporal) 8.90 µs/iter 1.30x
🥉 @iarna/toml@3.0.0 21.40 µs/iter 3.13x
4 @decimalturn/toml-patch@3.3.2 (baseline) 30.77 µs/iter 4.49x
5 @decimalturn/toml-patch (Date, current) 30.99 µs/iter 4.53x -1%
6 @decimalturn/toml-patch (Temporal, current) 37.89 µs/iter 5.53x

📖 Parse, smol-toml 5MB mixed (5mb-mixed.toml)

Library Performance Slowdown Change
🥇 smol-toml@1.9.1 (Date) 79.01 ms/iter 1x
🥈 smol-toml@1.9.1 (Temporal) 144.20 ms/iter 1.82x
🥉 @decimalturn/toml-patch@3.3.2 (baseline) 314.10 ms/iter 3.98x
4 @decimalturn/toml-patch (Date, current) 323.29 ms/iter 4.09x -3%
5 @decimalturn/toml-patch (Temporal, current) 455.68 ms/iter 5.77x
- @iarna/toml@3.0.0 DNF DNF

📖 Parse, iarna spec example v0.4.0 (0A-spec-01-example-v0.4.0.toml)

Library Performance Slowdown Change
🥇 smol-toml@1.9.1 (Temporal) 42.35 µs/iter 1x
🥈 smol-toml@1.9.1 (Date) 43.00 µs/iter 1.02x
🥉 @iarna/toml@3.0.0 134.82 µs/iter 3.18x
4 @decimalturn/toml-patch (Date, current) 181.25 µs/iter 4.28x 0%
5 @decimalturn/toml-patch@3.3.2 (baseline) 181.26 µs/iter 4.28x
6 @decimalturn/toml-patch (Temporal, current) 206.04 µs/iter 4.87x

Stringify Benchmark Results

Time per iteration. Lower is better. Change is throughput vs. reference: + is faster, - is slower.

✍️ Stringify, smol-toml spec example (toml-spec-example.toml)

Library Performance Slowdown Change
🥇 smol-toml@1.9.1 7.69 µs/iter 1x
🥈 @iarna/toml@3.0.0 24.74 µs/iter 3.22x
🥉 @decimalturn/toml-patch@3.3.2 (baseline) 139.47 µs/iter 18.15x
4 @decimalturn/toml-patch (current) 157.29 µs/iter 20.47x -11%

✍️ Stringify, smol-toml 5MB mixed (5mb-mixed.toml)

Library Performance Slowdown Change
🥇 smol-toml@1.9.1 102.75 ms/iter 1x
🥈 @iarna/toml@3.0.0 305.17 ms/iter 2.97x
🥉 @decimalturn/toml-patch@3.3.2 (baseline) 915.87 ms/iter 8.91x
4 @decimalturn/toml-patch (current) 1024.14 ms/iter 9.97x -11%

✍️ Stringify, iarna spec example v0.4.0 (0A-spec-01-example-v0.4.0.toml)

Library Performance Slowdown Change
🥇 smol-toml@1.9.1 32.74 µs/iter 1x
🥈 @iarna/toml@3.0.0 139.15 µs/iter 4.25x
🥉 @decimalturn/toml-patch@3.3.2 (baseline) 593.15 µs/iter 18.12x
4 @decimalturn/toml-patch (current) 677.41 µs/iter 20.69x -12%

🧩 Patch benchmarks

Full and lite patching are compared with smol-toml. The smol-toml method parses the document, updates the object, and stringifies it. Timings include each implementation’s complete operation; fixture creation and correctness checks are outside the timed section.

Current and base-branch full and lite patch builds are compared in the same run.

Edit existing scalar values

Change several existing root and nested scalar values.

🧩 Edit existing scalar values, representative-document

Library Performance Slowdown Change
🥇 smol-toml@1.9.1 6.89 µs/iter 1x
🥈 @decimalturn/toml-patch@3.3.2 (lite, baseline) 115.64 µs/iter 16.78x
🥉 @decimalturn/toml-patch (lite, current) 142.38 µs/iter 20.66x -19%
4 @decimalturn/toml-patch@3.3.2 (full, baseline) 268.29 µs/iter 38.92x
5 @decimalturn/toml-patch (full, current) 325.20 µs/iter 47.18x -18%

Edit an unrelated scalar with many top-level AOT scopes

Change one root value while each named AOT owns a nested subtable.

🧩 Edit an unrelated scalar with many top-level AOT scopes, aot-scopes-64

Library Performance Slowdown Change
🥇 smol-toml@1.9.1 162.01 µs/iter 1x
🥈 @decimalturn/toml-patch@3.3.2 (lite, baseline) 1.69 ms/iter 10.43x
🥉 @decimalturn/toml-patch (lite, current) 1.78 ms/iter 10.97x -5%
4 @decimalturn/toml-patch (full, current) 5.65 ms/iter 34.90x +113%
5 @decimalturn/toml-patch@3.3.2 (full, baseline) 12.03 ms/iter 74.26x

🧩 Edit an unrelated scalar with many top-level AOT scopes, aot-scopes-256

Library Performance Slowdown Change
🥇 smol-toml@1.9.1 666.47 µs/iter 1x
🥈 @decimalturn/toml-patch (lite, current) 6.94 ms/iter 10.42x +95%
🥉 @decimalturn/toml-patch@3.3.2 (lite, baseline) 13.51 ms/iter 20.27x
4 @decimalturn/toml-patch@3.3.2 (full, baseline) 20.49 ms/iter 30.74x
5 @decimalturn/toml-patch (full, current) 26.37 ms/iter 39.57x -22%

🧩 Edit an unrelated scalar with many top-level AOT scopes, aot-scopes-1024

Library Performance Slowdown Change
🥇 smol-toml@1.9.1 2.98 ms/iter 1x
🥈 @decimalturn/toml-patch (lite, current) 27.30 ms/iter 9.17x +13%
🥉 @decimalturn/toml-patch@3.3.2 (lite, baseline) 30.83 ms/iter 10.36x
4 @decimalturn/toml-patch@3.3.2 (full, baseline) 141.94 ms/iter 47.69x
5 @decimalturn/toml-patch (full, current) 161.09 ms/iter 54.12x -12%

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The fuzz test can place a root-intended inline assignment inside an array-of-tables entry, causing multi-mutation runs to throw before exercising the intended edits.

1 open issue
What changed in this PR

This PR addresses #335 by improving patch() handling of tables split across dotted keys and headers, aiming to preserve valid TOML and match the updated object.

Changes:

  • Fixes structural replacements and descendant deletion while keeping changes scoped to the selected array-of-tables entry.
  • Adds regression tests and a targeted structural fuzzer.
  • Adds fuzz-runner progress reporting and updates supporting documentation.
File Description
src/​patch.ts Corrects replacement containers, scoped header cleanup, and dotted-path handling.
src/​__tests__/​patch.test.ts Adds regressions for split tables, entry isolation, and out-of-order headers.
src/​__tests__/​fuzz6.test.ts Checks scenario rotation and three targeted round trips.
src/​__tests__/​fuzz-patch6.ts Generates targeted structural replacement and deletion scenarios.
scripts/​report-dependents.mjs Updates comments explaining how to refresh saved dependents HTML.
scripts/​fuzz-run6.ts Adds a runner for targeted structural fuzzing.
scripts/​fuzz-run5.ts Adds optional progress reporting.
package.json Registers the fuzz6 command.
docs/​Fuzz-Testing.md Documents variant 6, coverage boundaries, and sweep results.
CHANGELOG.md Records the patching fixes under Unreleased.

Review effort: Balanced

Comment thread src/__tests__/fuzz-patch6.ts Resolved
Emit root inline-table cases before section headers so multi-mutation seeds retain their document scope.
@DecimalTurn
DecimalTurn marked this pull request as ready for review November 16, 2026 01:20
@DecimalTurn
DecimalTurn merged commit f619097 into latest Nov 16, 2026
44 of 45 checks passed
@DecimalTurn
DecimalTurn deleted the fix-335 branch November 16, 2026 07:29
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.

patch(): invalid TOML or kept data when replacing/deleting tables split across headers and dotted keys

2 participants