# Quickstart: Dataset Lifecycle Workspace

## Prerequisites

- Backend virtualenv: `cd backend && source .venv/bin/activate`
- Frontend deps: `cd frontend && npm install`
- Superset environment configured (dev instance, URL configured in `backend/.env`)
- RBAC: user must have `plugin:migration:WRITE` permission for mutation endpoints, `plugin:migration:READ` for list/detail reads
- Backend dev server: `http://localhost:8000`
- Frontend dev server (proxies API to backend): `http://localhost:8100`
- Direct backend API access for smoke tests: `http://localhost:8000/api/datasets/...`
- Frontend proxy access (browser): `http://localhost:8100/datasets`

## Backend Verification

```bash
# Run backend tests
cd backend && source .venv/bin/activate && python -m pytest -v

# Lint
python -m ruff check .

# Run dev server
uvicorn src.main:app --reload --port 8000
```

## Frontend Verification

```bash
# Run frontend tests
cd frontend && npm run test

# Lint
cd frontend && npm run lint

# Build check
cd frontend && npm run build

# Dev server (requires backend on :8000)
cd frontend && npm run dev
```

## Feature-Specific Verification

### Backend API Tests

```bash
# Test metrics in dataset detail response (direct backend)
curl -s http://localhost:8000/api/datasets/32?env_id=dev | jq '.metrics, .metric_count'

# Test stats counts in dataset list
curl -s 'http://localhost:8000/api/datasets?env_id=dev&page=1&page_size=5' | jq '.stats'

# Test server-side filtering
curl -s 'http://localhost:8000/api/datasets?env_id=dev&filter=unmapped&page=1&page_size=5' | jq '.datasets | length'

# Test column description inline-edit
curl -s -X PUT http://localhost:8000/api/datasets/32/columns/851/description \
  -H 'Content-Type: application/json' \
  -d '{"description":"Updated via API"}'

# Test metric description inline-edit
curl -s -X PUT http://localhost:8000/api/datasets/32/metrics/70/description \
  -H 'Content-Type: application/json' \
  -d '{"description":"Count of all records"}'
```

### Frontend Component Tests

```bash
# Run dataset-specific component tests
cd frontend && npx vitest run src/routes/datasets/ --reporter=verbose
```

### Browser Validation

1. Open `http://localhost:8100/datasets`
2. Verify Stats Bar shows 4 tiles with counts
3. Click each tile — list filters correctly
4. Click a dataset card — detail panel loads with columns + metrics
5. Click ✏️ on a column — textarea appears, type description, save
6. Verify description persists after save
7. Check 2+ checkboxes — bottom panel appears
8. Click "Map Columns" — modal opens

### Docker

```bash
docker compose up --build
# Visit http://localhost:8100/datasets
```

## Key Files Changed/Created

| File | Change |
|------|--------|
| `backend/src/api/routes/datasets.py` | +MetricItem, +StatsCounts, +2 endpoints, MOD DatasetsResponse/DatasetDetailResponse |
| `backend/src/core/superset_client/_datasets.py` | +metrics extraction in get_dataset_detail |
| `backend/src/core/task_manager.py` | +dataset.updated WebSocket event on task complete |
| `frontend/src/routes/datasets/+page.svelte` | REWRITE (split-view orchestrator) |
| `frontend/src/routes/datasets/StatsBar.svelte` | NEW |
| `frontend/src/routes/datasets/DatasetList.svelte` | NEW |
| `frontend/src/routes/datasets/DatasetPreview.svelte` | NEW |
| `frontend/src/routes/datasets/ColumnsTable.svelte` | NEW |
| `frontend/src/routes/datasets/MetricsTable.svelte` | NEW |
| `frontend/src/lib/i18n/locales/en/datasets.json` | +11 keys |
| `frontend/src/lib/i18n/locales/ru/datasets.json` | +11 keys |
