mirror of
https://github.com/azaion/ui.git
synced 2026-06-22 10:31:10 +00:00
[AZ-456] Test infrastructure: Vitest + MSW + Playwright + scripts
Scaffolds the Blackbox test project per AZ-456 / environment.md across
the three profiles:
- fast : Vitest 3.x + jsdom + MSW 2.x + RTL/jest-dom; tests/setup.ts
boots the MSW Node server with onUnhandledRequest:'error',
afterEach resets handlers, clears bearer + navigate-to-login
spy. Default handlers ship for every suite service plus OWM
and tile stand-ins. Fixtures mirror seed_* in test-data.md.
- e2e : Playwright ^1.49 with chromium + firefox projects against the
suite docker-compose stack; owm-stub + tile-stub Bun servers,
playwright-runner image, seeds.sql for the test-db.
- static: scripts/run-tests.sh extended — tsc --noEmit (test config),
vite build, ripgrep checks (with grep -r fallback), CSV
report at test-output/static-report.csv per AC-7 columns.
Smoke tests cover AC-3, AC-4 (fast, 5 tests, PASS) and AC-1, AC-2,
AC-5, AC-8 (e2e, gated by Risk 4 docker availability). Static profile
(13 checks) PASS — STC-SEC1 (no literal OWM key) lifted from
QUARANTINE per AZ-447 with a narrowed pattern.
Files:
+24 tests/**, +10 e2e/**, +vitest.config.ts, +tsconfig.test.json
~package.json (test scripts + devDeps for vitest, @testing-library/*,
msw, @playwright/test, jsdom, @types/node, @vitest/coverage-v8)
~scripts/run-tests.sh, scripts/run-performance-tests.sh — switched
RESULTS_DIR to test-output/, compose path to project-local
~.gitignore — added /test-output/
Verification:
bun run test:fast → 11 / 11 PASS
./scripts/run-tests.sh → static 13/13 + fast 11/11 PASS, exit 0
Tracker: AZ-456 → In Testing.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
import snapshot from '../../_docs/00_problem/input_data/enum_spec_snapshot.json'
|
||||
|
||||
// Re-export the committed enum spec snapshot so test files can import it
|
||||
// without crossing the docs path. AC-04 / AC-29 contract checks resolve
|
||||
// against this object — never against `src/types/index.ts` directly.
|
||||
export const enumSpec = snapshot as EnumSpecSnapshot
|
||||
|
||||
export interface EnumSpecSnapshot {
|
||||
$schema_note: string
|
||||
source_of_truth: Array<{ file: string; note: string; extracted_at?: string }>
|
||||
ui_drift_summary: Record<string, unknown>
|
||||
enums: Record<
|
||||
string,
|
||||
{
|
||||
source: string
|
||||
values: Record<string, number>
|
||||
verification_pending: boolean
|
||||
notes?: string
|
||||
case_note?: string
|
||||
stale_example_note?: string
|
||||
verification_note?: string
|
||||
}
|
||||
>
|
||||
downstream_actions: Record<string, unknown>
|
||||
}
|
||||
|
||||
export function loadEnumSnapshot(): EnumSpecSnapshot {
|
||||
return enumSpec
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
import type { Aircraft } from '../../src/types'
|
||||
|
||||
// Three aircraft with one default, per `seed_aircraft` in test-data.md.
|
||||
export const seedAircraft: Aircraft[] = [
|
||||
{ id: 'aircraft-1', model: 'Bayraktar TB2', type: 'Plane', isDefault: true },
|
||||
{ id: 'aircraft-2', model: 'DJI Mavic 3', type: 'Copter', isDefault: false },
|
||||
{ id: 'aircraft-3', model: 'Leleka-100', type: 'Plane', isDefault: false },
|
||||
]
|
||||
Vendored
+82
@@ -0,0 +1,82 @@
|
||||
import type { AnnotationListItem } from '../../src/types'
|
||||
import { AnnotationSource, AnnotationStatus, Affiliation, CombatReadiness } from '../../src/types'
|
||||
|
||||
// Annotations exercising the source / status enums + the splitTile path
|
||||
// (AC-39): one with a valid splitTile string, one malformed.
|
||||
|
||||
export const seedAnnotations: AnnotationListItem[] = [
|
||||
{
|
||||
id: 'ann-1',
|
||||
mediaId: 'media-3',
|
||||
time: null,
|
||||
createdDate: '2026-05-03T14:30:00Z',
|
||||
userId: 'user-alice',
|
||||
source: AnnotationSource.AI,
|
||||
status: AnnotationStatus.Created,
|
||||
isSplit: false,
|
||||
splitTile: null,
|
||||
detections: [
|
||||
{
|
||||
id: 'det-1',
|
||||
classNum: 0,
|
||||
label: 'class-0',
|
||||
confidence: 0.92,
|
||||
affiliation: Affiliation.Hostile,
|
||||
combatReadiness: CombatReadiness.Ready,
|
||||
centerX: 0.4,
|
||||
centerY: 0.5,
|
||||
width: 0.1,
|
||||
height: 0.15,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'ann-2',
|
||||
mediaId: 'media-3',
|
||||
time: null,
|
||||
createdDate: '2026-05-03T14:32:00Z',
|
||||
userId: 'user-alice',
|
||||
source: AnnotationSource.AI,
|
||||
status: AnnotationStatus.Edited,
|
||||
isSplit: true,
|
||||
splitTile: '3 0.5 0.5 0.2 0.2',
|
||||
detections: [
|
||||
{
|
||||
id: 'det-2',
|
||||
classNum: 1,
|
||||
label: 'class-1',
|
||||
confidence: 0.88,
|
||||
affiliation: Affiliation.Friendly,
|
||||
combatReadiness: CombatReadiness.NotReady,
|
||||
centerX: 0.5,
|
||||
centerY: 0.5,
|
||||
width: 0.2,
|
||||
height: 0.2,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'ann-3',
|
||||
mediaId: 'media-5',
|
||||
time: '00:01:00',
|
||||
createdDate: '2026-05-04T10:15:00Z',
|
||||
userId: 'user-bob',
|
||||
source: AnnotationSource.Manual,
|
||||
status: AnnotationStatus.Validated,
|
||||
isSplit: false,
|
||||
splitTile: null,
|
||||
detections: [],
|
||||
},
|
||||
{
|
||||
id: 'ann-4',
|
||||
mediaId: 'media-5',
|
||||
time: '00:01:30',
|
||||
createdDate: '2026-05-04T10:20:00Z',
|
||||
userId: 'user-bob',
|
||||
source: AnnotationSource.Manual,
|
||||
status: AnnotationStatus.Edited,
|
||||
isSplit: true,
|
||||
splitTile: 'garbage',
|
||||
detections: [],
|
||||
},
|
||||
]
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
import type { DetectionClass } from '../../src/types'
|
||||
|
||||
// Detection classes ordered per the contract: [0..N-1, 20..20+N-1, 40..40+N-1]
|
||||
// with N=9 so AC-37 / data_model.md:158 hotkey 1..9 mapping is fully covered.
|
||||
// PhotoMode + maxSizeM are placeholder values — no test currently asserts on
|
||||
// them at the contract level; tests that need specific values override the
|
||||
// /api/admin/classes handler.
|
||||
const baseColors = [
|
||||
'#e6194b', '#3cb44b', '#ffe119', '#4363d8', '#f58231',
|
||||
'#911eb4', '#46f0f0', '#f032e6', '#bcf60c',
|
||||
]
|
||||
|
||||
const N = 9
|
||||
const offsets = [0, 20, 40]
|
||||
|
||||
export const seedClasses: DetectionClass[] = offsets.flatMap((offset) =>
|
||||
Array.from({ length: N }, (_, i) => ({
|
||||
id: offset + i,
|
||||
name: `class-${offset + i}`,
|
||||
shortName: `c${offset + i}`,
|
||||
color: baseColors[i % baseColors.length],
|
||||
maxSizeM: 5,
|
||||
photoMode: 0,
|
||||
})),
|
||||
)
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
import type { Flight } from '../../src/types'
|
||||
|
||||
// Five flights spanning the four seed users; flight-1 has the live-GPS
|
||||
// simulator wire-up so the SSE handler in /api/flights/:id/live-gps drives
|
||||
// AC-08 timing assertions.
|
||||
|
||||
export const seedFlights: Flight[] = [
|
||||
{ id: 'flight-1', name: 'Recon Alpha', createdDate: '2026-05-01T10:00:00Z', aircraftId: 'aircraft-1' },
|
||||
{ id: 'flight-2', name: 'Recon Bravo', createdDate: '2026-05-02T11:30:00Z', aircraftId: 'aircraft-1' },
|
||||
{ id: 'flight-3', name: 'Survey Charlie', createdDate: '2026-05-03T14:15:00Z', aircraftId: 'aircraft-2' },
|
||||
{ id: 'flight-4', name: 'Patrol Delta', createdDate: '2026-05-04T09:45:00Z', aircraftId: 'aircraft-3' },
|
||||
{ id: 'flight-5', name: 'Strike Echo', createdDate: '2026-05-05T16:00:00Z', aircraftId: 'aircraft-1' },
|
||||
]
|
||||
|
||||
export const liveGpsFlightId = 'flight-1'
|
||||
Vendored
+76
@@ -0,0 +1,76 @@
|
||||
import type { Media } from '../../src/types'
|
||||
import { MediaStatus, MediaType } from '../../src/types'
|
||||
|
||||
// 6 media items exercising the mediaStatus enum range (UI's current 0..3 scheme;
|
||||
// AC-04 fix lands the full 0..6 range — tests targeting the post-fix range
|
||||
// override seed_media via server.use to add Confirmed/Error rows once Step 4
|
||||
// drift-fix tasks land).
|
||||
|
||||
export const seedMedia: Media[] = [
|
||||
{
|
||||
id: 'media-1',
|
||||
name: 'sortie-1.jpg',
|
||||
path: '/media/sortie-1.jpg',
|
||||
mediaType: MediaType.Image,
|
||||
mediaStatus: MediaStatus.New,
|
||||
duration: null,
|
||||
annotationCount: 0,
|
||||
waypointId: null,
|
||||
userId: 'user-alice',
|
||||
},
|
||||
{
|
||||
id: 'media-2',
|
||||
name: 'sortie-2.jpg',
|
||||
path: '/media/sortie-2.jpg',
|
||||
mediaType: MediaType.Image,
|
||||
mediaStatus: MediaStatus.AiProcessing,
|
||||
duration: null,
|
||||
annotationCount: 0,
|
||||
waypointId: 'wp-1',
|
||||
userId: 'user-alice',
|
||||
},
|
||||
{
|
||||
id: 'media-3',
|
||||
name: 'sortie-3.jpg',
|
||||
path: '/media/sortie-3.jpg',
|
||||
mediaType: MediaType.Image,
|
||||
mediaStatus: MediaStatus.AiProcessed,
|
||||
duration: null,
|
||||
annotationCount: 4,
|
||||
waypointId: 'wp-1',
|
||||
userId: 'user-alice',
|
||||
},
|
||||
{
|
||||
id: 'media-4',
|
||||
name: 'patrol-1.mp4',
|
||||
path: '/media/patrol-1.mp4',
|
||||
mediaType: MediaType.Video,
|
||||
mediaStatus: MediaStatus.New,
|
||||
duration: '00:01:30',
|
||||
annotationCount: 0,
|
||||
waypointId: null,
|
||||
userId: 'user-bob',
|
||||
},
|
||||
{
|
||||
id: 'media-5',
|
||||
name: 'patrol-2.mp4',
|
||||
path: '/media/patrol-2.mp4',
|
||||
mediaType: MediaType.Video,
|
||||
mediaStatus: MediaStatus.AiProcessed,
|
||||
duration: '00:02:15',
|
||||
annotationCount: 8,
|
||||
waypointId: null,
|
||||
userId: 'user-bob',
|
||||
},
|
||||
{
|
||||
id: 'media-6',
|
||||
name: 'manual.jpg',
|
||||
path: '/media/manual.jpg',
|
||||
mediaType: MediaType.Image,
|
||||
mediaStatus: MediaStatus.ManualCreated,
|
||||
duration: null,
|
||||
annotationCount: 1,
|
||||
waypointId: null,
|
||||
userId: 'user-alice',
|
||||
},
|
||||
]
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
import type { UserSettings } from '../../src/types'
|
||||
|
||||
// Known panel widths + selected flight for op_alice so the rehydration tests
|
||||
// (AC-21, AC-06) assert against a deterministic state.
|
||||
export const seedUserSettings: UserSettings[] = [
|
||||
{
|
||||
id: 'user-settings-alice',
|
||||
userId: 'user-alice',
|
||||
selectedFlightId: 'flight-1',
|
||||
annotationsLeftPanelWidth: 280,
|
||||
annotationsRightPanelWidth: 320,
|
||||
datasetLeftPanelWidth: 240,
|
||||
datasetRightPanelWidth: 280,
|
||||
},
|
||||
{
|
||||
id: 'user-settings-bob',
|
||||
userId: 'user-bob',
|
||||
selectedFlightId: 'flight-3',
|
||||
annotationsLeftPanelWidth: null,
|
||||
annotationsRightPanelWidth: null,
|
||||
datasetLeftPanelWidth: null,
|
||||
datasetRightPanelWidth: null,
|
||||
},
|
||||
]
|
||||
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
import type { User } from '../../src/types'
|
||||
|
||||
// Mirrors `seed_users` per `_docs/02_document/tests/test-data.md`. Four users
|
||||
// covering the role / permission combinations the e2e tests rely on.
|
||||
|
||||
export const opAlice: User = {
|
||||
id: 'user-alice',
|
||||
name: 'Alice Operator',
|
||||
email: 'op_alice@test.local',
|
||||
role: 'Operator',
|
||||
isActive: true,
|
||||
}
|
||||
|
||||
export const opBob: User = {
|
||||
id: 'user-bob',
|
||||
name: 'Bob Operator',
|
||||
email: 'op_bob@test.local',
|
||||
role: 'Operator',
|
||||
isActive: true,
|
||||
}
|
||||
|
||||
export const adminCarol: User = {
|
||||
id: 'user-carol',
|
||||
name: 'Carol Admin',
|
||||
email: 'admin_carol@test.local',
|
||||
role: 'Admin',
|
||||
isActive: true,
|
||||
}
|
||||
|
||||
export const integratorDave: User = {
|
||||
id: 'user-dave',
|
||||
name: 'Dave Integrator',
|
||||
email: 'integrator_dave@test.local',
|
||||
role: 'SystemIntegrator',
|
||||
isActive: true,
|
||||
}
|
||||
|
||||
export const seedUsers: User[] = [opAlice, opBob, adminCarol, integratorDave]
|
||||
|
||||
// Permissions are a parallel structure — the suite's auth service is the
|
||||
// authoritative source. Tests that assert RBAC override the
|
||||
// `/api/admin/users/me` handler with the relevant permission set.
|
||||
export const seedPermissions: Record<string, string[]> = {
|
||||
'user-alice': ['ADMIN_VIEW', 'FLIGHTS_WRITE', 'ANNOTATIONS_WRITE', 'SETTINGS'],
|
||||
'user-bob': ['ADMIN_VIEW', 'FLIGHTS_WRITE', 'ANNOTATIONS_WRITE'],
|
||||
'user-carol': ['ADMIN_VIEW', 'ADMIN_WRITE', 'FLIGHTS_WRITE', 'ANNOTATIONS_WRITE', 'SETTINGS', 'CLASSES_WRITE'],
|
||||
'user-dave': ['ADMIN_VIEW', 'ADMIN_WRITE', 'INTEGRATION'],
|
||||
}
|
||||
Reference in New Issue
Block a user