1223 lines
58 KiB
JavaScript
1223 lines
58 KiB
JavaScript
// Story 2.12 acceptance tests for full preview and explicit partial mode.
|
|
//
|
|
// All mandatory UI leaves are active; backend-only contracts are verified in
|
|
// the Rust integration and unit suites.
|
|
//
|
|
// This file covers user-observable behavior; see
|
|
// `_bmad-output/test-artifacts/atdd-checklist-2-12-preview-partial-mode.md`
|
|
// for the complete AC-to-test evidence map.
|
|
|
|
const { test, expect } = require('@playwright/test');
|
|
const { getCurrentWorkspace, login, localized, uniqueName } = require('./helpers');
|
|
|
|
async function dismissOnboardingIfOpen(page) {
|
|
await page.locator('#crank-onboarding-panel').waitFor({ state: 'attached' });
|
|
await page.locator('[data-testid="onboarding-dismiss"]').waitFor({ state: 'attached' });
|
|
await page.evaluate(() => {
|
|
const dismiss = document.querySelector('[data-testid="onboarding-dismiss"]');
|
|
if (dismiss) dismiss.click();
|
|
});
|
|
await expect(page.locator('#crank-onboarding-panel')).toBeHidden();
|
|
}
|
|
|
|
function importDocument(prefix, paths) {
|
|
const lines = [
|
|
'openapi: 3.0.3',
|
|
"info: { title: 'Preview partial ATDD', version: '1' }",
|
|
'servers: [{ url: https://api.example.test }]',
|
|
'paths:',
|
|
];
|
|
for (const [path, operationId] of paths) {
|
|
lines.push(' /' + path + ':');
|
|
lines.push(' get:');
|
|
lines.push(' operationId: ' + operationId);
|
|
lines.push(' responses:');
|
|
lines.push(" '200': { description: OK }");
|
|
}
|
|
return lines.join('\n');
|
|
}
|
|
|
|
function candidate(prefix, suffix, overrides) {
|
|
return Object.assign(
|
|
{
|
|
key: 'GET /' + prefix + '-' + suffix,
|
|
method: 'GET',
|
|
path: '/' + prefix + '-' + suffix,
|
|
operation_id: prefix + '_' + suffix,
|
|
suggested_name: prefix + '_' + suffix,
|
|
suggested_display_name: prefix + ' ' + suffix,
|
|
description: 'ATDD candidate',
|
|
category: 'default',
|
|
input_fields: 0,
|
|
output_fields: 1,
|
|
server_urls: ['https://api.example.test'],
|
|
// Proposed Story 2.12 additions (not produced by the baseline API yet).
|
|
source_location: { pointer: '/paths/~1' + prefix + '-' + suffix + '/get' },
|
|
findings: [],
|
|
security_requirements: { source: 'none', alternatives: [] },
|
|
security_schemes: {},
|
|
draft: {
|
|
name: prefix + '_' + suffix,
|
|
display_name: prefix + ' ' + suffix,
|
|
category: 'default',
|
|
target: { method: 'GET', path: '/' + prefix + '-' + suffix, server_url: 'https://api.example.test' },
|
|
input_schema: { type: 'object', properties: {} },
|
|
output_schema: { type: 'object', properties: {} },
|
|
input_mapping: [],
|
|
output_mapping: [],
|
|
tool_description: {},
|
|
wizard_state: null,
|
|
},
|
|
},
|
|
overrides || {},
|
|
);
|
|
}
|
|
|
|
function previewResponse(prefix, operations, extra) {
|
|
return Object.assign(
|
|
{
|
|
job_id: 'imp_e2e_preview_partial',
|
|
expires_at: new Date(Date.now() + 60 * 60 * 1000).toISOString(),
|
|
preview: {
|
|
source: {
|
|
format: 'openapi',
|
|
version: '3.0.3',
|
|
title: 'Preview partial ATDD',
|
|
servers: ['https://api.example.test'],
|
|
},
|
|
groups: [{ key: 'default', title: 'Default', operations }],
|
|
findings: [],
|
|
// Proposed Story 2.12 addition.
|
|
conflicts: [],
|
|
},
|
|
security_profile_choices: [],
|
|
},
|
|
extra || {},
|
|
);
|
|
}
|
|
|
|
function planResponse(prefix, candidates, overrides) {
|
|
return Object.assign(
|
|
{
|
|
plan_reference: 'plan_e2e_preview_partial_212',
|
|
plan_digest: 'c'.repeat(64),
|
|
expires_at: new Date(Date.now() + 60 * 60 * 1000).toISOString(),
|
|
selection_mode: 'full',
|
|
counts: { selected: candidates.length, excluded: 0, actionable: candidates.length, blocked: 0 },
|
|
candidates,
|
|
},
|
|
overrides || {},
|
|
);
|
|
}
|
|
|
|
async function routeOperationsEmpty(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 }),
|
|
});
|
|
});
|
|
}
|
|
|
|
async function openImportModal(page, locale) {
|
|
await login(page);
|
|
await dismissOnboardingIfOpen(page);
|
|
await page.evaluate((language) => window.setLang(language), locale);
|
|
await page.getByRole('button', { name: localized('Import OpenAPI', 'Импорт OpenAPI') }).click();
|
|
await expect(page.locator('#openapi-import-modal')).toBeVisible();
|
|
}
|
|
|
|
async function uploadAndPreview(page, prefix, paths) {
|
|
await page.locator('#openapi-import-file').setInputFiles({
|
|
name: 'preview-partial.yaml',
|
|
mimeType: 'application/yaml',
|
|
buffer: Buffer.from(importDocument(prefix, paths)),
|
|
});
|
|
const previewResponseWaiter = page.waitForResponse((response) =>
|
|
response.request().method() === 'POST'
|
|
&& response.url().includes('/imports/openapi/preview'),
|
|
);
|
|
await page.locator('#openapi-import-preview').click();
|
|
await previewResponseWaiter;
|
|
await expect(page.locator('#openapi-import-preview-panel')).toBeVisible();
|
|
}
|
|
|
|
// AC-1: preview must expose source locations and stable finding codes for
|
|
// every candidate, finding and conflict. Backend emission is owned by the
|
|
// Rust preview suite; this leaf asserts the UI renders what the API returns.
|
|
test('[P1] AC-1 preview renders source locations and stable finding codes for candidates and conflicts', async ({ page }) => {
|
|
const prefix = uniqueName('preview_location');
|
|
const operations = [
|
|
candidate(prefix, 'located', {
|
|
findings: [
|
|
{
|
|
code: 'missing_operation_id',
|
|
severity: 'warning',
|
|
message: 'No operationId',
|
|
operation_key: 'GET /' + prefix + '-located',
|
|
source_location: { pointer: '/paths/~1' + prefix + '-located/get' },
|
|
},
|
|
],
|
|
}),
|
|
];
|
|
const response = previewResponse(prefix, operations);
|
|
response.preview.conflicts = [
|
|
{
|
|
operation_key: 'GET /' + prefix + '-located',
|
|
conflict_type: 'duplicate_name',
|
|
proposed_name: prefix + '_located_2',
|
|
source_location: { pointer: '/paths/~1' + prefix + '-located/get/operationId' },
|
|
},
|
|
];
|
|
await routeOperationsEmpty(page);
|
|
await page.route('**/api/admin/workspaces/*/imports/openapi/preview', async (route) => {
|
|
await route.fulfill({
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(response),
|
|
});
|
|
});
|
|
await openImportModal(page, 'en');
|
|
await uploadAndPreview(page, prefix, [[prefix + '-located', prefix + '_located']]);
|
|
|
|
const row = page.locator('.openapi-import-operation').first();
|
|
await row.locator('.openapi-import-findings summary').click();
|
|
await expect(row.locator('[data-testid="openapi-import-operation-location"]')).toContainText('/paths/');
|
|
await expect(row.locator('[data-testid="openapi-import-finding-code"]')).toContainText('missing_operation_id');
|
|
await expect(row.locator('[data-testid="openapi-import-finding-location"]')).toContainText('/paths/');
|
|
await expect(row.locator('[data-testid="openapi-import-conflict"]')).toContainText('duplicate_name');
|
|
await expect(row.locator('[data-testid="openapi-import-conflict-location"]')).toContainText('/operationId');
|
|
});
|
|
|
|
for (const locale of ['en', 'ru']) {
|
|
test(`[P0] AC-2.8-02 external reference denial gives safe guidance and stays blocked in ${locale}`, async ({ page }) => {
|
|
const prefix = uniqueName('preview_external_denied');
|
|
const sourceCanary = 'private-reference-message-canary';
|
|
const urlCanary = 'https://private.example.test/internal/openapi.yaml';
|
|
const operations = [candidate(prefix, 'blocked', {
|
|
status: 'blocked',
|
|
findings: [{
|
|
code: 'external_reference_disabled',
|
|
severity: 'error',
|
|
message: sourceCanary + ' ' + urlCanary,
|
|
operation_key: 'GET /' + prefix + '-blocked',
|
|
source_location: { pointer: '/paths/~1' + prefix + '-blocked/get/schema/$ref' },
|
|
}],
|
|
})];
|
|
const response = previewResponse(prefix, operations);
|
|
await routeOperationsEmpty(page);
|
|
await page.route('**/api/admin/workspaces/*/imports/openapi/preview', async (route) => {
|
|
await route.fulfill({ contentType: 'application/json', body: JSON.stringify(response) });
|
|
});
|
|
await openImportModal(page, locale);
|
|
await uploadAndPreview(page, prefix, [[prefix + '-blocked', prefix + '_blocked']]);
|
|
|
|
const row = page.locator('.openapi-import-operation').first();
|
|
const selection = row.locator('[data-openapi-operation]');
|
|
await expect(selection).toBeDisabled();
|
|
await expect(row.locator('[data-testid="openapi-import-operation-readiness"]')).toHaveAttribute('data-state', 'blocked');
|
|
await expect(page.locator('[data-testid="openapi-import-blockers"]')).toContainText('external_reference_disabled');
|
|
await row.locator('.openapi-import-findings summary').click();
|
|
const finding = row.locator('.openapi-import-finding');
|
|
await expect(finding).toContainText('external_reference_disabled');
|
|
await expect(finding).toContainText(locale === 'en' ? /server allowlist/i : /список разрешённых адресов/i);
|
|
await expect(finding).toContainText(locale === 'en' ? /offline/i : /работы без сети/i);
|
|
await expect(finding).not.toContainText(sourceCanary);
|
|
await expect(finding).not.toContainText(urlCanary);
|
|
});
|
|
}
|
|
|
|
// AC-4: duplicate/invalid/taken names must show a deterministic rename
|
|
// proposal and conflict type, and the snapshot must stay unchanged.
|
|
test('[P1] AC-4 preview shows conflict type and deterministic rename proposal without mutating the snapshot', async ({ page }) => {
|
|
const prefix = uniqueName('preview_naming');
|
|
const operations = [candidate(prefix, 'clash', { suggested_name: 'shared_name' })];
|
|
const response = previewResponse(prefix, operations);
|
|
const planCalls = [];
|
|
response.preview.conflicts = [
|
|
{
|
|
operation_key: 'GET /' + prefix + '-clash',
|
|
conflict_type: 'taken_name',
|
|
proposed_name: 'shared_name_2',
|
|
source_location: { pointer: '/paths/~1' + prefix + '-clash/get' },
|
|
},
|
|
];
|
|
await routeOperationsEmpty(page);
|
|
await page.route('**/api/admin/workspaces/*/imports/openapi/preview', async (route) => {
|
|
await route.fulfill({
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(response),
|
|
});
|
|
});
|
|
await page.route(/\/imports\/openapi\/[^/]+\/plans$/, async (route) => {
|
|
planCalls.push(route.request().postDataJSON());
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(planResponse(prefix, [{
|
|
key: 'GET /' + prefix + '-clash',
|
|
name: 'reviewed_name',
|
|
state: 'actionable',
|
|
action: 'rename',
|
|
target_operation_id: null,
|
|
confirmed_name: 'reviewed_name',
|
|
auth_profile_id: null,
|
|
reason: null,
|
|
}], { selection_mode: 'full', counts: { selected: 1, excluded: 0, actionable: 1, blocked: 0 } })),
|
|
});
|
|
});
|
|
await openImportModal(page, 'en');
|
|
await uploadAndPreview(page, prefix, [[prefix + '-clash', prefix + '_clash']]);
|
|
|
|
const conflict = page.locator('[data-testid="openapi-import-conflict"]').first();
|
|
await expect(conflict).toContainText('taken_name');
|
|
const proposal = page.locator('[data-testid="openapi-import-rename-proposal"]').first();
|
|
await expect(proposal).toHaveValue('shared_name_2');
|
|
await page.locator('[data-openapi-decision-action]').selectOption('rename');
|
|
await proposal.fill('reviewed_name');
|
|
// The original snapshot name is still shown verbatim next to the proposal.
|
|
await expect(page.locator('.openapi-import-operation').first()).toContainText('clash');
|
|
expect(operations[0].suggested_name).toBe('shared_name');
|
|
expect(operations[0].draft.name).toBe(prefix + '_clash');
|
|
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();
|
|
expect(planCalls).toHaveLength(1);
|
|
expect(planCalls[0].decisions).toContainEqual(expect.objectContaining({
|
|
operation_key: 'GET /' + prefix + '-clash',
|
|
action: 'rename',
|
|
confirmed_name: 'reviewed_name',
|
|
}));
|
|
});
|
|
|
|
// AC-6: any blocker in full mode forbids Apply for the whole document while
|
|
// showing the full blocker count and affected candidates.
|
|
test('[P1] AC-6 full mode disables Apply and lists blocker count and affected candidates', async ({ page }) => {
|
|
const prefix = uniqueName('preview_blocker');
|
|
const operations = [
|
|
candidate(prefix, 'valid'),
|
|
candidate(prefix, 'broken', {
|
|
findings: [
|
|
{
|
|
code: 'unsupported_schema',
|
|
severity: 'error',
|
|
message: 'Unsupported schema',
|
|
operation_key: 'GET /' + prefix + '-broken',
|
|
source_location: { pointer: '/paths/~1' + prefix + '-broken/get' },
|
|
},
|
|
],
|
|
}),
|
|
];
|
|
await routeOperationsEmpty(page);
|
|
await page.route('**/api/admin/workspaces/*/imports/openapi/preview', async (route) => {
|
|
const response = previewResponse(prefix, operations);
|
|
response.preview.findings = [{ code: 'unsupported_document', severity: 'error', message: 'Document blocker' }];
|
|
await route.fulfill({
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(response),
|
|
});
|
|
});
|
|
await page.route(/\/imports\/openapi\/[^/]+\/plans$/, async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(planResponse(prefix, [
|
|
{
|
|
key: 'GET /' + prefix + '-valid',
|
|
name: 'valid',
|
|
state: 'actionable',
|
|
action: 'create',
|
|
target_operation_id: null,
|
|
confirmed_name: null,
|
|
auth_profile_id: null,
|
|
reason: null,
|
|
},
|
|
{
|
|
key: 'GET /' + prefix + '-broken',
|
|
name: 'broken',
|
|
state: 'blocked',
|
|
action: 'create',
|
|
target_operation_id: null,
|
|
confirmed_name: null,
|
|
auth_profile_id: null,
|
|
reason: 'unsupported_schema',
|
|
},
|
|
], {
|
|
selection_mode: 'full',
|
|
counts: { selected: 2, excluded: 0, actionable: 1, blocked: 1 },
|
|
})),
|
|
});
|
|
});
|
|
await openImportModal(page, 'en');
|
|
await uploadAndPreview(page, prefix, [
|
|
[prefix + '-valid', prefix + '_valid'],
|
|
[prefix + '-broken', prefix + '_broken'],
|
|
]);
|
|
await page.locator('#openapi-import-create').click();
|
|
|
|
const blockers = page.locator('[data-testid="openapi-import-blockers"]');
|
|
await expect(blockers).toContainText('1');
|
|
await expect(page.locator('[data-testid="openapi-import-apply-confirmation"]')).toContainText('broken');
|
|
await expect(page.locator('#openapi-import-plan-apply')).toBeDisabled();
|
|
await expect(page.locator('#openapi-import-partial-mode')).toBeDisabled();
|
|
await expect(page.locator('[data-testid="openapi-import-apply-result"]')).toBeHidden();
|
|
});
|
|
|
|
// AC-7: partial mode is enabled explicitly and accepts only an actionable,
|
|
// dependency-closed subset; excluded/blocked reasons stay visible.
|
|
test('[P1] AC-7 explicit partial mode submits only the actionable closed subset and shows excluded reasons', async ({ page }) => {
|
|
const prefix = uniqueName('preview_partial');
|
|
const planCalls = [];
|
|
const operations = [
|
|
candidate(prefix, 'keep'),
|
|
candidate(prefix, 'drop'),
|
|
candidate(prefix, 'blocked', { status: 'blocked' }),
|
|
candidate(prefix, 'typed_blocked'),
|
|
];
|
|
await routeOperationsEmpty(page);
|
|
await page.route('**/api/admin/workspaces/*/imports/openapi/preview', async (route) => {
|
|
const response = previewResponse(prefix, operations);
|
|
response.preview.findings = [{
|
|
code: 'unsupported_schema',
|
|
severity: 'error',
|
|
operation_key: 'GET /' + prefix + '-typed_blocked',
|
|
}];
|
|
await route.fulfill({
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(response),
|
|
});
|
|
});
|
|
await page.route(/\/imports\/openapi\/[^/]+\/plans$/, async (route) => {
|
|
planCalls.push(route.request().postDataJSON());
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(planResponse(prefix, [
|
|
{
|
|
key: 'GET /' + prefix + '-keep',
|
|
name: prefix + '_keep',
|
|
state: 'actionable',
|
|
action: 'create',
|
|
target_operation_id: null,
|
|
confirmed_name: null,
|
|
auth_profile_id: null,
|
|
reason: null,
|
|
},
|
|
{
|
|
key: 'GET /' + prefix + '-drop',
|
|
name: prefix + '_drop',
|
|
state: 'excluded',
|
|
action: null,
|
|
target_operation_id: null,
|
|
confirmed_name: null,
|
|
auth_profile_id: null,
|
|
reason: 'not_selected',
|
|
},
|
|
], {
|
|
selection_mode: 'partial',
|
|
counts: { selected: 1, excluded: 1, actionable: 1, blocked: 0 },
|
|
})),
|
|
});
|
|
});
|
|
await openImportModal(page, 'en');
|
|
await uploadAndPreview(page, prefix, [
|
|
[prefix + '-keep', prefix + '_keep'],
|
|
[prefix + '-drop', prefix + '_drop'],
|
|
[prefix + '-blocked', prefix + '_blocked'],
|
|
[prefix + '-typed_blocked', prefix + '_typed_blocked'],
|
|
]);
|
|
|
|
const partialToggle = page.locator('#openapi-import-partial-mode');
|
|
await expect(partialToggle).toBeVisible();
|
|
await partialToggle.check();
|
|
const blockedInput = page.locator('[data-openapi-operation][value="GET /' + prefix + '-blocked"]');
|
|
await expect(blockedInput).toBeDisabled();
|
|
const typedBlockedInput = page.locator('[data-openapi-operation][value="GET /' + prefix + '-typed_blocked"]');
|
|
await expect(typedBlockedInput).toBeDisabled();
|
|
await expect(partialToggle).toBeChecked();
|
|
await page.locator('#openapi-import-select-visible').click();
|
|
await expect(blockedInput).not.toBeChecked();
|
|
await expect(typedBlockedInput).not.toBeChecked();
|
|
for (const checkbox of await page.locator('[data-openapi-operation]').all()) {
|
|
const key = await checkbox.inputValue();
|
|
if (!key.includes('-keep') && !(await checkbox.isDisabled())) await checkbox.uncheck();
|
|
}
|
|
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();
|
|
|
|
expect(planCalls).toHaveLength(1);
|
|
expect(planCalls[0].selection_mode).toBe('partial');
|
|
expect(planCalls[0].selected_operation_keys).toEqual(['GET /' + prefix + '-keep']);
|
|
await expect(page.locator('[data-testid="openapi-import-excluded-reason"]')).toContainText('not_selected');
|
|
});
|
|
|
|
// AC-8: a changed selection/name/mapping/policy creates a new immutable plan
|
|
// version with a new digest while the previous version stays readable.
|
|
test('[P1] AC-8 changed selection and rename decision create an immutable plan version; old plan stays readable', async ({ page }) => {
|
|
const prefix = uniqueName('preview_version');
|
|
const operations = [candidate(prefix, 'one'), candidate(prefix, 'two')];
|
|
const references = ['plan_previous_e2e', 'plan_current_e2e'];
|
|
const digests = ['d'.repeat(64), 'e'.repeat(64)];
|
|
const planCalls = [];
|
|
const planReads = [];
|
|
let workspaceId = '';
|
|
await routeOperationsEmpty(page);
|
|
await page.route('**/api/admin/workspaces/*/imports/openapi/preview', async (route) => {
|
|
await route.fulfill({
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(previewResponse(prefix, operations)),
|
|
});
|
|
});
|
|
await page.route(/\/imports\/openapi\/[^/]+\/plans$/, async (route) => {
|
|
const payload = route.request().postDataJSON();
|
|
planCalls.push(payload);
|
|
workspaceId = decodeURIComponent(new URL(route.request().url()).pathname.match(/\/workspaces\/([^/]+)/)[1]);
|
|
const index = Math.min(planCalls.length - 1, digests.length - 1);
|
|
const planCandidates = index === 0
|
|
? operations.map((operation) => ({
|
|
key: operation.key,
|
|
name: operation.suggested_name,
|
|
state: 'actionable',
|
|
action: 'create',
|
|
target_operation_id: null,
|
|
confirmed_name: null,
|
|
auth_profile_id: null,
|
|
reason: null,
|
|
}))
|
|
: [
|
|
{
|
|
key: operations[0].key,
|
|
name: prefix + '_renamed',
|
|
state: 'actionable',
|
|
action: 'rename',
|
|
target_operation_id: null,
|
|
confirmed_name: prefix + '_renamed',
|
|
auth_profile_id: null,
|
|
reason: null,
|
|
},
|
|
{
|
|
key: operations[1].key,
|
|
name: operations[1].suggested_name,
|
|
state: 'excluded',
|
|
action: null,
|
|
target_operation_id: null,
|
|
confirmed_name: null,
|
|
auth_profile_id: null,
|
|
reason: 'not_selected',
|
|
},
|
|
];
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(planResponse(prefix, planCandidates, {
|
|
plan_reference: references[index],
|
|
plan_digest: digests[index],
|
|
selection_mode: index === 0 ? 'full' : 'partial',
|
|
counts: index === 0
|
|
? { selected: 2, excluded: 0, actionable: 2, blocked: 0 }
|
|
: { selected: 1, excluded: 1, actionable: 1, blocked: 0 },
|
|
})),
|
|
});
|
|
});
|
|
await page.route(/\/imports\/openapi\/plans\/[^/]+$/, async (route) => {
|
|
const reference = decodeURIComponent(new URL(route.request().url()).pathname.split('/').pop());
|
|
planReads.push(reference);
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(planResponse(prefix, operations.map((operation) => ({
|
|
key: operation.key,
|
|
name: operation.suggested_name,
|
|
state: 'actionable',
|
|
action: 'create',
|
|
target_operation_id: null,
|
|
confirmed_name: null,
|
|
auth_profile_id: null,
|
|
reason: null,
|
|
})), {
|
|
plan_reference: reference,
|
|
plan_digest: digests[0],
|
|
revalidation_status: 'current',
|
|
revalidation_required: false,
|
|
reason: null,
|
|
})),
|
|
});
|
|
});
|
|
await openImportModal(page, 'en');
|
|
await uploadAndPreview(page, prefix, [[prefix + '-one', prefix + '_one'], [prefix + '-two', prefix + '_two']]);
|
|
|
|
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-back').click();
|
|
await page.locator('#openapi-import-partial-mode').check();
|
|
await page.locator('[data-openapi-operation][value="GET /' + prefix + '-two"]').uncheck();
|
|
await page.locator('[data-openapi-decision-action]').first().selectOption('rename');
|
|
await page.locator('[data-openapi-decision-name]').first().fill(prefix + '_renamed');
|
|
await page.locator('#openapi-import-create').click();
|
|
await expect(page.locator('[data-testid="openapi-import-apply-confirmation"]')).toBeVisible();
|
|
|
|
expect(planCalls).toHaveLength(2);
|
|
expect(planCalls[0].selected_operation_keys).toEqual(['GET /' + prefix + '-one', 'GET /' + prefix + '-two']);
|
|
expect(planCalls[1].selection_mode).toBe('partial');
|
|
expect(planCalls[1].selected_operation_keys).toEqual(['GET /' + prefix + '-one']);
|
|
expect(planCalls[1].decisions).toContainEqual(expect.objectContaining({
|
|
operation_key: 'GET /' + prefix + '-one', action: 'rename', confirmed_name: prefix + '_renamed',
|
|
}));
|
|
await expect(page.locator('[data-testid="openapi-import-plan-version"]')).toContainText('2');
|
|
await expect(page.locator('[data-testid="openapi-import-plan-version"]')).toContainText(references[1]);
|
|
await expect(page.locator('[data-testid="openapi-import-plan-version"]')).toContainText(digests[1]);
|
|
|
|
const previousPlan = await page.evaluate(async ({ workspace, reference }) => {
|
|
return window.CrankApi.revalidateOpenApiImportPlan(workspace, reference, {});
|
|
}, { workspace: workspaceId, reference: references[0] });
|
|
expect(planReads).toEqual([references[0]]);
|
|
expect(previousPlan.plan_reference).toBe(references[0]);
|
|
expect(previousPlan.plan_digest).toBe(digests[0]);
|
|
expect(previousPlan.candidates).toHaveLength(2);
|
|
});
|
|
|
|
// AC-10: re-opening a stored plan after catalog/Auth Profile drift must show
|
|
// stale/revalidation-required authority instead of a guaranteed Apply.
|
|
test('[P1] AC-10 reopens plans read-only, fails closed when stale/errors, and ignores an older GET response', async ({ page }) => {
|
|
const prefix = uniqueName('preview_stale');
|
|
const planReference = 'plan_stale_e2e';
|
|
const planDigest = 'f'.repeat(64);
|
|
const revalidationCalls = [];
|
|
let finishFirstRead;
|
|
const firstReadGate = new Promise((resolve) => { finishFirstRead = resolve; });
|
|
let applyCalls = 0;
|
|
await routeOperationsEmpty(page);
|
|
await page.route('**/api/admin/workspaces/*/imports/openapi/preview', async (route) => {
|
|
await route.fulfill({
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(previewResponse(prefix, [candidate(prefix, 'one')])),
|
|
});
|
|
});
|
|
await page.route(/\/imports\/openapi\/[^/]+\/plans$/, async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(planResponse(prefix, [
|
|
{
|
|
key: 'GET /' + prefix + '-one',
|
|
name: prefix + '_one',
|
|
state: 'actionable',
|
|
action: 'create',
|
|
target_operation_id: null,
|
|
confirmed_name: null,
|
|
auth_profile_id: null,
|
|
reason: null,
|
|
},
|
|
], { plan_reference: planReference, plan_digest: planDigest })),
|
|
});
|
|
});
|
|
await page.route(/\/imports\/openapi\/plans\/[^/]+$/, async (route) => {
|
|
const call = revalidationCalls.length + 1;
|
|
const reference = decodeURIComponent(new URL(route.request().url()).pathname.split('/').pop());
|
|
revalidationCalls.push(reference);
|
|
if (call === 1) await firstReadGate;
|
|
if (call === 4) {
|
|
await route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ message: 'temporary read failure' }) });
|
|
return;
|
|
}
|
|
const current = call === 2;
|
|
const response = planResponse(prefix, [{
|
|
key: 'GET /' + prefix + '-one',
|
|
name: prefix + '_one',
|
|
state: 'actionable',
|
|
action: 'create',
|
|
target_operation_id: null,
|
|
confirmed_name: null,
|
|
auth_profile_id: null,
|
|
reason: null,
|
|
}], {
|
|
plan_reference: reference,
|
|
plan_digest: planDigest,
|
|
revalidation_status: current ? 'current' : 'stale',
|
|
revalidation_required: !current,
|
|
reason: current ? null : 'catalog_changed',
|
|
});
|
|
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(response) });
|
|
});
|
|
await page.route(/\/imports\/openapi\/[^/]+\/apply$/, async (route) => {
|
|
applyCalls += 1;
|
|
await route.fulfill({ status: 500, contentType: 'application/json', body: JSON.stringify({ message: 'Apply must not run' }) });
|
|
});
|
|
await openImportModal(page, 'en');
|
|
await uploadAndPreview(page, prefix, [[prefix + '-one', prefix + '_one']]);
|
|
await page.locator('#openapi-import-create').click();
|
|
await expect(page.locator('[data-testid="openapi-import-apply-confirmation"]')).toBeVisible();
|
|
|
|
const reopen = page.locator('[data-testid="openapi-import-plan-reopen"]');
|
|
await expect(reopen).toHaveAccessibleName('Reopen and check current plan');
|
|
const firstRequest = page.waitForRequest((request) => request.method() === 'GET' && request.url().includes('/imports/openapi/plans/' + planReference));
|
|
await reopen.click();
|
|
await firstRequest;
|
|
const secondResponse = page.waitForResponse((response) => response.request().method() === 'GET' && response.url().includes('/imports/openapi/plans/' + planReference));
|
|
await reopen.click();
|
|
await secondResponse;
|
|
await expect(page.locator('[data-testid="openapi-import-plan-revalidation-status"]')).toContainText(localized('current', 'актуален'));
|
|
await expect(page.locator('#openapi-import-plan-apply')).toBeEnabled();
|
|
const firstResponse = page.waitForResponse((response) => response.request().method() === 'GET' && response.url().includes('/imports/openapi/plans/' + planReference));
|
|
finishFirstRead();
|
|
await firstResponse;
|
|
await expect(page.locator('[data-testid="openapi-import-plan-revalidation-status"]')).toContainText(localized('current', 'актуален'));
|
|
await expect(page.locator('#openapi-import-plan-apply')).toBeEnabled();
|
|
|
|
await reopen.click();
|
|
await expect(page.locator('[data-testid="openapi-import-plan-stale"]')).toBeVisible();
|
|
await expect(page.locator('[data-testid="openapi-import-plan-stale"]')).toContainText(localized('create a new plan', 'создайте новый план'));
|
|
await expect(page.locator('#openapi-import-plan-apply')).toBeDisabled();
|
|
await reopen.click();
|
|
await expect(page.locator('[data-testid="openapi-import-plan-revalidation-status"]')).toContainText(localized('could not be verified', 'Не удалось проверить'));
|
|
await expect(page.locator('[data-testid="openapi-import-plan-stale"]')).toContainText(localized('create a new plan', 'создайте новый план'));
|
|
await expect(page.locator('#openapi-import-plan-apply')).toBeDisabled();
|
|
expect(revalidationCalls).toEqual([planReference, planReference, planReference, planReference]);
|
|
expect(applyCalls).toBe(0);
|
|
});
|
|
|
|
// AC-11: a large preview must render bounded pages over up to 2,000 candidates
|
|
// without an unbounded DOM, while search/filter/grouping and selection survive
|
|
// page changes.
|
|
test('[P1] AC-11 renders bounded pages for 2000 candidates and preserves selection across pages', async ({ page }, testInfo) => {
|
|
test.setTimeout(120_000);
|
|
const prefix = uniqueName('preview_large');
|
|
const operations = [];
|
|
for (let index = 0; index < 2000; index += 1) {
|
|
operations.push(candidate(prefix, 'op_' + index));
|
|
}
|
|
const planCalls = [];
|
|
await routeOperationsEmpty(page);
|
|
await page.route('**/api/admin/workspaces/*/imports/openapi/preview', async (route) => {
|
|
const response = previewResponse(prefix, operations);
|
|
response.preview.findings = [{
|
|
code: 'document_notice', severity: 'warning', message: 'Document-wide sample finding',
|
|
}];
|
|
await route.fulfill({
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(response),
|
|
});
|
|
});
|
|
await page.route(/\/imports\/openapi\/[^/]+\/plans$/, async (route) => {
|
|
planCalls.push(route.request().postDataJSON());
|
|
const candidates = operations.map((operation, index) => {
|
|
const excluded = index === 0 || index === 100;
|
|
return {
|
|
key: operation.key,
|
|
name: operation.suggested_name,
|
|
state: excluded ? 'excluded' : 'actionable',
|
|
action: excluded ? null : 'create',
|
|
target_operation_id: null,
|
|
confirmed_name: null,
|
|
auth_profile_id: null,
|
|
reason: excluded ? 'not_selected' : null,
|
|
};
|
|
});
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(planResponse(prefix, candidates, {
|
|
selection_mode: 'partial',
|
|
counts: { selected: 1998, excluded: 2, actionable: 1998, blocked: 0 },
|
|
})),
|
|
});
|
|
});
|
|
await openImportModal(page, 'en');
|
|
await uploadAndPreview(page, prefix, [[prefix + '-op_0', prefix + '_op_0']]);
|
|
|
|
const pager = page.locator('[data-testid="openapi-import-pagination"]');
|
|
await expect(pager).toBeVisible();
|
|
const rendered = page.locator('.openapi-import-operation');
|
|
expect(await rendered.count()).toBeLessThanOrEqual(100);
|
|
await expect(page.locator('[data-testid="openapi-import-page-status"]')).toContainText('2000');
|
|
|
|
await page.locator('#openapi-import-partial-mode').check();
|
|
const groupToggle = page.locator('.openapi-import-group [data-openapi-group]');
|
|
await expect(page.locator('.openapi-import-group-toggle')).toContainText('Select group on this page');
|
|
const russianLabel = await page.evaluate(() => {
|
|
localStorage.setItem('crank_lang', 'ru');
|
|
const label = window.t('openapi.group.select');
|
|
localStorage.setItem('crank_lang', 'en');
|
|
return label;
|
|
});
|
|
expect(russianLabel).toBe('Выбрать группу на этой странице');
|
|
const firstPageFirst = page.locator('[data-openapi-operation]').first();
|
|
const firstPageFirstKey = await firstPageFirst.inputValue();
|
|
await firstPageFirst.uncheck();
|
|
await groupToggle.check();
|
|
await groupToggle.uncheck();
|
|
await expect(page.locator('#openapi-import-selection')).toContainText('Selected: 1900');
|
|
await pager.getByRole('button', { name: localized('Next', 'Далее') }).click();
|
|
await expect(page.locator('[data-openapi-operation]').first()).toBeChecked();
|
|
await pager.getByRole('button', { name: localized('Previous', 'Назад') }).click();
|
|
await groupToggle.check();
|
|
await firstPageFirst.uncheck();
|
|
await pager.getByRole('button', { name: localized('Next', 'Далее') }).click();
|
|
await expect(page.locator('[data-testid="openapi-import-page-status"]')).toContainText(localized('Page 2', 'Страница 2'));
|
|
const documentFindings = page.locator('.openapi-import-document-findings');
|
|
await expect(documentFindings.locator('summary')).toContainText('Findings: 1');
|
|
await documentFindings.locator('summary').click();
|
|
await expect(documentFindings).toContainText('document_notice');
|
|
expect(await rendered.count()).toBeLessThanOrEqual(100);
|
|
const secondPageFirst = page.locator('[data-openapi-operation]').first();
|
|
const secondPageFirstKey = await secondPageFirst.inputValue();
|
|
await secondPageFirst.uncheck();
|
|
await pager.getByRole('button', { name: localized('Previous', 'Назад') }).click();
|
|
await expect(page.locator(`[data-openapi-operation][value="${firstPageFirstKey}"]`)).not.toBeChecked();
|
|
await pager.getByRole('button', { name: localized('Next', 'Далее') }).click();
|
|
await expect(page.locator(`[data-openapi-operation][value="${secondPageFirstKey}"]`)).not.toBeChecked();
|
|
|
|
await page.locator('#openapi-import-search').fill('op_1999');
|
|
await expect(page.locator('[data-openapi-operation]')).toHaveCount(1);
|
|
await expect(page.locator('[data-openapi-operation]').first()).toBeChecked();
|
|
await expect(page.locator('[data-testid="openapi-import-page-status"]')).toContainText('1 matching operations');
|
|
const previewMetrics = await page.evaluate(() => {
|
|
const search = document.querySelector('#openapi-import-search');
|
|
const next = document.querySelector('#openapi-import-page-next');
|
|
const previous = document.querySelector('#openapi-import-page-previous');
|
|
const samples = { search_filter_ms: [], page_change_ms: [] };
|
|
for (let index = 0; index < 20; index += 1) {
|
|
const startSearch = performance.now();
|
|
search.value = 'op_' + (index * 10);
|
|
search.dispatchEvent(new Event('input', { bubbles: true }));
|
|
samples.search_filter_ms.push(Number((performance.now() - startSearch).toFixed(3)));
|
|
search.value = '';
|
|
search.dispatchEvent(new Event('input', { bubbles: true }));
|
|
const startPage = performance.now();
|
|
next.click();
|
|
samples.page_change_ms.push(Number((performance.now() - startPage).toFixed(3)));
|
|
previous.click();
|
|
}
|
|
return {
|
|
user_agent: navigator.userAgent,
|
|
platform: navigator.platform,
|
|
hardware_concurrency: navigator.hardwareConcurrency || null,
|
|
viewport: { width: innerWidth, height: innerHeight },
|
|
search_filter_ms: samples.search_filter_ms,
|
|
page_change_ms: samples.page_change_ms,
|
|
};
|
|
});
|
|
await page.locator('#openapi-import-search').fill('op_1999');
|
|
await expect(page.locator('[data-openapi-operation]')).toHaveCount(1);
|
|
await expect(page.locator('[data-openapi-operation]').first()).toBeChecked();
|
|
await expect(page.locator('[data-testid="openapi-import-page-status"]')).toContainText('1 matching operations');
|
|
await page.locator('#openapi-import-search').fill('');
|
|
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();
|
|
expect(planCalls).toHaveLength(1);
|
|
expect(planCalls[0].selection_mode).toBe('partial');
|
|
expect(planCalls[0].selected_operation_keys).toHaveLength(1998);
|
|
const planRows = page.locator('.openapi-import-plan-candidate');
|
|
expect(await planRows.count()).toBeLessThanOrEqual(100);
|
|
await expect(page.locator('[data-testid="openapi-import-plan-page-status"]')).toContainText('2000');
|
|
await page.locator('#openapi-import-plan-page-next').click();
|
|
expect(await planRows.count()).toBeLessThanOrEqual(100);
|
|
await expect(planRows.first()).toContainText(prefix + '_op_100');
|
|
const planMetrics = await page.evaluate(() => {
|
|
const next = document.querySelector('#openapi-import-plan-page-next');
|
|
const previous = document.querySelector('#openapi-import-plan-page-previous');
|
|
const samples = [];
|
|
for (let index = 0; index < 10; index += 1) {
|
|
let start = performance.now();
|
|
previous.click();
|
|
samples.push(Number((performance.now() - start).toFixed(3)));
|
|
start = performance.now();
|
|
next.click();
|
|
samples.push(Number((performance.now() - start).toFixed(3)));
|
|
}
|
|
return samples;
|
|
});
|
|
await testInfo.attach('ac11-local-shared-host-metrics.json', {
|
|
body: Buffer.from(JSON.stringify({
|
|
scope: 'LOCAL shared-host browser-handler samples; not Reference Deployment LAN evidence',
|
|
environment: {
|
|
user_agent: previewMetrics.user_agent,
|
|
platform: previewMetrics.platform,
|
|
hardware_concurrency: previewMetrics.hardware_concurrency,
|
|
viewport: previewMetrics.viewport,
|
|
},
|
|
candidates: 2000,
|
|
max_operation_rows: 100,
|
|
max_plan_candidate_rows: 100,
|
|
samples: {
|
|
search_filter_ms: previewMetrics.search_filter_ms,
|
|
preview_page_change_ms: previewMetrics.page_change_ms,
|
|
plan_page_change_ms: planMetrics,
|
|
},
|
|
}, null, 2)),
|
|
contentType: 'application/json',
|
|
});
|
|
console.log('AC11_LOCAL_SHARED_HOST_METRICS ' + JSON.stringify({
|
|
environment: {
|
|
user_agent: previewMetrics.user_agent,
|
|
platform: previewMetrics.platform,
|
|
hardware_concurrency: previewMetrics.hardware_concurrency,
|
|
viewport: previewMetrics.viewport,
|
|
},
|
|
candidates: 2000,
|
|
max_operation_rows: 100,
|
|
max_plan_candidate_rows: 100,
|
|
samples: {
|
|
search_filter_ms: previewMetrics.search_filter_ms,
|
|
preview_page_change_ms: previewMetrics.page_change_ms,
|
|
plan_page_change_ms: planMetrics,
|
|
},
|
|
}));
|
|
});
|
|
|
|
test('[P1] AC-11 keeps skipped apply outcomes accessible through bounded pages', async ({ page }) => {
|
|
const prefix = uniqueName('preview_skipped_pages');
|
|
const operation = candidate(prefix, 'one');
|
|
await routeOperationsEmpty(page);
|
|
await page.route('**/api/admin/workspaces/*/imports/openapi/preview', async (route) => {
|
|
await route.fulfill({ contentType: 'application/json', body: JSON.stringify(previewResponse(prefix, [operation])) });
|
|
});
|
|
await page.route(/\/imports\/openapi\/[^/]+\/plans$/, async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(planResponse(prefix, [{
|
|
key: operation.key,
|
|
name: operation.suggested_name,
|
|
state: 'actionable',
|
|
action: 'create',
|
|
target_operation_id: null,
|
|
confirmed_name: null,
|
|
auth_profile_id: null,
|
|
reason: null,
|
|
}], { counts: { selected: 1, excluded: 0, actionable: 1, blocked: 0 } })),
|
|
});
|
|
});
|
|
await page.route(/\/imports\/openapi\/[^/]+\/apply$/, async (route) => {
|
|
const skipped = Array.from({ length: 250 }, (_, index) => ({
|
|
operation_key: 'GET /' + prefix + '-skipped-' + index,
|
|
name: prefix + '_skipped_' + index,
|
|
reason: 'not_selected',
|
|
}));
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ created: [], skipped, findings: [] }),
|
|
});
|
|
});
|
|
await openImportModal(page, 'en');
|
|
await uploadAndPreview(page, prefix, [[prefix + '-one', prefix + '_one']]);
|
|
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();
|
|
|
|
const skipped = page.locator('.openapi-import-result-skipped');
|
|
await expect(skipped.locator('summary')).toContainText('250');
|
|
await skipped.locator('summary').click();
|
|
await expect(skipped.locator('li')).toHaveCount(100);
|
|
await expect(skipped.locator('[role="status"]')).toContainText('Page 1 of 3');
|
|
await skipped.getByRole('button', { name: localized('Next', 'Далее') }).click();
|
|
await expect(skipped.locator('li').first()).toContainText(prefix + '_skipped_100');
|
|
await expect(skipped.locator('li')).toHaveCount(100);
|
|
});
|
|
|
|
// AC-12: RU/EN upload states (uploading, parsing, loading, empty/no-methods,
|
|
// error, stale, confirmation) plus a request-generation guard that prevents an
|
|
// older preview from overwriting a newer file or selection.
|
|
test('[P1] AC-12 exposes RU/EN live import states and discards stale preview/revalidation responses', async ({ page }) => {
|
|
const prefix = uniqueName('preview_states');
|
|
const firstStaleCandidate = candidate(prefix, 'stale_file');
|
|
const actionable = candidate(prefix, 'actionable', { status: 'actionable' });
|
|
const blocked = candidate(prefix, 'blocked', { status: 'blocked' });
|
|
const operations = [actionable, blocked];
|
|
let releaseFirstPreview;
|
|
let finishFirstPreview;
|
|
let releaseOperations;
|
|
let releaseSelectionRead;
|
|
let releaseCurrentPreview;
|
|
let releaseRuPreview;
|
|
let releaseRuOperations;
|
|
let gateRuOperations = false;
|
|
const firstPreviewGate = new Promise((resolve) => { releaseFirstPreview = resolve; });
|
|
const operationsGate = new Promise((resolve) => { releaseOperations = resolve; });
|
|
const selectionReadGate = new Promise((resolve) => { releaseSelectionRead = resolve; });
|
|
const currentPreviewGate = new Promise((resolve) => { releaseCurrentPreview = resolve; });
|
|
const ruPreviewGate = new Promise((resolve) => { releaseRuPreview = resolve; });
|
|
const ruOperationsGate = new Promise((resolve) => { releaseRuOperations = resolve; });
|
|
const firstPreviewFinished = new Promise((resolve) => { finishFirstPreview = resolve; });
|
|
let previewCalls = 0;
|
|
let planCalls = 0;
|
|
let revalidationCalls = 0;
|
|
let staleApplyCalls = 0;
|
|
await routeOperationsEmpty(page);
|
|
await page.route('**/api/admin/workspaces/*/imports/openapi/preview', async (route) => {
|
|
previewCalls += 1;
|
|
if (previewCalls === 1) {
|
|
await firstPreviewGate;
|
|
try {
|
|
await route.fulfill({ contentType: 'application/json', body: JSON.stringify(previewResponse(prefix, [firstStaleCandidate])) });
|
|
} catch (_error) {
|
|
// The selected file replacement aborts this older request.
|
|
} finally {
|
|
finishFirstPreview();
|
|
}
|
|
return;
|
|
}
|
|
if (previewCalls === 2 || previewCalls === 5) {
|
|
if (previewCalls === 2) await currentPreviewGate;
|
|
if (previewCalls === 5) await ruPreviewGate;
|
|
await route.fulfill({ contentType: 'application/json', body: JSON.stringify(previewResponse(prefix, operations)) });
|
|
return;
|
|
}
|
|
const code = previewCalls === 4 || previewCalls === 7 ? 'openapi_upload.no_methods' : 'openapi_upload.invalid_document';
|
|
await route.fulfill({
|
|
status: 400,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ error: { code, message: code } }),
|
|
});
|
|
});
|
|
await page.route('**/api/admin/workspaces/*/operations', async (route) => {
|
|
if (gateRuOperations) await ruOperationsGate;
|
|
else await operationsGate;
|
|
await route.fulfill({ contentType: 'application/json', body: JSON.stringify({ items: [], page: 1, page_size: 0, total: 0 }) });
|
|
});
|
|
await page.route(/\/imports\/openapi\/[^/]+\/plans$/, async (route) => {
|
|
planCalls += 1;
|
|
const second = planCalls > 1;
|
|
const candidates = second
|
|
? [{ key: actionable.key, name: actionable.suggested_name, state: 'actionable', action: 'create', target_operation_id: null, confirmed_name: null, auth_profile_id: null, reason: null },
|
|
{ key: blocked.key, name: blocked.suggested_name, state: 'excluded', action: null, target_operation_id: null, confirmed_name: null, auth_profile_id: null, reason: 'not_selected' }]
|
|
: operations.map((operation) => ({ key: operation.key, name: operation.suggested_name, state: operation.status, action: operation.status === 'actionable' ? 'create' : null, target_operation_id: null, confirmed_name: null, auth_profile_id: null, reason: operation.status === 'blocked' ? 'unsupported_schema' : null }));
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(planResponse(prefix, candidates, {
|
|
plan_reference: 'plan_ac12_' + planCalls,
|
|
plan_digest: String(planCalls).padStart(64, 'a'),
|
|
selection_mode: second ? 'partial' : 'full',
|
|
counts: second
|
|
? { selected: 1, excluded: 1, actionable: 1, blocked: 0 }
|
|
: { selected: 2, excluded: 0, actionable: 1, blocked: 1 },
|
|
})),
|
|
});
|
|
});
|
|
await page.route(/\/imports\/openapi\/plans\/[^/]+$/, async (route) => {
|
|
revalidationCalls += 1;
|
|
const stale = { plan_reference: 'plan_ac12_1', plan_digest: '1'.padStart(64, 'a'), revalidation_status: 'stale', revalidation_required: true, reason: 'catalog_changed', counts: { selected: 2, excluded: 0, actionable: 1, blocked: 1 }, candidates: [] };
|
|
if (revalidationCalls === 1) {
|
|
await selectionReadGate;
|
|
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(stale) });
|
|
return;
|
|
}
|
|
const currentPlan = 'plan_ac12_' + planCalls;
|
|
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(Object.assign({}, stale, {
|
|
plan_reference: currentPlan,
|
|
plan_digest: String(planCalls).padStart(64, 'a'),
|
|
})) });
|
|
});
|
|
await page.route(/\/imports\/openapi\/[^/]+\/apply$/, async (route) => {
|
|
staleApplyCalls += 1;
|
|
await route.fulfill({ status: 500, contentType: 'application/json', body: JSON.stringify({ message: 'Apply must not run' }) });
|
|
});
|
|
await openImportModal(page, 'en');
|
|
|
|
await page.locator('#openapi-import-file').setInputFiles({
|
|
name: 'states-a.yaml',
|
|
mimeType: 'application/yaml',
|
|
buffer: Buffer.from(importDocument(prefix, [[prefix + '-stale_file', prefix + '_stale_file']])),
|
|
});
|
|
const firstPreview = page.waitForRequest((request) => request.method() === 'POST' && request.url().includes('/imports/openapi/preview'));
|
|
const previewButton = page.locator('#openapi-import-preview');
|
|
await previewButton.focus();
|
|
await expect(previewButton).toBeFocused();
|
|
await previewButton.press('Enter');
|
|
const status = page.locator('#openapi-import-status');
|
|
await expect(status).toHaveAttribute('role', 'status');
|
|
await expect(status).toHaveAttribute('aria-live', 'polite');
|
|
await page.evaluate(() => {
|
|
const node = document.querySelector('#openapi-import-status');
|
|
window.__openapiStatusHistory = [node.textContent];
|
|
new MutationObserver(() => window.__openapiStatusHistory.push(node.textContent))
|
|
.observe(node, { childList: true, characterData: true, subtree: true });
|
|
});
|
|
await expect(status).toContainText('Uploading');
|
|
await firstPreview;
|
|
|
|
// Replace the file while the first preview is still in flight.
|
|
await page.locator('#openapi-import-file').setInputFiles({
|
|
name: 'states-current.yaml',
|
|
mimeType: 'application/yaml',
|
|
buffer: Buffer.from(importDocument(prefix, [[prefix + '-actionable', prefix + '_actionable'], [prefix + '-blocked', prefix + '_blocked']])),
|
|
});
|
|
const currentPreview = page.waitForResponse((response) => response.request().method() === 'POST' && response.url().includes('/imports/openapi/preview'));
|
|
await page.locator('#openapi-import-preview').click();
|
|
await expect(status).toContainText('Uploading');
|
|
releaseCurrentPreview();
|
|
await currentPreview;
|
|
await expect(status).toContainText('Checking existing workspace operations');
|
|
releaseOperations();
|
|
await expect(status).toContainText('Document is ready');
|
|
const enStatusHistory = await page.evaluate(() => window.__openapiStatusHistory);
|
|
expect(enStatusHistory.some((message) => message.includes('Parsing the OpenAPI document'))).toBe(true);
|
|
await expect(page.locator('[data-testid="openapi-import-operation-readiness"][data-state="actionable"]')).toHaveAccessibleName('Actionable');
|
|
await expect(page.locator('[data-testid="openapi-import-operation-readiness"][data-state="blocked"]')).toHaveAccessibleName('Blocked');
|
|
releaseFirstPreview();
|
|
await firstPreviewFinished;
|
|
await expect(status).toContainText('Document is ready');
|
|
await expect(page.locator('.openapi-import-operation').first()).not.toContainText('stale_file');
|
|
|
|
await page.locator('#openapi-import-create').click();
|
|
await expect(page.locator('[data-testid="openapi-import-apply-confirmation"]')).toBeVisible();
|
|
await expect(status).toContainText('Review the server plan');
|
|
const reopen = page.locator('#openapi-import-plan-reopen');
|
|
await reopen.click();
|
|
await page.locator('#openapi-import-plan-back').click();
|
|
await page.locator('#openapi-import-partial-mode').check();
|
|
await page.locator('#openapi-import-create').click();
|
|
await expect(page.locator('[data-testid="openapi-import-plan-version"]')).toContainText('plan_ac12_2');
|
|
releaseSelectionRead();
|
|
await expect(page.locator('[data-testid="openapi-import-plan-version"]')).toContainText('plan_ac12_2');
|
|
await expect(page.locator('[data-testid="openapi-import-plan-revalidation-status"]')).toContainText('current');
|
|
expect(planCalls).toBe(2);
|
|
|
|
await reopen.click();
|
|
await expect(page.locator('[data-testid="openapi-import-plan-stale"]')).toBeVisible();
|
|
await expect(page.locator('#openapi-import-plan-apply')).toBeDisabled();
|
|
await page.locator('#openapi-import-plan-back').click();
|
|
|
|
await page.locator('#openapi-import-file').setInputFiles({ name: 'invalid.yaml', mimeType: 'application/yaml', buffer: Buffer.from('openapi: [') });
|
|
await page.locator('#openapi-import-preview').click();
|
|
await expect(status).toContainText(localized('not a valid', 'некоррект'));
|
|
await page.locator('#openapi-import-file').setInputFiles({ name: 'empty.yaml', mimeType: 'application/yaml', buffer: Buffer.from('') });
|
|
await expect(status).toContainText(localized('empty', 'пуст'));
|
|
await page.locator('#openapi-import-file').setInputFiles({ name: 'large.yaml', mimeType: 'application/yaml', buffer: Buffer.alloc(256 * 1024 + 1, 32) });
|
|
await expect(status).toContainText('256');
|
|
await page.locator('#openapi-import-file').setInputFiles({ name: 'no-methods.yaml', mimeType: 'application/yaml', buffer: Buffer.from("openapi: 3.0.3\ninfo: {title: Empty, version: '1'}\npaths: {}\n") });
|
|
await page.locator('#openapi-import-preview').click();
|
|
await expect(status).toContainText(localized('does not contain importable methods', 'нет поддерживаемых методов'));
|
|
expect(previewCalls).toBe(4);
|
|
expect(staleApplyCalls).toBe(0);
|
|
|
|
await page.evaluate(() => window.setLang('ru'));
|
|
gateRuOperations = true;
|
|
await page.locator('#openapi-import-file').setInputFiles({
|
|
name: 'states-ru.yaml', mimeType: 'application/yaml',
|
|
buffer: Buffer.from(importDocument(prefix, [[prefix + '-actionable', prefix + '_actionable'], [prefix + '-blocked', prefix + '_blocked']])),
|
|
});
|
|
const ruPreview = page.waitForResponse((response) => response.request().method() === 'POST' && response.url().includes('/imports/openapi/preview'));
|
|
await page.locator('#openapi-import-preview').click();
|
|
await expect(status).toContainText('Загружаю');
|
|
releaseRuPreview();
|
|
await ruPreview;
|
|
await expect(status).toContainText('Проверяю существующие операции');
|
|
releaseRuOperations();
|
|
await expect(status).toContainText('Документ готов');
|
|
const ruStatusHistory = await page.evaluate(() => window.__openapiStatusHistory);
|
|
expect(ruStatusHistory.some((message) => message.includes('Разбираю документ OpenAPI'))).toBe(true);
|
|
await expect(page.locator('[data-testid="openapi-import-operation-readiness"][data-state="actionable"]')).toHaveAccessibleName('Можно импортировать');
|
|
await expect(page.locator('[data-testid="openapi-import-operation-readiness"][data-state="blocked"]')).toHaveAccessibleName('Заблокировано');
|
|
await page.locator('#openapi-import-create').click();
|
|
await expect(page.locator('[data-testid="openapi-import-apply-confirmation"]')).toBeVisible();
|
|
await expect(status).toContainText('Проверьте план сервера');
|
|
await page.locator('#openapi-import-plan-reopen').click();
|
|
await expect(page.locator('[data-testid="openapi-import-plan-stale"]')).toContainText('создайте новый план');
|
|
await expect(page.locator('#openapi-import-plan-apply')).toBeDisabled();
|
|
await page.locator('#openapi-import-plan-back').click();
|
|
await page.locator('#openapi-import-file').setInputFiles({ name: 'empty-ru.yaml', mimeType: 'application/yaml', buffer: Buffer.from('') });
|
|
await expect(status).toContainText('пуст');
|
|
await page.locator('#openapi-import-file').setInputFiles({ name: 'large-ru.yaml', mimeType: 'application/yaml', buffer: Buffer.alloc(256 * 1024 + 1, 32) });
|
|
await expect(status).toContainText('256');
|
|
await page.locator('#openapi-import-file').setInputFiles({ name: 'invalid-ru.yaml', mimeType: 'application/yaml', buffer: Buffer.from('openapi: [') });
|
|
await page.locator('#openapi-import-preview').click();
|
|
await expect(status).toContainText('не является корректным');
|
|
await page.locator('#openapi-import-file').setInputFiles({ name: 'no-methods-ru.yaml', mimeType: 'application/yaml', buffer: Buffer.from("openapi: 3.0.3\ninfo: {title: Empty, version: '1'}\npaths: {}\n") });
|
|
await page.locator('#openapi-import-preview').click();
|
|
await expect(status).toContainText('нет методов для импорта');
|
|
expect(previewCalls).toBe(7);
|
|
expect(revalidationCalls).toBe(3);
|
|
});
|
|
|
|
// AC-13: end-to-end upload regression across valid, invalid, empty, oversized
|
|
// and no-method documents, with no Operations created before Apply.
|
|
test('[P1] AC-13 real upload round-trip validates YAML and rejects invalid inputs without Operation mutations', async ({ page }) => {
|
|
const prefix = uniqueName('preview_upload');
|
|
await openImportModal(page, 'en');
|
|
const workspace = await getCurrentWorkspace(page);
|
|
expect(workspace && workspace.id).toBeTruthy();
|
|
const readOperations = async () => page.evaluate(async (workspaceId) => window.CrankApi.listOperations(workspaceId), workspace.id);
|
|
const operationSignature = (result) => ({
|
|
total: result.total,
|
|
items: result.items.map((item) => ({ id: item.id, name: item.name, operation_id: item.operation_id, version: item.version })),
|
|
});
|
|
const baseline = operationSignature(await readOperations());
|
|
let previewPosts = 0;
|
|
let operationPosts = 0;
|
|
page.on('request', (request) => {
|
|
const url = new URL(request.url());
|
|
if (request.method() === 'POST' && url.pathname.endsWith('/imports/openapi/preview')) previewPosts += 1;
|
|
if (request.method() === 'POST' && /\/operations\/?$/.test(url.pathname)) operationPosts += 1;
|
|
});
|
|
|
|
// A YAML key containing quotes exercises operation-key rendering without CSS-selector interpolation.
|
|
const specialPath = '/' + prefix + '-"quoted"-path';
|
|
const validYaml = [
|
|
'openapi: 3.0.3',
|
|
"info: { title: 'Preview local round trip', version: '1' }",
|
|
"servers: [{ url: 'https://api.example.test' }]",
|
|
'paths:',
|
|
" '" + specialPath + "':",
|
|
' post:',
|
|
' operationId: ' + prefix + '_special',
|
|
' responses:',
|
|
" '200': { description: OK }",
|
|
'',
|
|
].join('\n');
|
|
await page.locator('#openapi-import-file').setInputFiles({
|
|
name: 'valid.yaml',
|
|
mimeType: 'application/yaml',
|
|
buffer: Buffer.from(validYaml),
|
|
});
|
|
await page.locator('#openapi-import-preview').click();
|
|
await expect(page.locator('#openapi-import-preview-panel')).toBeVisible();
|
|
const row = page.locator('.openapi-import-operation').first();
|
|
await expect(row).toContainText(specialPath);
|
|
await expect(row).toContainText('POST');
|
|
await expect(page.locator('[data-openapi-operation]').first()).toBeChecked();
|
|
await expect(row.locator('[data-testid="openapi-import-operation-readiness"]')).toHaveAccessibleName('Actionable');
|
|
|
|
// Malformed documents are rejected by the real preview endpoint.
|
|
await page.locator('#openapi-import-file').setInputFiles({
|
|
name: 'invalid.yaml', mimeType: 'application/yaml', buffer: Buffer.from('openapi: [')
|
|
});
|
|
await page.locator('#openapi-import-preview').click();
|
|
await expect(page.locator('#openapi-import-status')).toContainText(localized('not a valid', 'некоррект'));
|
|
|
|
// Empty and oversized files are rejected locally and must not POST previews.
|
|
await page.locator('#openapi-import-file').setInputFiles({
|
|
name: 'empty.yaml',
|
|
mimeType: 'application/yaml',
|
|
buffer: Buffer.from(''),
|
|
});
|
|
await expect(page.locator('#openapi-import-status')).toContainText(localized('empty', 'пуст'));
|
|
await page.locator('#openapi-import-preview').click();
|
|
await expect(page.locator('#openapi-import-status')).toContainText(localized('empty', 'пуст'));
|
|
await page.locator('#openapi-import-file').setInputFiles({
|
|
name: 'oversized.yaml', mimeType: 'application/yaml', buffer: Buffer.alloc(256 * 1024 + 1, 32),
|
|
});
|
|
await expect(page.locator('#openapi-import-status')).toContainText('256');
|
|
await page.locator('#openapi-import-preview').click();
|
|
await expect(page.locator('#openapi-import-status')).toContainText('256');
|
|
|
|
// A syntactically valid document with no supported methods reaches the real endpoint.
|
|
await page.locator('#openapi-import-file').setInputFiles({
|
|
name: 'no-methods.yaml',
|
|
mimeType: 'application/yaml',
|
|
buffer: Buffer.from("openapi: 3.0.3\ninfo: { title: Empty, version: '1' }\npaths: {}\n"),
|
|
});
|
|
await page.locator('#openapi-import-preview').click();
|
|
await expect(page.locator('#openapi-import-status')).toContainText(localized('does not contain importable methods', 'нет поддерживаемых методов'));
|
|
|
|
expect(previewPosts).toBe(3);
|
|
expect(operationPosts).toBe(0);
|
|
const after = operationSignature(await readOperations());
|
|
expect(after).toEqual(baseline);
|
|
});
|