Skip to content

Add failing specs for inter-token comments in merge_strings#742

Merged
jkmassel merged 2 commits into
foundationfrom
mokagio/merge-strings-inline-comment-tests
Jun 30, 2026
Merged

Add failing specs for inter-token comments in merge_strings#742
jkmassel merged 2 commits into
foundationfrom
mokagio/merge-strings-inline-comment-tests

Conversation

@mokagio

@mokagio mokagio commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

What does it do?

Adds two failing specs that pin a gap in #741, on which this branch is stacked.

AI-generated details

The duplicate-key scanner and plutil-based bookkeeping both accept .strings comments between a statement's tokens (e.g. CFBundleName /* c */ = WordPress;), but merge_strings' line-based key rewrite only prefixes when = and the value are adjacent. A key behind such a comment is written unprefixed while still bookkept with the prefix — resurfacing the key collisions the prefix exists to prevent. The second spec makes the harm concrete: merging two files that each hide the same key behind a comment collapses to a single key instead of two distinctly-prefixed ones.

The specs are red on purpose — they're the regression net for the fix (tokenizer-unification, or an interim comment-aware rewrite), which is intentionally not in this branch yet.

Heads-up for reviewers

How to test

bundle exec rspec spec/ios_l10n_helper_spec.rb — the two new #merge_strings examples fail; the rest pass.

These specs fail against the current `merge_strings`, pinning a gap left by
PR #741: the duplicate-key scanner and `plutil`-based bookkeeping both accept
`.strings` comments *between* a statement's tokens
(e.g. `CFBundleName /* c */ = WordPress;`), but the line-based key rewrite only
prefixes when `=` and the value are adjacent.
A key behind such a comment is written unprefixed while bookkept *with* the
prefix — resurfacing the very key collisions the prefix exists to prevent, as
the second spec demonstrates by merging two files into a single collapsed key.

---

Generated with the help of Claude Code, https://claude.com/claude-code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mokagio mokagio self-assigned this Jun 25, 2026
@dangermattic

dangermattic commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ Please add an entry in the CHANGELOG.md file to describe the changes made by this PR

Generated by 🚫 Danger

Assert parsed keys so the regression captures the merge contract without depending on raw output formatting.

---

Generated with the help of Codex, https://openai.com/codex

Co-Authored-By: Codex GPT-5 <noreply@openai.com>
@mokagio mokagio requested a review from jkmassel June 26, 2026 04:00
@jkmassel jkmassel marked this pull request as ready for review June 30, 2026 15:26
@jkmassel jkmassel merged commit 95e64bb into foundation Jun 30, 2026
6 of 8 checks passed
@jkmassel jkmassel deleted the mokagio/merge-strings-inline-comment-tests branch June 30, 2026 15:32
jkmassel added a commit that referenced this pull request Jun 30, 2026
`merge_strings` prefixed keys with line-based regexes that assume the key, `=`, and value
are adjacent, so an inter-token `.strings` comment — `AppName /* c */ = WordPress;` or
`CFBundleName = WordPress /* trailing */;` — broke the match and the key was written to the
merged file without the prefix, while the `plutil`-derived bookkeeping still recorded it
*with* the prefix. The inconsistency could resurface the very collisions the prefix exists
to avoid (two files sharing a key behind a comment merged to a single colliding key).

Replace the regexes with `StringsFileValidationHelper.prefix_keys`, a comment-aware
tokenizer that reuses the same state machine `find_duplicated_keys` uses: it prefixes a key
wherever the tokenizer enters one, regardless of surrounding comments, and leaves
`key = value`-looking text inside a comment alone. Bookkeeping and rewriting now agree by
construction. Fixes the failing specs added in #742.
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.

3 participants