Skip to content

Pattern Normalizer#8

Merged
jasperf merged 4 commits into
mainfrom
pattern-normalizer
May 14, 2026
Merged

Pattern Normalizer#8
jasperf merged 4 commits into
mainfrom
pattern-normalizer

Conversation

@jasperf
Copy link
Copy Markdown
Contributor

@jasperf jasperf commented May 14, 2026

This pull request introduces the pattern:diff command 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 --apply flag. The feature is implemented across five dedicated classes under src/PatternDiff/BlockNormalizer, PatternDiffer, PatternSyncer, TranslationDetector, and WooCommerceValidator — 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 both CHANGELOG.md and README.md has been expanded to reflect the new command surface and its options.

Pattern Diff Command and Core Logic:

  • PatternDiffCommand registers the pattern:diff CLI subcommand in bin/pt-cli, accepting a source clipboard file and target PHP pattern path, with an optional --apply flag to write merged output back to disk.
  • BlockNormalizer canonicalizes Gutenberg block markup to produce stable comparison inputs, while PatternDiffer performs the structural diff between normalized representations.
  • PatternSyncer orchestrates the merge of diffed blocks back into the PHP pattern wrapper, preserving header metadata and translation markers.
  • TranslationDetector and WooCommerceValidator provide pre-merge validation to detect __() / _e() wrapped strings and WooCommerce block namespaces respectively, preventing unsafe overwrites.

Test Coverage:

  • A full PHPUnit test suite was added under tests/PatternDiff/, covering all five new classes with unit tests for normalization, diffing, syncing, translation detection, and WooCommerce validation.
  • TranslationDetectorTest includes direct tests for the isTranslated() method, covering both positive and negative string fixtures to guard against false negatives in merge safety checks.
  • PatternDiffCommandTest exercises the command integration layer, validating flag handling and exit codes for both dry-run and --apply scenarios.

Tooling and Documentation:

  • .vibe/config.toml was updated to permit python and python3 as allowed vibe tool interpreters, unblocking any Python-based helper scripts in the diff workflow.
  • CHANGELOG.md for v2.3.0 was expanded to document previously omitted pattern:diff flags, and README.md was updated to describe the new command with usage examples.

Files Changed:

jasperf added 4 commits May 14, 2026 08:24
…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.
@jasperf jasperf merged commit 97f4cb6 into main May 14, 2026
@jasperf jasperf deleted the pattern-normalizer branch May 14, 2026 03:27
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.

1 participant