Skip to content

fix(code-metrics): yaml_subset quote mid-value and duplicate-key line - #8036

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-6699-39098692440-1
Oct 18, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-6699-39098692440-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #6699

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Both bugs reproduced against yaml_subset.py with failing tests, then fixed. A quote now opens a quoted string only where a value starts, and a duplicate key in a sequence-item mapping is reported on its own line.

Not verified

  • The fragment was written by hand because new-changelog-fragment needs a branch and HEAD was detached; check-changelog-fragments accepts it
  • A quote after a comma in a flow sequence value (a: [it's, b]) still splits wrongly in _flow_sequence; a separate bug, out of scope for this issue

Fix

  • plugins/code-metrics/scripts/yaml_subset.py: _strip_comment opens a quote only at a value start (new _value_starts_at); _mapping takes a seed so the sequence item's first key joins the duplicate check
  • plugins/code-metrics/scripts/test_yaml_subset.py: tests for quotes and comments in plain values and for the duplicate key line in a sequence item
  • .changes/code-metrics/fix-yaml-subset-quote-and-duplicate-line-7c4e2a91.md: patch changelog fragment

Verification

The run reports:

Left out: the items under Not verified.

Related

#6699

…cate key in a sequence item reports its own line

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 22a39807aea8b57c27d83105a833381bcf30ceaa: 0 finding(s), 0 as inline comments.

No security issues found in PR 8036 at 22a3980.

The PR changes the code-metrics YAML subset reader (plugins/code-metrics/scripts/yaml_subset.py), its tests, and a changelog fragment. It has two changes:

  • A quote now opens a quoted string only where a value starts, so a quote inside a plain value no longer hides a trailing # comment.
  • A duplicate key inside a sequence-item mapping is now reported on its own line, by seeding _mapping with the first entry.

The parser is pure string handling with no eval, deserialization of arbitrary types, file or network access, or subprocess use. The duplicate-key check still fires, just on a different line, and no guardrail or standing instruction is removed or softened. The only behavior change is how a comment is trimmed from a plain value, and nothing in the diff shows that feeding a trust decision.

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 22a39807aea8b57c27d83105a833381bcf30ceaa: 0 finding(s), 0 as inline comments.

No findings. I reviewed the whole diff (3 files) against #6699 and found no defects.

Fix 1, quote mid-value. _value_starts_at (plugins/code-metrics/scripts/yaml_subset.py:50) opens a quote only at line start, after - , after [ or ,, or after : . I traced these inputs by hand and they come out right:

  • title: it's fine # comment
  • say: a"b # c
  • - it's # c
  • k:\n - 'a # b'
  • quoted keys
  • - key: 'v'
  • [x, 'b # c']

Fix 2, duplicate key line. _mapping now takes a seed, so the sequence item's first key is checked inside the loop. raise YamlSubsetError(number, ...) then uses the duplicate key's own line. The no-more-entries case is handled by the else branch, which appends {key: first} as before.

Acceptance criteria. Both bugs have a named test. The PR describes them as failing before the fix, but I did not confirm that. The changelog fragment looks right (bump: patch).

Limits of this review. I could not run the tests: the sandbox required approval for the Python invocation. The test results in the PR body are author-claimed and unverified by me.

Known gap. The PR body already notes that _flow_sequence still splits on a quote after a comma (a: [it's, b]). That is separate from _strip_comment and outside #6699, so I did not report it.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path enqueued this pull request at head 22a39807aea8b57c27d83105a833381bcf30ceaa.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Oct 18, 2026
Merged via the queue into main with commit 611733f Oct 18, 2026
32 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-6699-39098692440-1 branch October 18, 2026 09:26
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.

code-metrics yaml_subset.py: quote mid-value swallows comments; duplicate key in a sequence item reports the wrong line

0 participants