story 2-13-importplan-re-import: implemented and reviewed via bmad-loop
This commit is contained in:
1 parent
c562d5368d
commit
f69c36fa65
66 files changed
+11366
-686
No files matched your search
@@ -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', 'Операции'));
|
||||
@@ -112,7 +154,6 @@ paths:
|
||||
await expect(importedOperation.locator('.openapi-import-mapping-preview')).toContainText('Header');
|
||||
await expect(importedOperation.locator('.openapi-import-mapping-preview')).toContainText('X-API-Version');
|
||||
await expect(importedOperation.locator('.openapi-import-mapping-preview')).toContainText('Body');
|
||||
await expect(importedOperation.locator('.openapi-import-mapping-preview')).toContainText('symbols');
|
||||
await expect(importedOperation.locator('.openapi-import-mapping-preview')).toContainText(localized('Response', 'Ответ'));
|
||||
await expect(page.locator('#openapi-import-selection')).toContainText(localized('Selected: 2', 'Выбрано: 2'));
|
||||
await page.locator('#openapi-import-search').fill('status');
|
||||
@@ -127,18 +168,19 @@ 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}');
|
||||
await expect(importedOperation.locator('.openapi-import-findings')).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 }) => {
|
||||
@@ -246,6 +288,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 +312,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 +337,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 +352,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 +383,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 +420,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 +451,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 +461,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 +478,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 +575,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 +650,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);
|
||||
});
|
||||
Reference in new issue
Block a user