feat(import): complete OpenAPI onboarding and verify delivery
CI / Rust Checks (pull_request) Failing after 1s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped

This commit is contained in:
bsodfather committed 2026-10-09 17:50:38 +03:00
1 parent bb3e376767
commit e93de7015a
244 files changed
+57020 -5139

No files matched your search

+121 -39
View File
@@ -11,6 +11,48 @@ async function dismissOnboardingIfOpen(page) {
await expect(page.locator('#crank-onboarding-panel')).toBeHidden();
}
function planResponse(payload, planReference) {
const decisions = payload.decisions || [];
return {
plan_reference: planReference,
plan_digest: 'c'.repeat(64),
expires_at: new Date(Date.now() + 60 * 60 * 1000).toISOString(),
selection_mode: payload.selection_mode,
counts: { selected: decisions.length, excluded: 0, actionable: decisions.length, blocked: 0 },
candidates: decisions.map((decision) => ({
key: decision.operation_key,
name: decision.confirmed_name || decision.operation_key,
state: 'actionable',
action: decision.action,
target_operation_id: decision.target_operation_id || null,
confirmed_name: decision.confirmed_name || null,
auth_profile_id: null,
reason: null,
})),
};
}
function applyResponse(payload, names) {
const outcomes = (payload.outcomes || []).map((outcome) => ({
key: outcome.key,
name: names && names[outcome.key] || outcome.name || outcome.key,
status: outcome.status || 'created',
}));
return {
counts: { created: outcomes.filter((outcome) => outcome.status === 'created').length },
outcomes,
};
}
async function mockEmptyOperationsList(page) {
await page.route('**/api/admin/workspaces/*/operations', async (route) => {
await route.fulfill({
contentType: 'application/json',
body: JSON.stringify({ items: [], page: 1, page_size: 0, total: 0 }),
});
});
}
test('operations page shows demo catalog and filter works', async ({ page }) => {
await login(page);
await expect(page.locator('.page-heading')).toHaveText(localized('Operations', 'Операции'));
@@ -100,7 +142,9 @@ paths:
const request = await previewRequest;
expect(request.headers()['content-type']).toMatch(/^multipart\/form-data; boundary=/i);
await expect(page.locator('#openapi-import-preview-panel')).toBeVisible();
await expect(page.locator('.openapi-import-document-findings')).toContainText(/base URL/i);
const documentFindings = page.locator('.openapi-import-document-findings');
await documentFindings.locator('summary').click();
await expect(documentFindings).toContainText(/base URL/i);
await expect(page.locator('.openapi-import-group').filter({ hasText: 'currency' })).toBeVisible();
const importedOperation = page.locator('.openapi-import-operation').filter({ hasText: 'Получить курсы валют' });
await expect(importedOperation).toBeVisible();
@@ -118,6 +162,7 @@ paths:
await page.locator('#openapi-import-search').fill('status');
await expect(page.locator('.openapi-import-operation:visible')).toHaveCount(1);
await expect(page.locator('.openapi-import-operation:visible').filter({ hasText: 'Проверить статус' })).toBeVisible();
await page.locator('#openapi-import-partial-mode').check();
await page.locator('#openapi-import-clear-visible').click();
await expect(page.locator('#openapi-import-selection')).toContainText(localized('Selected: 1', 'Выбрано: 1'));
await page.locator('#openapi-import-search').fill('');
@@ -127,18 +172,21 @@ paths:
await page.locator('#openapi-import-method-filter').selectOption('');
await page.locator('#openapi-import-server-custom').fill('https://api.example.test');
await page.locator('#openapi-import-create').click();
await expect(page.locator('#openapi-import-result')).toContainText(localized('Import result', 'Результат импорта'));
await expect(page.locator('.openapi-import-result-table')).toBeVisible();
await expect(page.locator('.openapi-import-result-row').filter({ hasText: operationId })).toContainText('POST /v1/rates/{date}');
await expect(page.locator('.openapi-import-result-row').filter({ hasText: operationId })).toContainText(localized('tool description is too short', 'Описание инструмента слишком короткое'));
await expect(page.locator('.openapi-import-result-row').filter({ hasText: operationId })).toContainText(localized('Fix in wizard', 'Исправить в мастере'));
await expect(page.locator('.openapi-import-primary-result a')).toHaveAttribute(
'href',
/\/wizard\/\?mode=edit&operationId=op_/
);
await expect(page.locator('[data-testid="openapi-import-apply-confirmation"]')).toBeVisible();
await page.locator('#openapi-import-plan-apply').click();
await expect(page.locator('#openapi-import-result')).toBeVisible();
await expect(page.locator('#openapi-import-result')).toContainText(localized('Import plan result', 'Результат плана импорта'));
await expect(page.locator('.openapi-import-plan-outcomes')).toContainText(operationId);
await expect(page.locator('.openapi-import-plan-outcomes')).toContainText('POST /v1/rates/{date}');
const operationFindings = importedOperation.locator('.openapi-import-findings');
await operationFindings.locator('summary').click();
await expect(operationFindings).toContainText(localized('tool description is too short', 'Описание инструмента слишком короткое'));
await expect(page.locator('tbody')).toContainText(new RegExp(operationId, 'i'));
await expect(page.locator('tbody')).not.toContainText(new RegExp(statusOperationId, 'i'));
await expect(page.locator('body')).not.toContainText(sourceCanary);
await page.locator('[data-openapi-close]').last().click();
await page.locator('tbody tr').filter({ hasText: operationId }).locator('.row-btn-edit').click();
await expect(page).toHaveURL(/\/wizard\/\?mode=edit&operationId=op_/);
});
test('OpenAPI upload rejects invalid files locally and restores focus after Escape', async ({ page }) => {
@@ -230,7 +278,7 @@ test('OpenAPI upload recovers from pagehide and a preview server error', async (
buffer: Buffer.from('openapi: 3.0.3'),
});
await page.locator('#openapi-import-preview').click();
await expect(page.locator('#openapi-import-status')).toContainText(localized('Uploading and parsing', 'Загружаю и разбираю'));
await expect(page.locator('#openapi-import-status')).toContainText(localized('Uploading the document', 'Загружаю документ'));
await page.evaluate(() => window.dispatchEvent(new PageTransitionEvent('pagehide', { persisted: true })));
await expect(page.locator('#openapi-import-status')).toHaveText('');
@@ -246,6 +294,7 @@ test('OpenAPI apply cancellation preserves the import job for an idempotent retr
await login(page);
await dismissOnboardingIfOpen(page);
await page.getByRole('button', { name: localized('Import OpenAPI', 'Импорт OpenAPI') }).click();
await mockEmptyOperationsList(page);
await page.route('**/imports/openapi/preview', async (route) => {
await route.fulfill({
@@ -269,11 +318,18 @@ test('OpenAPI apply cancellation preserves the import job for an idempotent retr
});
const requests = [];
await page.route('**/imports/openapi/*/plans', async (route) => {
const payload = route.request().postDataJSON();
await route.fulfill({
contentType: 'application/json',
body: JSON.stringify(planResponse(payload, 'plan_retry_same_authority')),
});
});
let releaseFirst;
const firstRequest = new Promise((resolve) => {
releaseFirst = resolve;
});
await page.route('**/imports/openapi/*/create', async (route) => {
await page.route('**/imports/openapi/*/apply', async (route) => {
requests.push({ url: route.request().url(), body: route.request().postData() });
if (requests.length === 1) await firstRequest;
if (requests.length === 3) {
@@ -287,12 +343,9 @@ test('OpenAPI apply cancellation preserves the import job for an idempotent retr
try {
await route.fulfill({
contentType: 'application/json',
body: JSON.stringify({
created: [{
operation_key: 'get:/retry', name: 'renamed_after_conflict', operation_id: 'op_retry', version: 1,
}],
skipped: [], findings: [],
}),
body: JSON.stringify(applyResponse({ outcomes: [{
key: 'get:/retry', name: 'renamed_after_conflict', status: 'created',
}] })),
});
} catch (_error) {
// The first request is deliberately aborted by the browser.
@@ -305,23 +358,25 @@ test('OpenAPI apply cancellation preserves the import job for an idempotent retr
await page.locator('#openapi-import-preview').click();
await expect(page.locator('#openapi-import-preview-panel')).toBeVisible();
await page.locator('#openapi-import-create').click();
await expect(page.locator('[data-testid="openapi-import-apply-confirmation"]')).toBeVisible();
await page.locator('#openapi-import-plan-apply').click();
await expect.poll(() => requests.length).toBe(1);
await page.locator('#openapi-import-cancel').click();
await expect(page.locator('#openapi-import-status')).toContainText(localized('may have completed', 'мог завершиться'));
await expect(page.locator('#openapi-import-status')).toContainText(localized('Apply result is unknown', 'Результат применения неизвестен'));
await expect(page.locator('#openapi-import-retry')).toBeVisible();
await page.locator('[data-openapi-close]').last().click();
await page.reload();
await page.getByRole('button', { name: localized('Import OpenAPI', 'Импорт OpenAPI') }).click();
await expect(page.locator('#openapi-import-retry')).toBeVisible();
await page.locator('#openapi-import-retry').click();
await expect(page.locator('#openapi-import-result')).toContainText('GET /retry');
await expect(page.locator('#openapi-import-result')).toContainText('get:/retry');
await expect.poll(() => requests.length).toBe(2);
// Let the cancelled first attempt answer after the retry. Its stale response
// must not overwrite or unlock the newer attempt's state.
releaseFirst();
await page.waitForTimeout(50);
await expect(page.locator('#openapi-import-result')).toContainText('GET /retry');
expect(requests[0].url).toContain('/imports/openapi/job_retry_same_authority/create');
await expect(page.locator('#openapi-import-result')).toContainText('get:/retry');
expect(requests[0].url).toContain('/imports/openapi/plan_retry_same_authority/apply');
expect(requests[1].url).toBe(requests[0].url);
expect(requests[1].body).toBe(requests[0].body);
@@ -334,17 +389,20 @@ test('OpenAPI apply cancellation preserves the import job for an idempotent retr
await page.locator('#openapi-import-preview').click();
await expect(page.locator('#openapi-import-preview-panel')).toBeVisible();
await page.locator('#openapi-import-create').click();
await expect(page.locator('[data-testid="openapi-import-apply-confirmation"]')).toBeVisible();
await page.locator('#openapi-import-plan-apply').click();
await expect.poll(() => requests.length).toBe(3);
await expect(page.locator('#openapi-import-file-select')).toBeEnabled();
await expect(page.locator('#openapi-import-reset')).toBeEnabled();
await expect(page.locator('#openapi-import-retry')).toBeVisible();
expect(await page.evaluate(() => sessionStorage.getItem('crank_openapi_apply_replay_v1'))).toBeNull();
expect(await page.evaluate(() => sessionStorage.getItem('crank_openapi_plan_apply_replay_v2'))).toBeNull();
});
test('OpenAPI apply preserves job authority after language or workspace changes', async ({ page }) => {
await login(page);
await dismissOnboardingIfOpen(page);
await page.getByRole('button', { name: localized('Import OpenAPI', 'Импорт OpenAPI') }).click();
await mockEmptyOperationsList(page);
await page.route('**/imports/openapi/preview', async (route) => {
await route.fulfill({
@@ -368,16 +426,21 @@ test('OpenAPI apply preserves job authority after language or workspace changes'
});
const releases = [];
const applyRequests = [];
await page.route('**/imports/openapi/*/create', async (route) => {
await page.route('**/imports/openapi/*/plans', async (route) => {
await route.fulfill({
contentType: 'application/json',
body: JSON.stringify(planResponse(route.request().postDataJSON(), 'plan_active_apply')),
});
});
await page.route('**/imports/openapi/*/apply', async (route) => {
applyRequests.push({ url: route.request().url(), body: route.request().postData() });
await new Promise((resolve) => releases.push(resolve));
try {
await route.fulfill({
contentType: 'application/json',
body: JSON.stringify({
created: [{ operation_key: 'get:/active', name: 'active', operation_id: 'op_active', version: 1 }],
skipped: [], findings: [],
}),
body: JSON.stringify(applyResponse({ outcomes: [{
key: 'get:/active', name: 'active', status: 'created',
}] })),
});
} catch (_error) {
// The invalidation aborts a request that must not update the modal afterwards.
@@ -394,6 +457,8 @@ test('OpenAPI apply preserves job authority after language or workspace changes'
await expect(page.locator('#openapi-import-preview-panel')).toBeVisible();
await page.locator('#openapi-import-server-custom').fill('https://api.example.test');
await page.locator('#openapi-import-create').click();
await expect(page.locator('[data-testid="openapi-import-apply-confirmation"]')).toBeVisible();
await page.locator('#openapi-import-plan-apply').click();
await expect(page.locator('#openapi-import-cancel')).toBeVisible();
await expect.poll(() => releases.length).toBeGreaterThan(0);
}
@@ -402,14 +467,14 @@ test('OpenAPI apply preserves job authority after language or workspace changes'
// Exercise the actual UI language switcher path: it updates storage,
// re-renders translations and dispatches crank:langchange in one action.
await page.evaluate(() => window.setLang('en'));
await expect(page.locator('#openapi-import-status')).toContainText('may have completed');
await expect(page.locator('#openapi-import-status')).toContainText('Apply result is unknown');
await expect(page.locator('#openapi-import-retry')).toBeVisible();
await expect(page.locator('#openapi-import-file-select')).toBeDisabled();
releases.shift()();
await page.locator('#openapi-import-retry').click();
await expect.poll(() => releases.length).toBeGreaterThan(0);
releases.shift()();
await expect(page.locator('#openapi-import-result')).toContainText('GET /active');
await expect(page.locator('#openapi-import-result')).toContainText('get:/active');
expect(applyRequests[1].url).toBe(applyRequests[0].url);
expect(applyRequests[1].body).toBe(applyRequests[0].body);
@@ -419,7 +484,7 @@ test('OpenAPI apply preserves job authority after language or workspace changes'
await page.evaluate(() => {
window.dispatchEvent(new CustomEvent('crank:workspacechange', { detail: { id: 'workspace-after-apply' } }));
});
await expect(page.locator('#openapi-import-status')).toContainText('may have completed');
await expect(page.locator('#openapi-import-status')).toContainText('Apply result is unknown');
await expect(page.locator('#openapi-import-retry')).toBeVisible();
await expect(page.locator('#openapi-import-file-select')).toBeDisabled();
releases.shift()();
@@ -516,6 +581,7 @@ test('OpenAPI upload ignores a stale failure and renders only correlation identi
await login(page);
await dismissOnboardingIfOpen(page);
await page.getByRole('button', { name: localized('Import OpenAPI', 'Импорт OpenAPI') }).click();
await mockEmptyOperationsList(page);
const sourceCanary = 'do-not-render-openapi-source-canary';
await page.locator('#openapi-import-file').setInputFiles({
name: 'safe.yaml',
@@ -590,14 +656,30 @@ test('OpenAPI upload ignores a stale failure and renders only correlation identi
});
await page.locator('#openapi-import-retry').click();
await expect(page.locator('#openapi-import-preview-panel')).toBeVisible();
let createRequests = 0;
await page.route('**/imports/openapi/*/create', async (route) => {
createRequests += 1;
await new Promise((resolve) => setTimeout(resolve, 100));
await route.fulfill({ contentType: 'application/json', body: JSON.stringify({ created: [], skipped: [], findings: [] }) });
await page.route('**/imports/openapi/*/plans', async (route) => {
await route.fulfill({
contentType: 'application/json',
body: JSON.stringify(planResponse(route.request().postDataJSON(), 'plan_ui_evidence')),
});
});
let applyRequests = 0;
let releaseApply;
const applyResponseHeld = new Promise((resolve) => { releaseApply = resolve; });
await page.route('**/imports/openapi/*/apply', async (route) => {
applyRequests += 1;
await applyResponseHeld;
await route.fulfill({
contentType: 'application/json',
body: JSON.stringify(applyResponse({ outcomes: [{ key: 'get:/health', name: 'health', status: 'created' }] })),
});
});
await page.locator('#openapi-import-create').click();
await page.locator('#openapi-import-create').evaluate((button) => button.click());
await expect(page.locator('#openapi-import-status')).toContainText('Created: 0; skipped: 0.');
expect(createRequests).toBe(1);
await expect(page.locator('[data-testid="openapi-import-apply-confirmation"]')).toBeVisible();
const applyButton = page.locator('#openapi-import-plan-apply');
await applyButton.dblclick();
await expect.poll(() => applyRequests).toBe(1);
await expect(applyButton).toBeDisabled();
releaseApply();
await expect(page.locator('#openapi-import-status')).toContainText('Import plan applied.');
expect(applyRequests).toBe(1);
});