Skip to content

blocks-engine: structured convert report (envelope + fallback inventory + metrics)#426

Merged
borkweb merged 12 commits into
trunkfrom
feature/js-envelope
Jun 30, 2026
Merged

blocks-engine: structured convert report (envelope + fallback inventory + metrics)#426
borkweb merged 12 commits into
trunkfrom
feature/js-envelope

Conversation

@borkweb

@borkweb borkweb commented Jun 30, 2026

Copy link
Copy Markdown
Member

What

This adds better reporting in the blocks-engine package—an idea from the php-transformer.

Adds a structured conversion report to @automattic/blocks-engine and wires it into the theme builder so HTML→blocks conversion fidelity is visible and measurable instead of a black box.

  • New canonical convertReport(html, ctx?, opts?) returning a versioned envelope: { schema, status, blockMarkup, fallbacks, diagnostics, metrics }.
  • convert() is unchanged for callers (still returns the markup string) — it's now a thin projection of convertReport().blockMarkup, so the string and the envelope can never drift.
  • fallbacks is a per-conversion inventory of everything that did not become a native block (each unconverted core/html island with a location + bounded snippet), capped at 100 with a true total in metrics.fallbackCount.
  • metrics: input/output bytes, block count, fallback/diagnostic counts, duration.
  • diagnostics: conversion_degraded (worker sentinel/internal-catch), content_dropped (non-empty input → empty output), fallback_inventory_truncated, normalized_markup.
  • Consumer: siteToTheme now aggregates per-page conversion fidelity into ThemeBuildResult — a typed ThemeDiagnostics.conversion aggregate, human-readable warnings ("page X: N section(s) fell back to raw HTML" / "conversion degraded"), and a fallbacks tally.

Why

  • Fidelity is now visible. Conversion failures used to be silent; they're now reported, located, and counted.
  • Regressions become measurable — the envelope is the foundation a future tuner/ratchet pass guards against.
  • Honest by construction — review hardening ensures the report can't claim success when content was dropped or the conversion degraded.

Design notes

  • Block analysis runs in the worker (where the WP parser already lives); buildReport stays pure and @wordpress/*-free, preserving the no-wordpress-runtime-deps contract.
  • See the design + deep-review record: packages/blocks-engine/docs/superpowers/specs/2026-06-30-convert-report-envelope-design.md.

Testing

  • pnpm build → exit 0
  • pnpm test100 files / 472 tests, 0 failures (baseline 439)
  • pnpm typecheck → 0 errors
  • dependency-boundary guard green

borkweb added 12 commits June 30, 2026 13:28
Design for porting php-transformer's structured result envelope into packages/blocks-engine as item #1 of docs/to-port-to-js.md: a new canonical convertReport() returning { schema, status, blockMarkup, fallbacks, diagnostics, metrics }, with convert() projected to .blockMarkup. Covers the tolerant ConversionFinding shape, core/html-as-fallback-source inventory, metrics, a pure unit-testable buildReport core, and an assertConvertReport contract. Scopes ratchet integration and hallucination findings out to later items.
Incorporates the four decisions from the plan deep review: (1) block analysis moves into the worker (Approach A) so buildReport stays pure and WP-free and the no-wordpress-runtime-deps contract holds, reusing walkBlocks and adding blockCount/htmlIslands to FixResult; (2) conversion_degraded diagnostic when the pool sentinel fires; (3) unconverted_html inventory capped at 100 with a fallback_inventory_truncated diagnostic while metrics.fallbackCount keeps the true total; (4) snippet sanitized, char-based (multibyte-safe) truncation, documented as untrusted. Updates sections 3-8 and the testing matrix accordingly.
Capture the 6 review-deferred follow-ups (invalid-block severity, fallbackCount/length doc, inventory perf gate per council C, snippet render-safety, failed-status decision, purity import-graph guard) in the spec so nothing is lost after the branch lands. Docs only.
Declare ThemeDiagnostics.conversion optional so adding it is backward-compatible for external code that constructs a ThemeBuildResult/ThemeDiagnostics literal (e.g. downstream test fixtures), which would otherwise have to add the new field to compile. siteToTheme still always populates it, so readers are unaffected at runtime. Keeps the change purely additive for consumers like data-liberation-agent.
The root .gitignore pattern 'docs/superpowers/' is anchored to the repo root, so it did not cover 'packages/blocks-engine/docs/superpowers/' — which let a design spec get committed by mistake. Switch to '**/docs/superpowers/' so the path is ignored at any depth, and remove the spec doc that should not have been committed.
Root pattern 'docs/superpowers/' is anchored to the repo root and did not cover 'packages/blocks-engine/docs/superpowers/', which let a design spec get committed by mistake. Use '**/docs/superpowers/' so superpowers docs are ignored at any depth.
@borkweb borkweb merged commit 58d75b7 into trunk Jun 30, 2026
2 checks passed
@borkweb borkweb deleted the feature/js-envelope branch June 30, 2026 20:13
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