Skip to content

fix: Adjust commented out kv behavior to match expected behavior of comment ownership rules - #277

Merged
DecimalTurn merged 11 commits into
latestfrom
dev-fix-commented-kv
Aug 9, 2026
Merged

fix: Adjust commented out kv behavior to match expected behavior of comment ownership rules#277
DecimalTurn merged 11 commits into
latestfrom
dev-fix-commented-kv

Conversation

@DecimalTurn

Copy link
Copy Markdown
Owner

No description provided.

…live

When a pending comment run before a KV contains dead entries
(commented-out KVs like `# a = 1`) mixed with alive prose, but the
LAST comment is alive, only the suffix after the last dead entry is
assigned to the KV. The dead entries and anything before them are
pinned. If the run ends with a dead entry, the whole run still belongs
to the KV (one prose line defeats R6).
…elow

A commented-out KV (like `# a = 1`) now acts as a barrier in a pending
comment run: only comments after the LAST dead entry whose key differs
from the following KV are assigned to that KV. Dead entries whose key
matches the KV stay in the run (they are related, e.g. `# b = 8080`
above `b = 2`).

Added commentedOutFirstKey() to extract the first key segment from a
commented-out entry for comparison with the KV key from getMemberKey().
Replace the single IS_COMMENTED_OUT_KEY_VALUE regex (which matched any
`# key =` prefix) with two distinct patterns:

- IS_PURE_COMMENTED_OUT_KV: full-line match requiring a single value token
  after `=`, rejecting multi-word prose like `# key = 1 is something...`
- looksLikeKV(): used for barrier detection, also matches lines with an
  inline comment after the value (`# key = val # note`), which still sever
  ownership even though they are not pure dead entries.

The barrier loop in scanSlots now uses looksLikeKV() instead of the old
isCommentedOutEntry() to correctly handle inline-commented KVs while
ignoring prose sentences that happen to contain `=`.
Previously when every comment in a pending run was a dead entry (R6),
the entire run was unconditionally pinned. Now the barrier logic also
runs for all-dead runs: dead entries whose key matches the KV stay in
the run and are removed with the KV, while dead entries with different
keys are still pinned.

Added edge-case tests for quoted values, booleans, dotted keys, inline
comments with matching/non-matching keys.
Replaced the inline-comment-only heuristic in looksLikeKV() with a
combined approach: a comment acts as a barrier when it matches the
lenient KV regex AND either has an inline `#` comment after the value,
or has ≤3 words after `=`. This correctly handles short multi-word
values like `# "x key" = old value` (2 words → barrier) while still
rejecting obvious prose like `# key = 1 is something to consider`
(5 words → not a barrier).

Added tests for quoted-key deletion with matching and non-matching
commented-out KVs.
Copilot AI lite review requested due to automatic review settings August 9, 2026 06:18
@DecimalTurn DecimalTurn changed the title fix: adjust commented out kv behavior to match expected behavior of comment ownership rules fix: Adjust commented out kv behavior to match expected behavior of comment ownership rules Aug 9, 2026

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.

Pull request overview

Adjusts how “commented-out key/value” lines are detected and how they affect comment ownership, so dead entries don’t incorrectly get treated as prose (or vice versa) when determining which comments are owned/preserved during patching.

Changes:

  • Tightens commented-out KV detection to require a single-token value (treating multi-word # key = ... prose as “alive” comments).
  • Updates slot-scanning ownership logic so commented-out KVs can act as barriers based on key mismatch, including support for inline trailing comments and short values.
  • Expands/updates test coverage for the revised comment ownership semantics.

Reviewed changes

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

File Description
src/comment-ownership.ts Refines regex-based detection of commented-out KVs and updates ownership barrier logic in scanSlots.
src/tests/patch.test.ts Converts a previously failing test to passing and adds multiple new cases around commented-out KV ownership/barrier behavior.
src/tests/comment-ownership.test.ts Updates expected behavior for an R2 adjacency case involving a commented-out KV with a differing key.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/comment-ownership.ts Outdated
Comment thread src/comment-ownership.ts Outdated
…*=.*#/

The broad pattern /#.*=.*#/ would match a # inside a quoted value
(e.g. `# k = "a # b" extra`), incorrectly classifying the line as a
barrier. Use a regex that requires the full KV pattern followed by
a single value token and then a # inline comment marker.
The regex for detecting inline comments (`# key = val # note`) used
VALUE_TOKEN which backtracks from a quoted string to [^\s#]+, causing
`# k = "a # b" extra` to match `"a` as the value and ` #` as the
inline comment start. Replaced with hasInlineCommentAfterValue() which
walks characters after `=`, tracking quote state, and only counts a `#`
as an inline comment when outside both single and double quotes.

Added a test that would have failed with the old regex.
@DecimalTurn
DecimalTurn merged commit 11f0cf6 into latest Aug 9, 2026
15 checks passed
@DecimalTurn
DecimalTurn deleted the dev-fix-commented-kv branch August 9, 2026 06:37
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