Pattern Normalizer#8
Merged
Merged
Conversation
…o PHP patterns Adds pattern:diff --apply (with --dry-run preview) that merges Gutenberg editor clipboard HTML back into an existing PHP pattern file while preserving all PHP translation wrappers. - PatternSyncer: strips __privatePreviewState, normalises font-size slug values to CSS variables, removes nested <p> copy artefacts, remaps text nodes to original esc_html_e/esc_attr_e/wp_kses_post calls, and generates new wrappers for any new text strings - PatternDiffCommand: new --apply and --dry-run options wire into syncer - Fix PatternDiffer::isTranslatable() — missing if-guard caused early return false, silently skipping all translation detection - Bump to v2.3.0
Covers the previously untested public method with four cases: wrapped text (true), bare text (false), mismatched text (false), and escaped single quotes in wrapper (true).
CHANGELOG: add all new classes (BlockNormalizer, PatternDiffer, TranslationDetector, WooCommerceValidator), the full PatternDiff test suite, all command options, and the .vibe/config.toml change. README: document --show-suggestions, --json, and --similarity-threshold options for pattern:diff.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces the
pattern:diffcommand to pt-cli (v2.3.0), a new subcommand that compares Gutenberg clipboard content against existing PHP pattern files and optionally merges changes in place via the--applyflag. The feature is implemented across five dedicated classes undersrc/PatternDiff/—BlockNormalizer,PatternDiffer,PatternSyncer,TranslationDetector, andWooCommerceValidator— each with a corresponding PHPUnit test file, bringing 2,913 lines of new production and test code. The command enables a structured workflow for keeping PHP pattern files in sync with Gutenberg editor output without requiring a WordPress runtime. Documentation in bothCHANGELOG.mdandREADME.mdhas been expanded to reflect the new command surface and its options.Pattern Diff Command and Core Logic:
PatternDiffCommandregisters thepattern:diffCLI subcommand inbin/pt-cli, accepting a source clipboard file and target PHP pattern path, with an optional--applyflag to write merged output back to disk.BlockNormalizercanonicalizes Gutenberg block markup to produce stable comparison inputs, whilePatternDifferperforms the structural diff between normalized representations.PatternSyncerorchestrates the merge of diffed blocks back into the PHP pattern wrapper, preserving header metadata and translation markers.TranslationDetectorandWooCommerceValidatorprovide pre-merge validation to detect__()/_e()wrapped strings and WooCommerce block namespaces respectively, preventing unsafe overwrites.Test Coverage:
tests/PatternDiff/, covering all five new classes with unit tests for normalization, diffing, syncing, translation detection, and WooCommerce validation.TranslationDetectorTestincludes direct tests for theisTranslated()method, covering both positive and negative string fixtures to guard against false negatives in merge safety checks.PatternDiffCommandTestexercises the command integration layer, validating flag handling and exit codes for both dry-run and--applyscenarios.Tooling and Documentation:
.vibe/config.tomlwas updated to permitpythonandpython3as allowed vibe tool interpreters, unblocking any Python-based helper scripts in the diff workflow.CHANGELOG.mdfor v2.3.0 was expanded to document previously omittedpattern:diffflags, andREADME.mdwas updated to describe the new command with usage examples.Files Changed:
.vibe/config.toml(Modified)CHANGELOG.md(Modified)README.md(Modified)bin/pt-cli(Modified)src/Commands/PatternDiffCommand.php(Added)src/PatternDiff/BlockNormalizer.php(Added)src/PatternDiff/PatternDiffer.php(Added)src/PatternDiff/PatternSyncer.php(Added)src/PatternDiff/TranslationDetector.php(Added)src/PatternDiff/WooCommerceValidator.php(Added)tests/Commands/PatternDiffCommandTest.php(Added)tests/PatternDiff/BlockNormalizerTest.php(Added)tests/PatternDiff/PatternDifferTest.php(Added)tests/PatternDiff/PatternSyncerTest.php(Added)tests/PatternDiff/TranslationDetectorTest.php(Added)tests/PatternDiff/WooCommerceValidatorTest.php(Added)