95 lines
7.8 KiB
JavaScript
95 lines
7.8 KiB
JavaScript
import { openWorkbenchTool } from './ui-navigation.mjs';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import { randomUUID } from 'node:crypto';
|
|
import { chromium, expect } from 'playwright/test';
|
|
import { fixture, launchWorkbench, compatibleFixture, completion, call, until } from '../tests/helpers.mjs';
|
|
|
|
const directory = path.resolve('.qa', 'skills-ui-' + randomUUID()); fs.mkdirSync(directory, { recursive: true });
|
|
const disposers = [], t = { after: dispose => disposers.push(dispose) }, f = fixture(t); f.store.close();
|
|
const filename = path.join(f.root, 'engineering-workflow', 'SKILL.md'); fs.mkdirSync(path.dirname(filename));
|
|
fs.writeFileSync(filename, '# 工程交付技能\n\n读取实际代码,保留用户已有修改。使用原始测试结果核对交付,不以模型文字代替完成。\n');
|
|
let saved;
|
|
const model = await compatibleFixture(t, (_url, _body, requests) => requests.length === 1
|
|
? completion([call('ui-skill-read', 'read_registered_skill', { skill_id: saved.id, revision: saved.revision, source_sha256: saved.source.sha256 })])
|
|
: completion([], '本地夹具:技能原文已读取,模型能力不在此验收。'));
|
|
const host = await launchWorkbench(t, f.data); assert.notEqual(new URL(host.url).port, '4318');
|
|
const browser = await chromium.launch({ channel: 'msedge', headless: true });
|
|
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
|
const pageErrors = [], requestFailures = [], marks = [];
|
|
page.on('pageerror', error => pageErrors.push(error.message));
|
|
page.on('requestfailed', request => requestFailures.push(request.url() + ': ' + request.failure()?.errorText));
|
|
const mark = value => { marks.push(value); console.log('PASS ' + value); };
|
|
try {
|
|
await page.addInitScript(({ projectId, sessionId }) => { localStorage.setItem('awb-project', projectId); localStorage.setItem('awb-session', sessionId); },
|
|
{ projectId: f.project.id, sessionId: f.session.id });
|
|
await page.goto(host.url); await page.waitForLoadState('networkidle');
|
|
await openWorkbenchTool(page, '项目技能');
|
|
const dialog = page.getByRole('dialog', { name: '项目技能', exact: true }); await expect(dialog).toBeVisible();
|
|
const editor = dialog.locator('.skill-register');
|
|
await editor.getByLabel('技能名称', { exact: true }).fill('工程交付核验');
|
|
await editor.getByLabel('版本', { exact: true }).fill('1.0.0');
|
|
await editor.getByLabel('技能文件路径', { exact: true }).fill(filename);
|
|
await editor.getByLabel('用途说明', { exact: true }).fill('工程修改与交付前使用,核对代码、测试和用户已有变更。');
|
|
await editor.getByRole('button', { name: '登记技能', exact: true }).click();
|
|
const row = dialog.locator('.skill-row').filter({ hasText: '工程交付核验' });
|
|
await expect(row).toContainText('已停用'); await expect(row).toContainText('来源一致');
|
|
await row.getByRole('button', { name: '审查原文', exact: true }).click();
|
|
await expect(dialog.getByLabel('技能原文')).toContainText('读取实际代码');
|
|
await row.getByRole('button', { name: '启用技能', exact: true }).click();
|
|
await expect(row).toContainText('已启用');
|
|
saved = (await host.api('/projects/' + f.project.id + '/skills')).skills[0];
|
|
assert.equal(saved.enabled, true); assert.equal(model.requests.length, 0);
|
|
await page.screenshot({ path: path.join(directory, 'desktop-skill-source.png') });
|
|
mark('desktop registers a disabled skill, reviews original UTF-8 instructions and explicitly enables it with no model calls');
|
|
fs.appendFileSync(filename, '\n新修订:发现失败后保留原结果,修正后重新检查。\n');
|
|
await dialog.getByRole('button', { name: '核对来源', exact: true }).click();
|
|
await expect(row).toContainText('来源已变化');
|
|
await row.getByRole('button', { name: '停用技能', exact: true }).click();
|
|
await expect(row.getByRole('button', { name: '启用技能', exact: true })).toBeDisabled();
|
|
await row.locator('summary').click();
|
|
await row.getByLabel('新修订版本 工程交付核验', { exact: true }).fill('1.1.0');
|
|
await row.getByRole('button', { name: '登记新修订', exact: true }).click();
|
|
await expect(row).toContainText('修订 2'); await expect(row).toContainText('已停用');
|
|
await expect(row).toContainText('来源一致');
|
|
mark('source edit blocks activation until a new reviewed revision is registered; original revision remains available');
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
await row.getByRole('button', { name: '启用技能', exact: true }).click();
|
|
await expect(row).toContainText('已启用');
|
|
await row.getByRole('button', { name: '审查原文', exact: true }).click();
|
|
await expect(dialog.getByLabel('技能原文')).toContainText('新修订');
|
|
assert.ok(await page.locator('body').evaluate(node => node.scrollWidth <= 390));
|
|
await dialog.locator('.skill-heading').scrollIntoViewIfNeeded();
|
|
await page.screenshot({ path: path.join(directory, 'mobile-skill-source.png') });
|
|
mark('390px review and activation retain readable paths, revision history and visible source state without horizontal overflow');
|
|
saved = (await host.api('/projects/' + f.project.id + '/skills')).skills[0];
|
|
await page.keyboard.press('Escape');
|
|
await host.api('/config', { mode: 'compatible', baseUrl: model.baseUrl, model: 'owned-skills-ui', apiKey: 'owned-ui-skills-key', contextLimit: 24000 });
|
|
await host.api('/sessions/' + f.session.id + '/messages', { content: '使用本项目已启用的工程交付技能,读取原文。' });
|
|
await until(async () => (await host.api('/sessions/' + f.session.id)).status === 'completed');
|
|
assert.equal(model.requests.length, 2);
|
|
const execution = await host.api('/sessions/' + f.session.id + '/execution');
|
|
assert.equal(execution.progress.totalTools, 1); assert.equal(execution.progress.completedTools, 1);
|
|
const completedSession = await host.api('/sessions/' + f.session.id);
|
|
assert.equal(completedSession.events.filter(value => value.tool === 'read_registered_skill' && value.phase === 'completed').length, 1);
|
|
await page.setViewportSize({ width: 1440, height: 1000 }); await page.reload(); await page.waitForLoadState('networkidle');
|
|
await page.getByRole('button', { name: '查看任务记录', exact: true }).click();
|
|
const context = page.getByLabel('请求上下文', { exact: true }); await expect(context).toContainText('1 项本次目录记录');
|
|
await context.getByRole('button', { name: '查看本次技能目录', exact: true }).click();
|
|
const artifact = page.getByRole('dialog', { name: '执行结果工件', exact: true });
|
|
await expect(artifact.locator('pre')).toContainText(saved.source.sha256);
|
|
assert.equal(JSON.parse(await artifact.locator('pre').innerText()).entries[0].revision, 2);
|
|
await page.screenshot({ path: path.join(directory, 'desktop-sent-skill-catalog.png') });
|
|
mark('actual local HTTP task reads precisely revision 2 and exposes its SHA-bound sent catalog in task evidence');
|
|
assert.deepEqual(pageErrors, []); assert.deepEqual(requestFailures, []);
|
|
fs.writeFileSync(path.join(directory, 'result.json'), JSON.stringify({ success: true, viewportWidths: [1440, 390], assertions: marks,
|
|
pageErrors, requestFailures, localFixtureModelRequests: model.requests.length, realModelRequests: 0,
|
|
screenshots: ['desktop-skill-source.png', 'mobile-skill-source.png', 'desktop-sent-skill-catalog.png'] }, null, 2));
|
|
console.log('EVIDENCE ' + directory);
|
|
} catch (error) {
|
|
await page.screenshot({ path: path.join(directory, 'failure.png') }).catch(() => {});
|
|
fs.writeFileSync(path.join(directory, 'result.json'), JSON.stringify({ success: false, error: error.message, assertions: marks, pageErrors, requestFailures }, null, 2));
|
|
console.error('EVIDENCE ' + directory); throw error;
|
|
} finally { await browser.close(); for (const dispose of disposers.reverse()) await dispose(); }
|