From bb43a17b9befa6e8e13414ca10837efaeee5a65d Mon Sep 17 00:00:00 2001 From: Jakub Zych Date: Fri, 27 Nov 2026 14:01:34 +0100 Subject: [PATCH] docs(phase-37): add 37-VERIFICATION.md goal-backward verification report --- .../37-media-library-album/37-VERIFICATION.md | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .planning/phases/37-media-library-album/37-VERIFICATION.md diff --git a/.planning/phases/37-media-library-album/37-VERIFICATION.md b/.planning/phases/37-media-library-album/37-VERIFICATION.md new file mode 100644 index 00000000..7cd0d6ae --- /dev/null +++ b/.planning/phases/37-media-library-album/37-VERIFICATION.md @@ -0,0 +1,96 @@ +--- +phase: 37-media-library-album +verified: 2026-11-27T13:01:00Z +status: passed +score: 34/34 must-haves verified +--- + +# Phase 37: Media Library (`album`) Verification Report + +**Phase Goal:** Ship a core, plugin-agnostic Media Library (`modules/album`) backed by `lagoon/attach` (`blob.Bucket`) and Postgres metadata with virtual folders, immutable SEO-slug blob keys, synchronous automatic responsive WebP `srcset` variants, a first-class admin **Media** screen + `type: mediafinder` form field + shared Media Picker modal in `cabana`/`boardwalk`, granularly scoped (`media` / `media:read`) MCP tools in `pier`, unified backward-compatible Mail Images (`cabana`) and Journal uploads (`sm-journal-plugin`), and batched render-time inline WebP `srcset`/`sizes` enrichment (`sm-journal-plugin` + `vue-journal-layer`). +**Verified:** 2026-11-27T13:01:00Z +**Status:** `passed` +**Re-verification:** No — initial goal-backward verification across Plans `37-01` through `37-05`. + +## Goal Achievement + +### Observable Truths (`must_haves.truths` across Plans 37-01 through 37-05) + +| # | Plan | Truth | Status | Evidence | +| --- | --- | --- | --- | --- | +| 1 | 37-01 | `modules/album` is a core framework module with zero import of `modules/lagoon` (only `lagoon/attach*`), allowing `modules/lagoon/migrations.go` to register `album.Migrations` cleanly without circular imports (D-01). | VERIFIED | `go list -f '{{range .Imports}}...' ./modules/album` lists only `backpack`, `compass`, `lagoon/attach`, `lagoon/attach/webp`; `modules/lagoon/migrations.go:230` registers `{"summercms.album", "media", album.Migrations}`. | +| 2 | 37-01 | `album.Migrations` creates `summer_media_folders`, `summer_media_items`, and `summer_media_upload_tokens` with full indexes, FKs, unique `(COALESCE(parent_id, 0), slug)`, unique `short_id`/`blob_key`, indexed `sha256`, JSONB `variants`, and nullable unique `legacy_file_id` (D-02, D-08, D-09, D-13). | VERIFIED | `modules/album/migrations.go` lines 8–45 define all three tables, unique index `(COALESCE(parent_id, 0), slug)`, and `legacy_file_id BIGINT UNIQUE`; verified up/down/up by `TestMigrationsUpDown`. | +| 3 | 37-01 | Uploads store originals at `media//.` reusing `attach.DefaultImageExtensions`, `attach.DefaultFileExtensions`, `attach.IsAllowedImage` (`attach.MaxImagePixels` bomb guard), `attach.DiskExtension`, and `attach.UploadWriterOptions`, rejecting SVG/HTML/JS (D-03, D-06). | VERIFIED | `modules/album/service.go` lines 152–283 wire all `attach.*` primitives and pixel-dimension guard; proven by `TestDecompressionBombAndPolyglotGuards` & `TestUploadAndNoDedup`. | +| 4 | 37-01 | Raster image uploads synchronously generate WebP width variants (`480w`, `960w`, `1600w`, never upscaling) via `lagoon/attach/webp`, store them beside the original, persist `width`/`height`/`sha256`/`variants`, and clean up blobs on error (D-07, D-08). | VERIFIED | `modules/album/variants.go:25–33` (`GenerateWebPVariants`) + `modules/album/service.go:237`; proven by `TestWebPVariants` & `TestUploadAndNoDedup`. | +| 5 | 37-01 | `PrepareUpload` stores only the SHA-256 hash of a high-entropy single-use token (5 min TTL), and `ConsumeUploadToken` atomically marks `used_at = NOW()` (`WHERE token_hash = ? AND used_at IS NULL AND expires_at > NOW() RETURNING ...`) (D-09, D-10). | VERIFIED | `modules/album/tokens.go:6,122–154`; proven against concurrent races, replay, and expiry by `TestConsumeUploadTokenSingleUse`. | +| 6 | 37-01 | Deleting an item exposes `DeleteItemInTx` and `DeleteBlobs` so callers wrap deletes in `lagoon.Transaction` + `lagoon.AfterCommit` and rolled-back transactions never delete live blobs (D-12). | VERIFIED | `modules/album/service.go` + `modules/cabana/media_routes.go` (`lagoon.AfterCommit`); proven by `TestDeleteItemInTxAfterCommit`. | +| 7 | 37-01 | `surf.BuildRouter` mounts zero-DB-hit `GET /media/{short_id}/{file}` (`Cache-Control: immutable`, `nosniff`, CSP, `Content-Disposition: attachment` for non-inline) and raw `PUT`/`POST /media/upload/{token}` with `MaxBytesReader` and inline throttle (D-06, D-09, D-10). | VERIFIED | `modules/album/http.go:39–87` (no DB access in `StaticHandler`), `modules/surf/router.go:750` -> `modules/surf/media.go:25`; proven by `TestStaticHandlerSecurity` & `TestMediaMount`. | +| 8 | 37-01 | `album.BackfillMailImages` idempotently indexes legacy `System\Models\MailImageLibrary` rows into folder `mail` via `legacy_file_id` without altering existing `/uploads/...` URLs (D-13). | VERIFIED | `modules/album/backfill.go`; proven by `TestBackfillMailImages`. | +| 9 | 37-01 | `modules/album/README.md` (with `**Name:**` mnemonic), root `README.md` row, and `docs/services/media-library.md` pass `summer docs:build --check` and `TestDocsTree` (D-01). | VERIFIED | `modules/album/README.md:7`, `README.md:94`, `docs/services/media-library.md`; re-run `scripts/check-phase37.sh --docs` passed (`TestDocsTree` + `docs:build: no problems found`). | +| 10 | 37-02 | `cabana` registers `media.view_media` and `media.manage_media` permissions (no default role grants) and `media:read` / `media` token scopes under `backend::lang.api_tokens.group_media` (D-04, D-11). | VERIFIED | `modules/cabana/backend_screens.go:29–35,127–173`; grep across `modules/cabana/` confirms zero default role grants. | +| 11 | 37-02 | `cabana` exposes all 11 `/media/*` REST endpoints gated by `media.view_media`/`media.manage_media` and classified in `token_routes_test.go` (D-04, D-05, D-09, D-10, D-11). | VERIFIED | `modules/cabana/media_routes.go`, `modules/cabana/http.go`, `modules/cabana/token_routes_test.go`; proven by `TestTokenRouteGates`, `TestMediaPermissionsMatrix`, `TestMediaTokenScopes`. | +| 12 | 37-02 | `DELETE /media/items/{id}` runs `album.DeleteItemInTx` inside `lagoon.Transaction` and deletes original + WebP variant blobs strictly via `lagoon.AfterCommit` (D-12). | VERIFIED | `modules/cabana/media_routes.go` uses `lagoon.Transaction` + `lagoon.AfterCommit`; proven by `TestMediaUploadLifecycleAndAfterCommitDelete`. | +| 13 | 37-02 | `cabana` compiles `type: mediafinder` YAML fields (`mode`, `multiple`, `folder`) into the form schema and OpenAPI spec (D-05). | VERIFIED | `modules/cabana/field_media.go`; proven by `TestMediaFinderFieldSchema`. | +| 14 | 37-02 | `GET/POST /mail/images` store new uploads into `modules/album` under folder `mail` (with idempotent `BackfillMailImages`) preserving `AdminMailImage` JSON and `MailBrandSetting.LogoFileID` resolution (D-13). | VERIFIED | `modules/cabana/mail_routes.go` & `modules/cabana/mail_admin.go`; proven by `TestMailImagesUnifiedOverAlbum`. | +| 15 | 37-02 | `pier` exposes all 7 `media_*` MCP tools (`prepare_upload`, `upload`, `list`, `get`, `update`, `delete`, `create_folder`) under guard `backend` with zero boot warnings and `pier.maxRequestBody = 8 << 20` (D-04, D-10). | VERIFIED | `modules/cabana/media_mcp.go:99–176`, `modules/surf/pier_on.go:28`, `modules/pier/pier.go:39` (`const maxRequestBody = 8 << 20`); proven by `TestMediaMCPTools`. | +| 16 | 37-02 | EN & PL phrasebooks define all media/permission/scope keys, and OpenAPI/TS schemas pass `scripts/check-admin-openapi.sh --check`. | VERIFIED | `modules/phrasebook/backend/lang/{en,pl}/lang.yaml`, `admin/openapi/admin.json`, `admin/src/api/schema.d.ts`, `37-VALIDATION.md`. | +| 17 | 37-03 | Administrators with `media.view_media` or `media.manage_media` see **Media** in `PluginRail.vue` leading to `/media` (`MediaView.vue`); others do not (D-05, D-11). | VERIFIED | `admin/src/components/shell/PluginRail.vue:203–210`, `admin/src/state/useMediaAccess.ts`, `admin/src/app/router.ts:76`. | +| 18 | 37-03 | `MediaView.vue` / `MediaBrowser.vue` / `MediaInspector.vue` support folder tree CRUD, grid/list views, debounced search, type filter, drag-and-drop upload, metadata edit, copy URL, and delete confirmation dialog warning about broken published URLs (D-05, D-12). | VERIFIED | `admin/src/components/media/MediaInspector.vue:266–274` (`ConfirmDialog` with `backend::lang.media.delete_confirm_body` in EN/PL warning published URLs stop displaying); proven by `MediaBrowser.test.ts`. | +| 19 | 37-03 | `MediaPickerModal.vue` wraps `MediaBrowser.vue` in a `reka-ui` dialog, and `MailImagePicker.vue` delegates to it without regressing mail insert/choose flows (D-05, D-13). | VERIFIED | `admin/src/components/mail/MailImagePicker.vue:5,42` delegates to `MediaPickerModal`; proven by `MediaPickerModal.test.ts` & `MailImagePicker.test.ts`. | +| 20 | 37-03 | `MediaFinderField.vue` is registered as `'mediafinder'` in `registry.ts` and supports single/multiple selection + preview + clear/remove (D-05). | VERIFIED | `admin/src/components/form/registry.ts:113,144` (`['mediafinder', MediaFinderField]`); proven by `MediaFinderField.test.ts`. | +| 21 | 37-03 | All API calls use generated OpenAPI types, `typecheck`/`build` pass, and `modules/boardwalk/dist` passes `scripts/check-admin-dist.sh`. | VERIFIED | `admin/src/api/media.ts`, `37-VALIDATION.md` (`check-admin-dist.sh` + `vue-tsc --noEmit` + Vitest 1776/1776). | +| 22 | 37-04 | `sm-journal-plugin` `POST /_journal/api/v1/media/upload` stores via `modules/album` (folder `journal` + sanitized subfolders) preserving `{data: {url, path}}` and additively returning `id`, `short_id`, `width`, `height`, `variants`, `srcset` (D-13). | VERIFIED | `../sm-journal-plugin/controllers/api/media.go:53–96` + `../sm-journal-plugin/classes/enrich_media.go:26–55`. | +| 23 | 37-04 | Existing `/uploads/...` inline image URLs in historical Journal posts remain completely untouched (D-13). | VERIFIED | `../sm-journal-plugin/classes/enrich_media.go:160–164` emits non-`/media//...` tags byte-for-byte unchanged. | +| 24 | 37-04 | Stored Journal post HTML stays clean; during API serialization (`Index`, `Show`, `Store`, `Update`, `AuthorPosts`), `sm-journal-plugin` enriches `/media//...` `` tags with `srcset`/`sizes` using a single batched `GetItemsByShortIDs` query (D-14). | VERIFIED | `../sm-journal-plugin/controllers/api/posts.go:144,209,685–734,788–792` (`batchLoadPostMedia` -> single `svc.GetItemsByShortIDs` call; `p.ContentHTML` in DB never mutated). | +| 25 | 37-04 | Journal Blog Editor exposes "Choose from Media Library" reusing the shared admin `MediaPickerModal` via `PluginField.vue` (D-05). | VERIFIED | `admin/src/components/form/fields/PluginField.vue` + `../sm-journal-plugin/assets/src/blogeditor/` (`summer-media-pick` / `summer-media-pick-result`); tested in `sm-journal-plugin` Vitest (258/258). | +| 26 | 37-04 | `vue-journal-layer` `sanitize-html` allow-list permits validated `srcset`, `sizes`, `width`, `height`, `loading`, and `decoding` on `` while stripping unsafe schemes (D-14). | VERIFIED | `../vue-journal-layer/app/utils/htmlGate.ts:78–83,135–145,212–236` (`allowedSrcset`, `allowedSizes`); tested by 204/204 TAP tests. | +| 27 | 37-04 | Local cross-repo verification uses temporary `GOWORK` / scratch `modfile` without dirtying submodule pointers or tagging releases (`AGENTS.md`). | VERIFIED | `scripts/check-phase37.sh:253–274,358–407`; `git status -s` in both sibling repos is completely clean. | +| 28 | 37-05 | Comprehensive Go unit & Postgres tests cover `modules/album` (migrations, folders, WebP variants, non-image attachment, SVG/HTML/JS & bomb rejection, no-dedup `sha256`, atomic upload tokens, `AfterCommit` delete, `BackfillMailImages`). | VERIFIED | `modules/album/album_test.go`, `modules/album/album_postgres_test.go` (5 unit + 7 Postgres tests passing in `37-VALIDATION.md`). | +| 29 | 37-05 | Go tests cover `cabana` media REST endpoints, permissions, scopes, `mediafinder`, unified `/mail/images`, `TestTokenRouteGates`, and `TestOpenAPIConformance`. | VERIFIED | `modules/cabana/media_routes_test.go`, `modules/cabana/media_postgres_test.go`, `modules/cabana/openapi_conformance_test.go`. | +| 30 | 37-05 | Go tests under `-tags summercms_mcp` verify all 7 `media_*` MCP tools, signed upload E2E, 5 MB base64 cap, scope filtering, and zero boot warnings. | VERIFIED | `modules/pier/media_mcp_test.go` (`TestMediaMCPTools`). | +| 31 | 37-05 | Go tests in `modules/surf` verify zero-DB-hit `/media/{short_id}/{file}` serving, headers, prefix collision rejection, and raw `/media/upload/{token}` mount. | VERIFIED | `modules/surf/media_test.go` (`TestMediaMount`). | +| 32 | 37-05 | Vitest component tests cover `MediaBrowser`, `MediaPickerModal`, and `MediaFinderField`. | VERIFIED | `admin/tests/media/MediaBrowser.test.ts`, `admin/tests/media/MediaPickerModal.test.ts`, `admin/tests/form/MediaFinderField.test.ts` (note: placed under `admin/tests/` to match `vitest.config.ts`). | +| 33 | 37-05 | `scripts/check-phase37.sh` runs all fail-closed gates (`--go`, `--docker`, `--admin`, `--docs`, `--consumers`, `--marker`). | VERIFIED | `scripts/check-phase37.sh` exists, executable, all 6 stages recorded PASS in `37-VALIDATION.md`; `--docs` and `--marker` independently re-verified PASS during this verification pass. | +| 34 | 37-05 | Zero release tags, zero tag pushes, zero downstream `go.mod`/submodule bumps, and zero changelog posts performed (`AGENTS.md` rule 5). | VERIFIED | Latest tags unchanged (`summercms.go`: `v0.6.9`, `sm-journal-plugin`: `v0.4.0`, `vue-journal-layer`: `v0.8.1`); sibling repos have clean `git status -s`; `../sm-journal-plugin/go.mod` untouched (`v0.6.1` + local dev replace). | + +**Score:** 34/34 truths verified. + +--- + +### Artifact Verification + +All promised artifacts across Plans `37-01` through `37-05` exist, are non-empty, and are wired into production code or test suites: + +- **Plan 37-01 (`modules/album`, `modules/lagoon`, `modules/surf`, `docs/`):** `album.go`, `migrations.go`, `models.go`, `service.go`, `variants.go`, `tokens.go`, `http.go`, `backfill.go`, `album_smoke_test.go`, `example_test.go`, `README.md`, `modules/surf/media.go`, `docs/services/media-library.md` — all present and wired. +- **Plan 37-02 (`modules/cabana`, `modules/pier`, `modules/phrasebook`, `admin/openapi/`):** `media_routes.go`, `media_mcp.go`, `field_media.go`, `admin/openapi/admin.json`, `admin/src/api/schema.d.ts`, `admin/src/api/types.ts` — all present and conformed. +- **Plan 37-03 (`admin/`, `modules/boardwalk/dist/`):** `admin/src/api/media.ts`, `MediaView.vue`, `MediaBrowser.vue`, `MediaFolderTree.vue`, `MediaInspector.vue`, `MediaPickerModal.vue`, `MediaFinderField.vue`, `useMediaAccess.ts`, `modules/boardwalk/dist/` — all present and in sync. +- **Plan 37-04 (`../sm-journal-plugin`, `../vue-journal-layer`):** `controllers/api/media.go`, `classes/enrich_media.go`, `controllers/api/posts.go`, `assets/dist/blogeditor.js`, `app/utils/htmlGate.ts` — all present and committed cleanly in their respective repos. +- **Plan 37-05 (tests & gate):** `modules/album/album_test.go`, `modules/album/album_postgres_test.go`, `modules/cabana/media_routes_test.go`, `modules/cabana/media_postgres_test.go`, `modules/pier/media_mcp_test.go`, `modules/surf/media_test.go`, `admin/tests/media/MediaBrowser.test.ts`, `admin/tests/media/MediaPickerModal.test.ts`, `admin/tests/form/MediaFinderField.test.ts`, `scripts/check-phase37.sh`, `.planning/phases/37-media-library-album/37-VALIDATION.md` — all present. + +--- + +### Key Links & Guardrails Verification + +| Check | Result | Evidence | +| --- | --- | --- | +| `modules/album` zero import of `modules/lagoon` (only `lagoon/attach*`) | PASS | `go list` shows only `modules/lagoon/attach` and `modules/lagoon/attach/webp`. | +| `modules/lagoon/migrations.go` -> `album.Migrations` | PASS | Line 230: `{"summercms.album", "media", album.Migrations}`. | +| `modules/surf/router.go` -> `mountMedia(r, app)` | PASS | Line 750 calls `mountMedia(r, app)` directly after `mountUploads`. | +| `modules/cabana` permissions (`media.view_media`, `media.manage_media`) with zero default role grants | PASS | Declared in `backend_screens.go`; zero default role grants anywhere in `modules/cabana/`. | +| `modules/cabana/media_routes.go` -> `lagoon.AfterCommit` blob cleanup | PASS | `mediaItemsDelete` wraps `DeleteItemInTx` in `lagoon.Transaction` + `lagoon.AfterCommit`. | +| `modules/surf/pier_on.go` -> `cabana.MediaMCPPlugin` + 8 MiB `pier.maxRequestBody` | PASS | `pier_on.go:28` mounts all 7 `media_*` tools; `modules/pier/pier.go:39` sets `const maxRequestBody = 8 << 20`. | +| `MediaInspector.vue` D-12 published-URL-breakage delete warning | PASS | `MediaInspector.vue:266–274` renders `ConfirmDialog` with `backend::lang.media.delete_confirm_body` (EN & PL). | +| `sm-journal-plugin` single batched query without mutating stored HTML | PASS | `controllers/api/posts.go:685–734,788–792` calls `svc.GetItemsByShortIDs` once per request and enriches serialized output only. | +| Release Ordering Guardrail (`AGENTS.md`) | PASS | Zero release tags created (`v0.6.9` / `v0.4.0` / `v0.8.1`), zero tag pushes, zero downstream `go.mod`/submodule bumps, zero changelog entries; sibling repos clean. | +| No consuming-app names in framework code/docs | PASS | `scripts/check-phase37.sh --marker` passed (`no consuming-app names added since v0.6.9`). | + +--- + +### Gaps & Human UAT Notes + +- **Automated Gaps:** None (`0` gaps found). +- **Release Lifecycle Note (`AGENTS.md`):** Per the Release Ordering Guardrail, ensure `/msd-code-review 37` (if not yet executed) and explicit user go-ahead are completed before cutting/pushing release tags, bumping downstream consumer `go.mod`/submodules, or publishing changelog entries. +- **Recommended Human UAT Spot-Checks (optional visual/UX confirmation):** + 1. Open `/media` in a running admin instance (both light and dark mode), verify folder tree navigation, drag-and-drop upload, inspector metadata save, copy URL, and the published-URL-breakage warning dialog on delete. + 2. Insert an image via the Blog Editor's "Choose from Media Library" toolbar button and confirm the published Journal page renders `` in SSR HTML with zero hydration mismatch. + 3. Open `/account/tokens` / MCP consent screen and verify the **Media** group displays `media:read` and `media` scopes cleanly in `ScopePicker`.