mirror of
https://github.com/azaion/ui.git
synced 2026-06-21 14:31:10 +00:00
1dd25edee3
AZ-466 — Destructive UX policy + ConfirmDialog a11y + no-alert (4pts):
src/components/ConfirmDialog.test.tsx (8 fast),
tests/destructive_ux.test.tsx (4 fast, AdminPage class-delete drift),
e2e/tests/destructive_ux.e2e.ts. New static checks STC-SEC7 (alert
allowlist) + STC-SEC8 (destructive-surfaces gated/drift) wired through
scripts/check-banned-deps.mjs reading tests/security/banned-deps.json.
AZ-475 — Numeric form input rejection (2pts):
tests/form_hygiene.test.tsx (3 fast). Documents two SettingsPage drifts:
silent zero coercion via parseInt(v)||0 and labels missing htmlFor.
AZ-462 — Overlay membership at in-window edges (2pts):
tests/overlay_membership.test.tsx (6 fast). Documents getTimeWindowDetections
strict < drift; AC-1 boundary tests are it.fails(); AC-2 / control PASS.
Mocks HTMLCanvasElement.getContext to capture strokeRect.
AZ-460 — Annotation save URL + payload contract (2pts):
tests/annotations_endpoint.test.tsx (6 fast),
e2e/tests/annotations_endpoint.e2e.ts. AC-1 URL canary PASSes; AC-2
payload missing 4 fields documented as it.fails(); AC-3 manual-draw
PASS, AI-suggestion-accept + bulk-edit-save QUARANTINE skip.
Test infrastructure:
- tests/setup.ts: NoopResizeObserver + NoopEventSource JSDOM polyfills.
- tests/msw/handlers/annotations.ts: doubly-prefixed paths matching
production calls (e.g. /api/annotations/annotations).
- tests/msw/handlers/flights.ts: plural /aircrafts paths.
Verification: bun run test:fast → 80 passed, 13 skipped (14 files).
scripts/run-tests.sh --static-only → 24/24 PASS (was 22; +STC-SEC7/SEC8).
Per-batch self-review verdict: PASS_WITH_WARNINGS. Cumulative review
of batches 04-06 due after batch 6 per implement/SKILL.md Step 14.5.
Report: _docs/03_implementation/batch_04_report.md.
Also includes the previously-untracked
_docs/03_implementation/cumulative_review_batches_01-03_report.md
generated at the start of this session before batch 4 began.
Co-authored-by: Cursor <cursoragent@cursor.com>
151 lines
6.0 KiB
TypeScript
151 lines
6.0 KiB
TypeScript
import { http } from 'msw'
|
|
import { jsonResponse, noContent, paginate, sse } from '../helpers'
|
|
import { seedMedia } from '../../fixtures/seed_media'
|
|
import { seedAnnotations } from '../../fixtures/seed_annotations'
|
|
import { seedUserSettings } from '../../fixtures/seed_user_settings'
|
|
|
|
// Default `/api/annotations/*` handlers — media list, annotation CRUD, dataset,
|
|
// status SSE. The annotation status SSE returns a small canned event sequence
|
|
// so dataset / annotations tests don't have to register their own stream just
|
|
// to mount a component.
|
|
|
|
export const annotationsHandlers = [
|
|
http.get('/api/annotations/media', ({ request }) => {
|
|
const url = new URL(request.url)
|
|
const page = Number(url.searchParams.get('page') ?? '1')
|
|
const pageSize = Number(url.searchParams.get('pageSize') ?? String(seedMedia.length))
|
|
return jsonResponse(paginate(seedMedia, page, pageSize))
|
|
}),
|
|
|
|
http.get('/api/annotations/media/:id', ({ params }) => {
|
|
const m = seedMedia.find((x) => x.id === params.id)
|
|
if (!m) return new Response(null, { status: 404 })
|
|
return jsonResponse(m)
|
|
}),
|
|
|
|
http.get('/api/annotations/media/:id/annotations', ({ params }) =>
|
|
jsonResponse(seedAnnotations.filter((a) => a.mediaId === params.id)),
|
|
),
|
|
|
|
// Production routes use the doubly-prefixed canary `/api/annotations/annotations/*`
|
|
// — gateway prefix `/api/annotations/` + service base `/annotations/`. AZ-460 AC-1
|
|
// pins this path; the static check would catch a single-prefix regression.
|
|
http.get('/api/annotations/annotations', ({ request }) => {
|
|
const url = new URL(request.url)
|
|
const mediaId = url.searchParams.get('mediaId')
|
|
const items = mediaId ? seedAnnotations.filter((a) => a.mediaId === mediaId) : seedAnnotations
|
|
const page = Number(url.searchParams.get('page') ?? '1')
|
|
const pageSize = Number(url.searchParams.get('pageSize') ?? String(items.length))
|
|
return jsonResponse(paginate(items, page, pageSize))
|
|
}),
|
|
|
|
http.post('/api/annotations/annotations', async ({ request }) => {
|
|
const body = (await request.json()) as Record<string, unknown>
|
|
return jsonResponse({ id: 'ann-new', createdDate: new Date().toISOString(), ...body }, { status: 201 })
|
|
}),
|
|
|
|
http.patch('/api/annotations/annotations/:id/status', async ({ request, params }) => {
|
|
const body = (await request.json()) as { status?: number }
|
|
return jsonResponse({ id: params.id, status: body.status ?? 10 })
|
|
}),
|
|
|
|
http.delete('/api/annotations/annotations/:id', () => noContent()),
|
|
|
|
// Single-prefix variants kept for backward compatibility with existing tests
|
|
// that may rely on them. Production uses doubly-prefixed (above).
|
|
http.get('/api/annotations', () => jsonResponse(seedAnnotations)),
|
|
http.post('/api/annotations', async ({ request }) => {
|
|
const body = (await request.json()) as Record<string, unknown>
|
|
return jsonResponse({ id: 'ann-new', createdDate: new Date().toISOString(), ...body }, { status: 201 })
|
|
}),
|
|
http.patch('/api/annotations/:id/status', async ({ request, params }) => {
|
|
const body = (await request.json()) as { status?: number }
|
|
return jsonResponse({ id: params.id, status: body.status ?? 10 })
|
|
}),
|
|
http.delete('/api/annotations/:id', () => noContent()),
|
|
|
|
http.get('/api/annotations/dataset', () =>
|
|
jsonResponse(
|
|
seedAnnotations.map((a) => ({
|
|
annotationId: a.id,
|
|
imageName: `image-${a.mediaId}.jpg`,
|
|
thumbnailPath: `/thumbs/${a.mediaId}.jpg`,
|
|
status: a.status,
|
|
createdDate: a.createdDate,
|
|
createdEmail: 'op_alice@test.local',
|
|
flightName: 'Flight 1',
|
|
source: a.source,
|
|
isSeed: false,
|
|
isSplit: a.isSplit,
|
|
})),
|
|
),
|
|
),
|
|
|
|
http.post('/api/annotations/dataset/bulk-status', async ({ request }) => {
|
|
const body = (await request.json()) as { ids?: string[]; status?: number }
|
|
return jsonResponse({ updated: body.ids?.length ?? 0, status: body.status ?? 30 })
|
|
}),
|
|
|
|
http.get('/api/annotations/dataset/distribution', () =>
|
|
jsonResponse([
|
|
{ classNum: 0, label: 'class-0', color: '#ff0000', count: 12 },
|
|
{ classNum: 1, label: 'class-1', color: '#00ff00', count: 7 },
|
|
]),
|
|
),
|
|
|
|
http.get('/api/annotations/status', () =>
|
|
sse([
|
|
{ event: 'status', data: { annotationId: seedAnnotations[0]?.id ?? 'ann-1', status: 20 }, id: '1' },
|
|
{ event: 'status', data: { annotationId: seedAnnotations[0]?.id ?? 'ann-1', status: 30 }, id: '2' },
|
|
]),
|
|
),
|
|
|
|
http.get('/api/annotations/users/:userId/settings', ({ params }) => {
|
|
const s = seedUserSettings.find((x) => x.userId === params.userId)
|
|
if (!s) return new Response(null, { status: 404 })
|
|
return jsonResponse(s)
|
|
}),
|
|
|
|
http.put('/api/annotations/users/:userId/settings', async ({ request, params }) => {
|
|
const body = (await request.json()) as Record<string, unknown>
|
|
return jsonResponse({ id: 'user-settings-1', userId: params.userId, ...body })
|
|
}),
|
|
|
|
// System / directory settings — used by `<SettingsPage>` (production paths).
|
|
http.get('/api/annotations/settings/system', () =>
|
|
jsonResponse({
|
|
id: 'sys-settings-1',
|
|
name: 'Test System',
|
|
militaryUnit: null,
|
|
defaultCameraWidth: 1920,
|
|
defaultCameraFoV: 60,
|
|
}),
|
|
),
|
|
http.put('/api/annotations/settings/system', async ({ request }) =>
|
|
jsonResponse(await request.json()),
|
|
),
|
|
http.get('/api/annotations/settings/directories', () =>
|
|
jsonResponse({
|
|
id: 'dirs-1',
|
|
videosDir: '/srv/videos',
|
|
imagesDir: '/srv/images',
|
|
labelsDir: '/srv/labels',
|
|
resultsDir: '/srv/results',
|
|
thumbnailsDir: '/srv/thumbs',
|
|
gpsSatDir: '/srv/gps-sat',
|
|
gpsRouteDir: '/srv/gps-route',
|
|
}),
|
|
),
|
|
http.put('/api/annotations/settings/directories', async ({ request }) =>
|
|
jsonResponse(await request.json()),
|
|
),
|
|
|
|
// Used by AdminPage when listing detection classes for the editor.
|
|
http.get('/api/annotations/classes', () =>
|
|
jsonResponse([
|
|
{ id: 1, name: 'class-a', shortName: 'a', color: '#ff0000', maxSizeM: 7 },
|
|
{ id: 2, name: 'class-b', shortName: 'b', color: '#00ff00', maxSizeM: 5 },
|
|
]),
|
|
),
|
|
]
|