133 lines
10 KiB
Markdown
133 lines
10 KiB
Markdown
---
|
||
title: '2.6 — Завершить OpenAPI upload UX и release evidence'
|
||
type: 'feature'
|
||
created: '2026-08-28'
|
||
status: 'done'
|
||
baseline_commit: 'd2849ea3fef50ff62e08ae537c8eec46d195f040'
|
||
review_loop_iteration: 0
|
||
context:
|
||
- '_bmad-output/implementation-artifacts/epic-2-context.md'
|
||
- '_bmad-output/implementation-artifacts/spec-2-5-openapi-upload-preview.md'
|
||
---
|
||
|
||
<frozen-after-approval reason="human-owned intent — do not modify unless human renegotiates">
|
||
|
||
## Intent
|
||
|
||
**Problem:** OpenAPI modal по-прежнему превращает файл в текст и отправляет legacy JSON `{document}`, поэтому после Story 2.5 production upload из UI не работает. Асинхронный flow не защищён от replacement/close/workspace races, почти полностью hardcoded на RU и не даёт воспроизводимого release evidence.
|
||
|
||
**Approach:** Сделать выбранный `File` единственным authoritative ingress, отправлять его multipart через общий authenticated API client и оформить preview/apply как отменяемую revision-guarded state machine с безопасной RU/EN диагностикой, accessibility и real-stack Playwright evidence.
|
||
|
||
## Boundaries & Constraints
|
||
|
||
**Always:** Один `.yaml|.yml|.json` файл размером 1..256 KiB; browser сам формирует multipart boundary; backend остаётся security authority. Replacement, reset, close, workspace/language change и navigation отменяют request и инвалидируют поздний response. UI показывает только bounded filename/size, actionable localized message и canonical Request ID/Trace ID; File/raw source, digest, source ID и path не попадают в DOM diagnostics, logs или evidence. Apply допускает только один in-flight request и сохраняет backend idempotency authority.
|
||
|
||
**Ask First:** Изменение backend contract 2.5; новый production dependency; изменение capability-baseline schema/accepted evidence; сохранение preview после закрытия modal или смены workspace.
|
||
|
||
**Never:** Legacy JSON preview или textarea/paste fallback; client-side parser/security authority; NormalizedIR/support matrix/external `$ref`/partial mode/new conflict semantics из 2.7+; auto-publish; raw Playwright trace/video/source как release evidence.
|
||
|
||
## I/O & Edge-Case Matrix
|
||
|
||
| Scenario | Input / State | Expected Output / Behavior | Error Handling |
|
||
|----------|---------------|----------------------------|----------------|
|
||
| Upload/apply | Valid YAML/JSON File | Multipart preview, selectable methods, single create и Draft result | Loading/status announced; repeat apply reuses canonical job semantics |
|
||
| Local reject | No file, bad extension/type, empty или >256 KiB | No request/job/preview; control remains retryable | Localized bounded recovery without invented IDs |
|
||
| Server/network reject | Parse/413/4xx/5xx или ambiguous network failure | Previous authority is not silently replaced | Safe RU/EN message; display Request/Trace IDs only when received; explicit retry |
|
||
| Cancel/stale | A→B replacement, reset/close/workspace/language/navigation during preview/apply | A aborted or ignored; B/current context alone may render or mutate UI | `cancelled` is not shown as backend failure; stale job/selection/result cleared |
|
||
| Accessibility | Keyboard, screen reader, reduced motion | Focus enters/restores, Escape closes, status/error announced, meaning not color-only | Error focuses recovery/status without trapping the user |
|
||
|
||
</frozen-after-approval>
|
||
|
||
## Code Map
|
||
|
||
- `apps/ui/js/api.js:218-245,412-419` — reuse common credentials/CSRF/error correlation; multipart body must bypass JSON serialization and accept `signal` without setting `Content-Type`.
|
||
- `apps/ui/js/openapi-import.js:1-548` — replace raw textarea flow; add File/revision/controllers/state transitions, current-context guards, safe diagnostics and lifecycle listeners. Reuse render/filter/apply result code.
|
||
- `apps/ui/js/{onboarding.js,catalog.js,secrets.js}` — read-only examples for AbortController, generation and workspace identity guards.
|
||
- `apps/ui/index.html:380-451`, `apps/ui/css/openapi-import.css` — file-only modal, cancel/retry/status semantics, focus and reduced-motion behavior.
|
||
- `apps/ui/js/i18n.js` — add complete EN/RU OpenAPI keys; no new hardcoded user-facing copy.
|
||
- `apps/ui/tests/e2e/operations.spec.js` — convert happy path to `setInputFiles`; add deterministic multipart, validation, replacement/cancel/stale, correlation, RU/EN, keyboard and double-create evidence against real Admin API where applicable.
|
||
- `apps/ui/{playwright.config.js,package.json}`, `.gitea/workflows/{ci.yml,release.yml}`, `scripts/collect-capability-baseline.py` — reuse pinned Playwright and sanitized count-only collector; produce deterministic JSON evidence without publishing raw source artifacts.
|
||
- `docs/openapi-import.md`, `docs/{admin-api.md,production-checklist.md}` — document multipart limit, state/recovery contract, artifact lifecycle/backup coordination and redacted diagnostics.
|
||
- `apps/admin-api/src/{app.rs,routes/imports.rs,service/imports.rs}` — read-only 2.5 production authority unless a demonstrated UI boundary defect requires Ask First.
|
||
|
||
## Tasks & Acceptance
|
||
|
||
**Execution:**
|
||
- [x] `apps/ui/js/{api.js,openapi-import.js,i18n.js}` — implement file-only multipart transport, localized cancellable state machine, correlation recovery and stale/apply guards.
|
||
- [x] `apps/ui/{index.html,css/openapi-import.css}` — provide accessible file/cancel/retry/status UI with focus restoration and reduced-motion support.
|
||
- [x] `apps/ui/tests/e2e/operations.spec.js` — cover the complete matrix with real upload→preview→apply plus deterministic intercepted race/error scenarios that assert multipart shape and no canary leakage.
|
||
- [x] `apps/ui/{playwright.config.js,package.json}`, `.gitea/workflows/{ci.yml,release.yml}`, `scripts/collect-capability-baseline.py` — emit and validate sanitized Playwright release evidence for the OpenAPI flow.
|
||
- [x] `docs/{openapi-import.md,admin-api.md,production-checklist.md}` — align operator/user documentation with the shipped contract and recovery model.
|
||
|
||
**Acceptance Criteria:**
|
||
- Given current File/workspace/language revision, when any async preview/apply settles, then only that exact revision may change job, selection, status or result and no duplicate Draft mutation is initiated.
|
||
- Given RU or EN UI and any local/backend failure, when recovery is rendered, then it is keyboard/screen-reader usable, contains canonical correlation only when available and exposes no raw source or internal artifact identity.
|
||
- Given CI/release verification, when OpenAPI evidence is collected, then the real multipart flow passes and the tracked artifact contains only bounded schema-valid metadata/counts tied to the source revision.
|
||
|
||
## Spec Change Log
|
||
|
||
## Design Notes
|
||
|
||
`File` остаётся в памяти только в текущей modal revision. Каждое destructive context change сначала увеличивает revision и aborts controllers, затем очищает job/preview/result. `AbortError` переводит текущий flow в `cancelled`; ответ старой revision не делает ничего. Local validation улучшает UX, но не заменяет identical backend checks.
|
||
|
||
## Verification
|
||
|
||
**Commands:**
|
||
- `cd apps/ui && npm run build` — production bundle собирается без legacy textarea path.
|
||
- `cd apps/ui && npx playwright test tests/e2e/operations.spec.js --workers=1` — multipart happy path и UI edge matrix проходят.
|
||
- `just ui-e2e` — полный real-stack UI regression проходит.
|
||
- `python3 scripts/validate-capability-baseline.py docs/capability-baseline/manifest.json` — evidence остаётся schema-valid и redacted.
|
||
- `cargo fmt --all --check && cargo clippy --workspace --all-targets --all-features -- -D warnings && just rust-boundaries && just rust-code-health` — workspace gates чисты.
|
||
|
||
## Suggested Review Order
|
||
|
||
**Production upload boundary**
|
||
|
||
- Multipart route задаёт единственный file-only ingress и bounded validation.
|
||
[`imports.rs:28`](../../apps/admin-api/src/routes/imports.rs#L28)
|
||
|
||
- Service связывает immutable artifact source, preview job и verified apply.
|
||
[`imports.rs:35`](../../apps/admin-api/src/service/imports.rs#L35)
|
||
|
||
- Registry cleanup завершает lifecycle истёкших jobs и dangling sources.
|
||
[`import_job.rs:146`](../../crates/crank-registry/src/postgres/import_job.rs#L146)
|
||
|
||
**UI state machine and safety**
|
||
|
||
- Modal state machine централизует revision, abort, stale-response и safe diagnostics.
|
||
[`openapi-import.js:442`](../../apps/ui/js/openapi-import.js#L442)
|
||
|
||
- Browser формирует multipart boundary и передаёт cancellation signal.
|
||
[`api.js:412`](../../apps/ui/js/api.js#L412)
|
||
|
||
- Apply guard допускает только одну текущую Draft-мутацию.
|
||
[`openapi-import.js:674`](../../apps/ui/js/openapi-import.js#L674)
|
||
|
||
- Context listeners инвалидируют language, workspace, cross-tab и navigation races.
|
||
[`openapi-import.js:843`](../../apps/ui/js/openapi-import.js#L843)
|
||
|
||
- Accessible modal предоставляет file activation, live status и focus contract.
|
||
[`index.html:380`](../../apps/ui/index.html#L380)
|
||
|
||
**Release evidence**
|
||
|
||
- Collector fail-closed связывает evidence с обязательными OpenAPI test titles.
|
||
[`collect-capability-baseline.py:82`](../../scripts/collect-capability-baseline.py#L82)
|
||
|
||
- Candidate validator отдельно требует schema-valid accepted evidence.
|
||
[`validate-capability-run.py:125`](../../scripts/validate-capability-run.py#L125)
|
||
|
||
- Release сохраняет sanitized evidence в dist и включает его checksum.
|
||
[`release.yml:129`](../../.gitea/workflows/release.yml#L129)
|
||
|
||
**Verification and operations**
|
||
|
||
- Real-stack suite покрывает multipart happy path и полный stale/error matrix.
|
||
[`operations.spec.js:26`](../../apps/ui/tests/e2e/operations.spec.js#L26)
|
||
|
||
- User guide фиксирует recovery, retention и redacted diagnostics.
|
||
[`openapi-import.md:19`](../../docs/openapi-import.md#L19)
|
||
|
||
- Production checklist задаёт допустимый release evidence contract.
|
||
[`production-checklist.md:53`](../../docs/production-checklist.md#L53)
|