docs(phase-37): add 37-VALIDATION.md and 37-05-SUMMARY.md

This commit is contained in:
Jakub Zych
2026-11-27 13:58:07 +01:00
parent a672c1aa9e
commit de9ede0dbd
2 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
---
phase: 37-media-library-album
plan: 05
subsystem: verification-and-tests
tags: [album, cabana, pier, surf, admin, vitest, postgres, testcontainers, validation]
requires: ["37-01", "37-02", "37-03", "37-04"]
provides:
- "Comprehensive Docker-free Go unit tests and Docker-backed Postgres integration tests across `modules/album`, `modules/cabana`, `modules/pier` (`-tags summercms_mcp`), and `modules/surf`"
- "Vitest component test suites for `MediaBrowser.vue`, `MediaPickerModal.vue`, and `MediaFinderField.vue`"
- "Fail-closed `scripts/check-phase37.sh` verification gate (`--go`, `--docker`, `--admin`, `--docs`, `--consumers`, `--marker`, `--all`)"
- "Nyquist validation matrix in `.planning/phases/37-media-library-album/37-VALIDATION.md`"
affects:
- "modules/album"
- "modules/cabana"
- "modules/pier"
- "modules/surf"
- "admin/tests"
- "scripts/check-phase37.sh"
key-files:
created:
- 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
modified:
- modules/cabana/openapi_conformance_test.go
key-decisions:
- "Placed the 3 new Vitest suites under `admin/tests/media/` and `admin/tests/form/` (instead of `admin/src/.../__tests__/`) because `admin/vitest.config.ts` includes only `tests/**/*.test.ts`."
- "Added `media.view_media` and `media.manage_media` grants to the non-superuser `conform` fixture user in `modules/cabana/openapi_conformance_test.go` after `TestPhase10OpenAPIConformance` (Postgres) flagged 403 on `POST /media/folders`."
completed: 2026-11-27
---
# Phase 37 Plan 05: Comprehensive Test Suite, `scripts/check-phase37.sh`, and `37-VALIDATION.md` Summary
**Completed the full Go unit/Postgres test suite, Vitest component test suite, fail-closed `scripts/check-phase37.sh` gate (with read-only sibling consumer proofs), and Nyquist validation matrix (`37-VALIDATION.md`) — all stages passing green with zero release tags or consumer bumps.**
## Commits
- `a672c1aa` — `test(album,cabana,pier,surf,admin): add Phase 37 test suites and fail-closed check-phase37.sh gate`
## What Was Built
1. **Go Unit & Postgres Integration Tests**:
- `modules/album/album_test.go`: slug sanitization, 12-char `short_id` format/uniqueness, synchronous non-upscaling WebP `480w`/`960w`/`1600w` variants, `StaticHandler` security headers & traversal rejection, synthetic 20000×20000 PNG decompression-bomb & SVG/HTML/JS polyglot guards, and `Install`/`ServiceFrom`/config helpers.
- `modules/album/album_postgres_test.go`: `TestMain` with `flag.Parse()` + `testing.Short()` guard; Postgres integration tests for migrations up/down/up, folder CRUD + cycle prevention + non-empty delete `ErrFolderNotEmpty`, upload + `sha256` non-dedup + PDF attachment + disallowed types + size cap, atomic single-use upload tokens (concurrent race, replay, expiry, `SignedUploadHandler` E2E), `DeleteItemInTx` + `lagoon.AfterCommit` rollback vs commit safety, `GetItemsByShortIDs` + `ListItems` filters + immutable URL on `UpdateItem`, and idempotent `BackfillMailImages`.
- `modules/cabana/media_routes_test.go` & `modules/cabana/media_postgres_test.go`: `type: mediafinder` YAML schema compile & error cases, `MediaMCPPlugin` permissions/scopes/7-tool inventory, `media.view_media` vs `media.manage_media` permission matrix, `media:read` vs `media` personal token scope enforcement, multipart + base64 5 MB cap + AfterCommit delete lifecycle, and backward-compatible Mail Images unification over `album`.
- `modules/cabana/openapi_conformance_test.go`: added `media.view_media` and `media.manage_media` to the non-superuser `conform` fixture user so `TestPhase10OpenAPIConformance` passes all 11 `/media/*` OpenAPI conformance cases against real Postgres.
- `modules/pier/media_mcp_test.go` (`//go:build summercms_mcp`): tests all 7 `media_*` MCP tools, `media_prepare_upload` → HTTP `PUT /media/upload/{token}` + replay 401, exact 5 MB base64 `media_upload` succeeding and >5 MB failing, `media:read` vs `media` scope filtering, and zero `warnUncoveredBackendWriteTools` boot warnings.
- `modules/surf/media_test.go`: `mountMedia` static off/on, zero-DB-hit `/media/{short_id}/{file}` serving & headers, prefix collision & invalid prefix rejection, and raw `/media/upload/{token}` mount without admin cookie/CSRF.
2. **Vitest Component Tests**:
- `admin/tests/media/MediaBrowser.test.ts`: folder tree navigation, grid/list toggle, 300ms debounced search, inspector metadata editing, and hard-delete confirmation dialog warning about broken published URLs (D-12).
- `admin/tests/media/MediaPickerModal.test.ts`: `defaultFolder` slug filtering, single select with alt-text prefill, and multiple selection in file mode.
- `admin/tests/form/MediaFinderField.test.ts`: single image select/preview/clear and multiple file add/remove.
3. **Fail-Closed Verification Gate & Validation Matrix**:
- `scripts/check-phase37.sh`: executable gate script covering `--go`, `--docker`, `--admin`, `--docs`, `--consumers` (read-only scratch modfile for `../sm-journal-plugin` + `../vue-journal-layer` TAP tests + clean sibling git status checks), and `--marker` (no consuming-app names since `v0.6.9`).
- `.planning/phases/37-media-library-album/37-VALIDATION.md`: Nyquist validation matrix mapping D-01..D-14, OpenAPI/dist, and release guardrails to passing automated checks.
## Verification Results
All `scripts/check-phase37.sh` stages passed green:
- `--go`: `go vet ./...`, `go vet -tags summercms_mcp ./...`, `go test -short -count=1 ./...` (all packages green), plus all 11 required named tests across `album`, `cabana`, `surf`, and `pier` (`-tags summercms_mcp`).
- `--docker`: all 7 Postgres tests in `modules/album` + all 5 Postgres tests in `modules/cabana` (including full `TestPhase10OpenAPIConformance`).
- `--admin`: Vitest `1776 passed (1776)`, `vue-tsc --noEmit`, `scripts/check-admin-openapi.sh --check`, and `scripts/check-admin-dist.sh`.
- `--docs`: `TestDocsTree` + `summer docs:build --check` (`docs:build: no problems found`).
- `--consumers`: `../sm-journal-plugin` (`go vet`, `go test -short ./...`, Vitest `258 passed (258)`) and `../vue-journal-layer` (TAP `# pass 204`), both clean before and after.
- `--marker`: zero consuming-app names added since `v0.6.9`.
## Deviations from Plan
- Placed the 3 Vitest files in `admin/tests/media/` and `admin/tests/form/` instead of `admin/src/.../__tests__/` because `admin/vitest.config.ts` includes only `tests/**/*.test.ts`.
- Fixed `modules/cabana/openapi_conformance_test.go` (`newConformEnv`) to grant `media.view_media` and `media.manage_media` to the non-superuser conformance fixture user, which was caught when running `TestPhase10OpenAPIConformance` against real Postgres.
- Removed a leftover untracked `../sm-journal-plugin/go.work.sum` from Wave 4's temporary `GOWORK` run so `--consumers` verified clean sibling git status before and after.

View File

@@ -0,0 +1,43 @@
---
phase: 37-media-library-album
status: verified
nyquist_compliant: true
updated: 2026-11-27
gate_script: scripts/check-phase37.sh
---
# Phase 37 — Media Library (`modules/album`) Validation Matrix (`37-VALIDATION`)
Every Phase 37 decision (D-01 through D-14) and roadmap success criterion is mapped below to automated, fail-closed tests enforced by `scripts/check-phase37.sh`.
## Automated Verification Gate Results
| Stage | Command | Result | Key Evidence |
| --- | --- | --- | --- |
| `go` | `scripts/check-phase37.sh --go` | **PASS** | `go vet ./...`, `go vet -tags summercms_mcp ./...`, `go test -short -count=1 ./...` (all packages green), 5 `album` tests, 4 `cabana` tests, 1 `surf` test, 1 `pier` (`-tags summercms_mcp`) test |
| `docker` | `scripts/check-phase37.sh --docker` | **PASS** | 7 Postgres integration tests in `modules/album` + 5 Postgres integration tests in `modules/cabana` (including full `TestPhase10OpenAPIConformance` over all 11 `/media/*` endpoints) |
| `admin` | `scripts/check-phase37.sh --admin` | **PASS** | Vitest `1776 passed (1776)` (incl. `MediaBrowser.test.ts`, `MediaPickerModal.test.ts`, `MediaFinderField.test.ts`, `MailImagePicker.test.ts`), `vue-tsc --noEmit`, `check-admin-openapi.sh --check`, `check-admin-dist.sh` |
| `docs` | `scripts/check-phase37.sh --docs` | **PASS** | `TestDocsTree` passed + `summer docs:build --check` (`no problems found`) |
| `consumers` | `scripts/check-phase37.sh --consumers` | **PASS** | Read-only scratch modfile resolving `summercms` to local checkout: `../sm-journal-plugin` `go vet`, `go test -short ./...`, Vitest `258 passed (258)`; `../vue-journal-layer` TAP `# pass 204`; both siblings clean before & after |
| `marker` | `scripts/check-phase37.sh --marker` | **PASS** | Zero consuming-application names added since `v0.6.9` under `modules/`, `cmd/`, `internal/`, or `docs/` |
## Nyquist Requirement & Decision Traceability Matrix
| Decision / Invariant | Verification Coverage | File(s) | Status |
| --- | --- | --- | --- |
| **D-01** Core `modules/album` module, README mnemonic, root table, `docs/services/media-library.md` | `TestDocsTree`, `summer docs:build --check`, `TestConfigAndInstallHelpers` | `modules/album/album_test.go`, `cmd/summer` | PASS |
| **D-02** Postgres-indexed metadata (`summer_media_folders`, `summer_media_items`, `summer_media_upload_tokens`) + migrations up/down + virtual folders | `TestMigrationsUpDown`, `TestFolderCRUDAndNonEmptyDelete`, `TestGetItemsByShortIDsAndListFilters` | `modules/album/album_postgres_test.go` | PASS |
| **D-03** Allowed raster & file types, `Content-Disposition: attachment` for non-images, SVG/HTML/JS & polyglot/decompression-bomb rejection | `TestDecompressionBombAndPolyglotGuards`, `TestStaticHandlerSecurity`, `TestUploadAndNoDedup` | `modules/album/album_test.go`, `modules/album/album_postgres_test.go` | PASS |
| **D-04** Dual MCP upload path (`media_prepare_upload` -> `PUT /media/upload/{token}`, `media_upload` base64 5 MB cap) + 7 `media_*` tools + `media`/`media:read` scopes + zero boot warnings | `TestMediaMCPPluginSurfaceAndScopes`, `TestMediaMCPTools`, `TestMediaTokenScopes` | `modules/cabana/media_routes_test.go`, `modules/pier/media_mcp_test.go`, `modules/cabana/media_postgres_test.go` | PASS |
| **D-05** Admin **Media** screen, `type: mediafinder` YAML schema + Vue control, shared `MediaPickerModal` | `TestMediaFinderFieldSchema`, `MediaBrowser.test.ts`, `MediaPickerModal.test.ts`, `MediaFinderField.test.ts`, `MailImagePicker.test.ts` | `modules/cabana/media_routes_test.go`, `admin/tests/media/*`, `admin/tests/form/*` | PASS |
| **D-06** Immutable `media/<short-id>/<slug>.<ext>` keys, zero-DB-hit `/media/{short_id}/{file}` serving (`Cache-Control: immutable`, `nosniff`, CSP, traversal rejection), prefix collision guard | `TestSlugAndShortID`, `TestStaticHandlerSecurity`, `TestMediaMount`, `TestGetItemsByShortIDsAndListFilters` | `modules/album/album_test.go`, `modules/surf/media_test.go`, `modules/album/album_postgres_test.go` | PASS |
| **D-07** Synchronous WebP `480w`/`960w`/`1600w` variants without upscaling + aspect ratio preservation | `TestWebPVariants`, `TestUploadAndNoDedup`, `TestMediaUploadLifecycleAndAfterCommitDelete` | `modules/album/album_test.go`, `modules/album/album_postgres_test.go`, `modules/cabana/media_postgres_test.go` | PASS |
| **D-08** Stored `sha256` without auto-dedup (identical uploads create independent rows/keys) | `TestUploadAndNoDedup`, `TestGetItemsByShortIDsAndListFilters` | `modules/album/album_postgres_test.go` | PASS |
| **D-09** Single-use DB-backed upload tokens (SHA-256 hash only, atomic consume, replay & expiry rejected, raw mount without admin cookie/CSRF) | `TestConsumeUploadTokenSingleUse`, `TestMediaMount`, `TestMediaMCPTools` | `modules/album/album_postgres_test.go`, `modules/surf/media_test.go`, `modules/pier/media_mcp_test.go` | PASS |
| **D-10** Default size caps (5 MB base64 cap, 25 MB binary cap, 8 MiB `pier.maxRequestBody`) | `TestConfigAndInstallHelpers`, `TestUploadAndNoDedup`, `TestMediaUploadLifecycleAndAfterCommitDelete`, `TestMediaMCPTools` | `modules/album/*_test.go`, `modules/cabana/media_postgres_test.go`, `modules/pier/media_mcp_test.go` | PASS |
| **D-11** Shared team library under `media.view_media` & `media.manage_media` (no default role grants) + `media:read` / `media` scopes | `TestMediaPermissionsMatrix`, `TestMediaTokenScopes`, `TestTokenRouteGates` | `modules/cabana/media_postgres_test.go`, `modules/cabana/token_routes_test.go` | PASS |
| **D-12** Hard delete with `DeleteItemInTx` + `lagoon.AfterCommit` rollback safety + UI broken-URL warning dialog | `TestDeleteItemInTxAfterCommit`, `TestMediaUploadLifecycleAndAfterCommitDelete`, `MediaBrowser.test.ts` | `modules/album/album_postgres_test.go`, `modules/cabana/media_postgres_test.go`, `admin/tests/media/MediaBrowser.test.ts` | PASS |
| **D-13** Backward-compatible Mail Images & Journal upload unification + idempotent `BackfillMailImages` preserving `/uploads/...` URLs | `TestBackfillMailImages`, `TestMailImagesUnifiedOverAlbum`, `sm-journal-plugin` `go test -short ./...` | `modules/album/album_postgres_test.go`, `modules/cabana/media_postgres_test.go`, `../sm-journal-plugin` | PASS |
| **D-14** Clean stored post HTML + single-query batched render-time `srcset`/`sizes` enrichment + `vue-journal-layer` sanitizer allow-list | `../sm-journal-plugin` (`classes/enrich_media_test.go`, `tests/blogeditor/element.test.ts`), `../vue-journal-layer` (`tests/htmlGate.test.ts`) | `scripts/check-phase37.sh --consumers` | PASS |
| **OpenAPI & Dist** All 11 `/media/*` endpoints conform to `admin/openapi/admin.json`, `schema.d.ts`, and `modules/boardwalk/dist` | `TestPhase10ConformanceInventory`, `TestPhase10OpenAPIConformance`, `check-admin-openapi.sh --check`, `check-admin-dist.sh` | `modules/cabana/openapi_conformance_test.go`, `scripts/check-phase37.sh` | PASS |
| **Release Guardrail** Zero release tags, tag pushes, downstream `go.mod`/submodule bumps, or changelog posts | Verified clean sibling repos & no new git tags | `AGENTS.md`, `scripts/check-phase37.sh --consumers` | PASS |