Files
ss-tools/frontend/src/routes/datasets/__tests__/DatasetPreview.test.ts
busya 3133e50645 perf: fix translate deadlock, speed, trace_id, UI bugs — fullstack patch
## Backend (7 production files + 6 test files)

### P0-2: LLM output truncation cascade fix
- _token_budget.py: OUTPUT_PER_ROW_PER_LANG 120→200, OUTPUT_SAFETY_FACTOR 0.70→0.55
- Prevents finish_reason=length → split → retry cascade (3 calls → 1 call per batch)
- P2-8: added qwen-flash/qwen-plus/qwen-max/qwen-coder to PROVIDER_DEFAULTS

### P1-4/P1-5: EncryptionManager singleton
- encryption.py: get_encryption_manager() process-wide singleton
- llm_provider.py: use singleton instead of new EncryptionManager() per batch
- Eliminates ~90 redundant Fernet key validations per translation run

### P1-6: Cache-hit log aggregation
- _batch_proc.py: one log per batch (batch_rows + cache_hits) instead of per-row
- 1076 log lines → ~30 per run

### P1-7: Timezone-aware datetime fix
- scheduler.py: _ensure_aware() helper for naive DB datetime → UTC-aware
- Fixes TypeError in scheduled translation concurrency check

### P2-9: Connection test timeout
- connection_service.py: asyncio.wait_for(15s) on all dialect tests
- Prevents 2-minute UI hangs from DNS/TCP stalls

### Trace ID propagation
- middleware/trace.py: inject x-trace-id response header via ASGI send wrapper

### Test fixes & integration tests
- test_scheduler.py: AsyncMock for execute_run, mock get_async_job_runner
- test_sql_insert_service.py: AsyncMock for execute_sql
- test_token_budget.py: batch_size 50→45 for new OUTPUT_PER_ROW_PER_LANG=200
- test_encryption.py: +2 singleton tests
- test_scheduler_ensure_aware.py: +4 (naive→aware, passthrough, None, subtraction)
- test_batch_classify_persist.py: +2 cache-hit aggregation tests
- test_connection_service_edge.py: +2 timeout tests
- test_trace_middleware.py: +4 x-trace-id header tests
- test_token_budget.py: +4 qwen-flash/O200 tests

## Frontend (7 production files + 5 test files)

### Trace ID propagation
- api.ts: _captureTraceId() reads x-trace-id → setTraceId() in fetchApi/requestApi/postApi/deleteApi

### Duplicate datasource columns fetch
- ConfigTabForm.svelte: guard availableColumns.length === 0 before fetch

### Admin pages Svelte 5 runes fix
- admin/users/+page.svelte: plain let → () for all template-bound vars
- admin/roles/+page.svelte: same fix
- Both pages were stuck on «Загрузка...» due to mixed reactivity models

### Validation popover positioning
- +page.svelte: pass trigger HTMLElement instead of event
- DashboardHubModel.svelte.ts: toggleValidationPopover(HTMLElement), closeValidationPopover()
- Added X close button + click-outside overlay + i18n

### Test fixes & integration tests
- api.test.ts: mock setTraceId/getTraceId, +3 _captureTraceId tests
- provider_config.integration.test.ts: handleDelete→promptDeleteProvider
- DatasetPreview.test.ts: dashboards/ → ROUTES.dashboards
- test_config_tab_form.svelte.js: +2 columns fetch guard tests (NEW)
- admin-users.test.ts: +3 loading→table tests (NEW)
- admin-roles.test.ts: +2 loading→table tests (NEW)

## Semantic curation
- Removed @COMPLEXITY N from 6 route files + metrics.py (duplicate of [C:N])
- Added [C:N] to 2 orphan child contracts in metrics.py
- Added [C:N] + @BRIEF to 4 frontend anchors
- Fixed #region → # #region consistency in validation_tasks.py

## Verification
- Backend: 608 pytest passed (0 failures)
- Frontend: 2472 vitest passed (128 files, 0 failures)
- Frontend build: ✓ built in 18s
- Browser: dashboards, admin/users, admin/roles, validation popover — all green
2026-06-18 23:54:57 +03:00

63 lines
2.2 KiB
TypeScript

// #region DatasetPreviewTest [C:2] [TYPE Module] [SEMANTICS test, datasets, detail, preview, component]
// @BRIEF Contract-focused unit tests for DatasetPreview.svelte component.
// @LAYER Test
import { describe, it, expect } from 'vitest';
import fs from 'node:fs';
import path from 'node:path';
const COMPONENT_PATH = path.resolve(process.cwd(), 'src/routes/datasets/DatasetPreview.svelte');
describe('DatasetPreview Component', () => {
it('component file exists', () => {
expect(fs.existsSync(COMPONENT_PATH)).toBe(true);
});
it('shows no-selection placeholder', () => {
const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(src).toContain('no_selection');
expect(src).toContain('!dataset');
});
it('shows loading skeleton', () => {
const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(src).toContain('isLoading');
expect(src).toContain('animate-pulse');
expect(src).toContain('aria-busy');
});
it('shows error state with retry', () => {
const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(src).toContain('error');
expect(src).toContain('onretry');
expect(src).toContain('retry');
});
it('renders header with table_name, schema, counts', () => {
const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(src).toContain('table_name');
expect(src).toContain('schema');
expect(src).toContain('column_count');
expect(src).toContain('metric_count');
});
it('renders linked dashboards as clickable pills', () => {
const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(src).toContain('linked_dashboards');
expect(src).toContain('ROUTES.dashboards');
});
it('includes ColumnsTable and MetricsTable', () => {
const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(src).toContain('ColumnsTable');
expect(src).toContain('MetricsTable');
});
it('is presentational — receives dataset, isLoading, error props', () => {
const src = fs.readFileSync(COMPONENT_PATH, 'utf-8');
expect(src).toContain('$props()');
expect(src).toContain('dataset = null');
expect(src).toContain('isLoading = false');
expect(src).toContain('error = null');
});
});