Skip to content

feat: Gutenberg 22.8 V2 encoding compatibility and e2e test suite#25

Merged
pento merged 10 commits intomainfrom
fix/gutenberg-22.8-v2-encoding
Mar 28, 2026
Merged

feat: Gutenberg 22.8 V2 encoding compatibility and e2e test suite#25
pento merged 10 commits intomainfrom
fix/gutenberg-22.8-v2-encoding

Conversation

@pento
Copy link
Copy Markdown
Owner

@pento pento commented Mar 27, 2026

Summary

  • Adapts the Yjs sync protocol to match Gutenberg 22.8's mixed V1/V2 encoding (PR WordPress/gutenberg#76304)
  • Increases sync wait timeout from 5s to 15s to accommodate Gutenberg 22.8's slower polling intervals (4s solo / 1s collaborative)
  • Displays WordPress version during setup wizard; sync endpoint availability is the actual compatibility gate
  • Adds Playwright e2e test suite for collaborative block sync against live wp-env
  • Fixes pre-existing TypeScript strict mode issues in test files by including tests in tsconfig.json

Protocol changes

Gutenberg 22.8 switched regular updates and compactions to V2 encoding but kept the sync handshake (step1/step2) on V1 via y-protocols. We now match this:

Message type Encoding Reason
step1 V1 (y-protocols) State vectors are format-agnostic
step2 V1 (y-protocols) Gutenberg uses syncProtocol.readSyncMessage which hardcodes V1
update V2 Gutenberg captures via doc.on('updateV2'), applies with applyUpdateV2
compaction V2 Gutenberg uses encodeStateAsUpdateV2

E2e tests

6 Playwright tests against a live wp-env + Gutenberg instance:

  • MCP inserts blocks visible in browser
  • MCP edits block content visible in browser
  • MCP changes block attributes visible in browser
  • MCP removes blocks visible in browser
  • Browser edits visible in MCP
  • Multiple sequential edits in a single session

Test plan

  • npm run typecheck — passes
  • npm test — 834 unit/integration tests pass
  • npm run lint — clean
  • npm run test:e2e — 6 e2e tests pass
  • Manual verification: handshake delivers state to late-joining clients
  • Manual verification: real-time edits sync bidirectionally
  • Manual verification: notes sync in real-time (with Gutenberg fix for collab sidebar mounting)

Gutenberg 22.8 (PR #76304) switched Yjs update encoding from V1 to V2,
breaking collaborative editing with external clients. This adapts the
sync protocol to match Gutenberg's mixed V1/V2 approach:

- Step1/step2 handshake: V1 via y-protocols (Gutenberg still uses
  syncProtocol.readSyncMessage which hardcodes V1)
- Regular updates and compactions: V2 (doc.on('updateV2'),
  applyUpdateV2, encodeStateAsUpdateV2)

Also increases sync wait timeout from 5s to 15s to accommodate
Gutenberg 22.8's slower polling intervals (4s solo), and adds a
minimum WordPress version check (7.0+) during setup and connect.

Adds a Playwright e2e test suite covering block insert, edit, attribute
change, remove, browser-to-MCP sync, and multi-step workflows against
a live wp-env Gutenberg instance.
Copilot AI review requested due to automatic review settings March 27, 2026 23:49
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

✅ Coverage Report

Metric Value
Current coverage 94.20% (1999/2122)
Baseline coverage 94.18% (1990/2113)
Result PASS

Changed Files

File Baseline Current Status
src/cli/setup.ts 94.55% 94.61% PASS
src/session/session-manager.ts 90.25% 90.25% PASS
src/wordpress/api-client.ts 98.68% 98.80% PASS
src/yjs/sync-protocol.ts 95.83% 95.83% PASS

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the server’s Yjs sync protocol and tooling to interoperate with Gutenberg 22.8’s mixed V1/V2 encoding, and adds Playwright e2e coverage for collaborative block sync against a live wp-env WordPress instance.

Changes:

  • Switch sync UPDATE/COMPACTION handling to Yjs V2 (updateV2 / applyUpdateV2 / encodeStateAsUpdateV2) while keeping sync step1/step2 via y-protocols (V1).
  • Add minimum WordPress version check during connection/setup and increase initial sync wait timeout to 15s.
  • Add Playwright-based e2e suite + helpers and include tests/config in TypeScript project for strict checking.

Reviewed changes

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

Show a summary per file
File Description
src/yjs/sync-protocol.ts Implements mixed V1 (handshake) / V2 (updates+compaction) encoding behavior.
src/session/session-manager.ts Uses updateV2, increases sync wait timeout, and enforces minimum WP version on connect.
src/wordpress/api-client.ts Adds checkMinimumVersion() and associated error messaging.
src/cli/setup.ts Runs minimum version check during setup credential validation and logs version.
tests/unit/sync-protocol.test.ts Updates unit tests to use V2 events/decoding where appropriate.
tests/integration/two-client-sync.test.ts Updates integration tests to capture V2 updates.
tests/unit/session-manager.test.ts Mocks new API client method + fixes strict typing in fs mock.
tests/unit/server.test.ts Fixes strict nullability for handler registries.
tests/unit/cli/setup.test.ts Adjusts mocked REST validation sequence to include version check.
tests/unit/cli/auth-server.test.ts Adjusts execFile mock signature for strict typing.
tests/e2e/helpers/wp-env.ts Adds wp-env lifecycle and WP CLI helpers for e2e.
tests/e2e/helpers/mcp.ts Adds MCP stdio client helper utilities for e2e.
tests/e2e/global-setup.ts / tests/e2e/global-teardown.ts Starts/stops wp-env for Playwright runs.
tests/e2e/block-sync.spec.ts Adds browser↔MCP collaborative block sync e2e scenarios.
playwright.config.ts Introduces Playwright test configuration.
tsconfig.json Includes tests/config files; removes rootDir.
package.json / package-lock.json Adds Playwright dependency and e2e scripts.
CLAUDE.md Documents mixed encoding + minimum version behavior.
.markdownlint-cli2.jsonc / .gitignore Ignores Playwright output and adds minor formatting/ignore updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pento added 2 commits March 28, 2026 10:56
Covers: version >= 7.0, version < 7.0, endpoint unavailable, missing
version field, empty version, unparseable version, and the setup wizard
exit path for old WordPress versions.
- STATE_FILE collision: include repo root hash in temp filename to
  prevent concurrent e2e runs from different checkouts interfering.

- Version check logic: rename checkMinimumVersion() to
  getWordPressVersion() — now purely informational (never throws).
  The sync endpoint check remains the real gate. If the endpoint
  returns 404, the error message includes the detected WP version
  and mentions both upgrade paths (WP 7.0+ or Gutenberg 22.8+).
  This fixes a bug where WP 6.x + Gutenberg 22.8+ users were
  incorrectly blocked.
Copilot AI review requested due to automatic review settings March 28, 2026 00:06
Replace wp-cli commands (npx wp-env run cli) with REST API calls for
post creation, deletion, and app password creation. This eliminates
concurrent wp-cli execution issues that caused "Environment not
initialized" errors when running tests in parallel.

Also always run wp-env start in global setup (idempotent) to ensure
wp-env's internal state file is valid regardless of how the environment
was started.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pento added 2 commits March 28, 2026 11:28
- Use shared app password (created once in global setup via wp-cli)
  for all REST API calls, eliminating per-test app password creation
  race conditions.
- Replace wp-cli post CRUD with REST API calls, safe for concurrent
  execution across workers.
- Revert unconditional wp-env start (afterStart script is too slow).
- Add e2e job to CI workflow (Node 22, Playwright + wp-env).
- Enable fullyParallel with 2 workers.
Add a Playwright setup project that logs in once and saves storage
state. All test workers reuse the saved session, eliminating concurrent
login race conditions. Bumps workers to 4.
Copilot AI review requested due to automatic review settings March 28, 2026 00:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 22 out of 25 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pento added 2 commits March 28, 2026 11:57
Fetch the latest Gutenberg release ZIP via GitHub API at CI time
instead of cloning and building trunk. This avoids the slow
afterStart build step and the directory layout issues in CI.
- CLAUDE.md: Update stale version check docs to match the current
  informational getWordPressVersion() approach.
- session-manager.test.ts: Replace hacky `as []` cast with properly
  typed variadic mock signature for mockReadFile.
Copilot AI review requested due to automatic review settings March 28, 2026 01:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- ensureWpEnvRunning() checks state file for existing app password
  before creating a new one, preventing accumulation.
- teardownWpEnv() preserves state file when CLAUDABORATIVE_E2E_REUSE_ENV=1
  so the next run can reuse the password.
@pento pento merged commit 67d8f13 into main Mar 28, 2026
4 checks passed
@pento pento deleted the fix/gutenberg-22.8-v2-encoding branch March 28, 2026 01:35
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