docs(phase-38): add 38-01 execution summary

This commit is contained in:
Jakub Zych
2026-11-28 12:45:22 +01:00
parent 5d82411ef5
commit 44f47ad64f

View File

@@ -0,0 +1,82 @@
---
phase: 38-extensible-journal-embed-providers
plan: 01
subsystem: sm-journal-plugin
tags: [journal, embeds, sanitizer, blogeditor, tiptap]
requires: []
provides:
- "`classes.EmbedRegistry` with Go + YAML (`golem15.journal.embed_providers`) registration and fail-loud boot validation"
- "Pair-aware `(data-embed, data-id)` HTML sanitization with `data-aspect`/`data-height` and UGC fallback children"
- "Dynamic Blog Editor embed providers (`blogRequestOptions`), adaptive embed dialog, fallback-preserving TipTap `Embed` node, and preview"
affects:
- "../sm-journal-plugin"
- "Plan 38-02 (vue-journal-layer)"
- "Plan 38-03 (unit tests, corpus cross-check, docs)"
tech-stack:
added: []
patterns:
- "App-scoped `*classes.EmbedRegistry` published on `backpack.App` with thread-safe lazy `*bluemonday.Policy` caching"
- "Post-bluemonday `golang.org/x/net/html` pair-aware `<figure>` validation (`enforceEmbedPairs`)"
- "Adaptive Blog Editor embed form (unchanged single URL input when only `youtube` is registered)"
key-files:
created:
- "../sm-journal-plugin/classes/embed_registry.go"
modified:
- "../sm-journal-plugin/classes/format_html.go"
- "../sm-journal-plugin/classes/blog_editor.go"
- "../sm-journal-plugin/classes/editor_policy_test.go"
- "../sm-journal-plugin/plugin.go"
- "../sm-journal-plugin/config/config.yaml"
- "../sm-journal-plugin/controllers/api/posts.go"
- "../sm-journal-plugin/controllers/api/posts_helpers.go"
- "../sm-journal-plugin/controllers/posts.go"
- "../sm-journal-plugin/console/import_posts.go"
- "../sm-journal-plugin/assets/src/blogeditor/embed.ts"
- "../sm-journal-plugin/assets/src/blogeditor/extensions.ts"
- "../sm-journal-plugin/assets/src/blogeditor/element.ts"
- "../sm-journal-plugin/assets/src/blogeditor/preview.ts"
- "../sm-journal-plugin/assets/src/blogeditor/labels.ts"
- "../sm-journal-plugin/assets/src/blogeditor/blogeditor.css"
- "../sm-journal-plugin/assets/dist/blogeditor.js"
- "../sm-journal-plugin/assets/dist/blogeditor.css"
- "../sm-journal-plugin/tests/blogeditor/additions.test.ts"
key-decisions:
- "Anchored `IDPattern` with `^(?:...)$` in both Go (`EmbedRegistry.Register`) and TS (`resolveEmbedProviders`) after validating the raw regex so partial matches cannot slip through."
- "Updated `classes/editor_policy_test.go` stripped-embed expectations from orphan half-attributes to `<figure></figure>` to reflect D-03 pair-aware stripping."
- "Wired `loadBlogHTMLFor(app)` and `console.ImportFromDirApp` alongside `decodeBlogHTMLFor`, `blogRequestOptions`, and API post write helpers so every Journal write/load path respects app-scoped custom providers."
duration: 10m
completed: 2026-11-28
---
# Phase 38 Plan 01: Extensible Embed Registry & Blog Editor (`sm-journal-plugin`) Summary
Implemented the generic, app-extensible embed provider registry, pair-aware HTML sanitizer, and dynamic Blog Editor authoring/preview flow in `sm-journal-plugin`.
## Commits
- **`sm-journal-plugin` `55ac26e`** — `feat(journal): add EmbedRegistry, YAML boot config, and pair-aware sanitizer`
- Added `classes/embed_registry.go` (`EmbedProvider`, `EmbedProviderDescriptor`, `EmbedRegistry`, `NewEmbedRegistry`, `EmbedRegistryFrom`, `LoadFromConfig`, `EditorDescriptors`, `Match`, `Policy`).
- Updated `classes/format_html.go` with registry-backed `newHTMLPolicyFor`, `data-aspect`/`data-height` allow-lists, and post-bluemonday `enforceEmbedPairs` across `FormatHTML`, `SanitizeHTML`, `SanitizeHTMLReport`, `FormatTranslation`, and `CheckHTML`.
- Published `*classes.EmbedRegistry` in `Plugin.Register` and merged `golem15.journal.embed_providers` in `Plugin.Boot` (failing loud on invalid keys, missing/invalid regexes, or unknown modes); documented `embed_providers: {}` in `config/config.yaml`.
- Wired `EmbedRegistryFrom(app)` across `classes/blog_editor.go` (`decodeBlogHTMLFor`, `loadBlogHTMLFor`, `blogRequestOptions`), `controllers/api/posts.go` & `posts_helpers.go`, `console/import_posts.go` (`ImportFromDirApp`), and `controllers/posts.go`.
- **`sm-journal-plugin` `37e89e5`** — `feat(blogeditor): support dynamic embed providers, fallbacks, and adaptive form`
- Generalized `assets/src/blogeditor/embed.ts` with `EmbedProviderConfig`, `ResolvedEmbedProvider`, `resolveEmbedProviders`, `findEmbedProvider`, `validateEmbedId`/`isValidEmbed`, `parseEmbedUrlWith`, `isValidAspect`, and `isValidHeight`, preserving `EMBED_PROVIDERS`, `isEmbedProvider`, and `parseEmbedUrl`.
- Extended TipTap `Embed` node in `extensions.ts` to model, round-trip, and render `<figure data-embed>` with `data-aspect`/`data-height` and fallback `<img>`/`<figcaption>` (preserving empty `<figure data-embed="youtube" data-id="..."></figure>` unchanged).
- Updated `element.ts`, `preview.ts`, `labels.ts`, and `blogeditor.css` with adaptive embed form UX (single URL input when only `youtube` is registered; provider selector + ID + Media Library fallback picker + alt/caption/aspect/height when custom providers exist) and rebuilt `assets/dist/blogeditor.{js,css}`.
## Verification Results
- `cd ../sm-journal-plugin && go vet ./... && go test -short ./...`: PASS (all packages green).
- `npm --prefix ../sm-journal-plugin run build`: PASS (`tsc --noEmit && vite build`, rebuilt `assets/dist/blogeditor.js` and `assets/dist/blogeditor.css`).
- `npm --prefix ../sm-journal-plugin run test`: PASS (10 test files, 259/259 tests passed).
## Deviations & Notes for Wave 2
- **Expected test updates (Rule 1):**
- Updated 11 stripped-embed cases in `classes/editor_policy_test.go` from orphan single-attribute `<figure data-embed="youtube"></figure>` / `<figure data-id="..."></figure>` to `<figure></figure>` to match D-03 pair-aware stripping.
- Updated `tests/blogeditor/additions.test.ts` `readOptions` assertions to include the new `embedProviders` default field.
- **Additional files touched beyond plan frontmatter:** `controllers/api/posts_helpers.go`, `controllers/posts.go`, `classes/editor_policy_test.go`, and `tests/blogeditor/additions.test.ts` (needed to wire all API/import sanitization paths and align existing assertions with the new pair-aware contract and `EditorOptions` shape).
- **Notes for Wave 2 (`vue-journal-layer`):**
- `data-aspect` regex: `^[1-9][0-9]{0,3}(?:\s*\/\s*[1-9][0-9]{0,3}|\.[0-9]{1,4})?$`
- `data-height` regex: `^[1-9][0-9]{0,3}(?:px)?$`
- Pair-aware stripping in `htmlGate.ts` should mirror `enforceEmbedPairs` by stripping `data-embed`, `data-id`, `data-aspect`, and `data-height` whenever `(data-embed, data-id)` is incomplete or fails the provider's `idPattern`.