chore: baseline Agent Workbench 1.0.0
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
[CmdletBinding()]
|
||||
param([int]$Port = 0, [switch]$NoBrowser)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
[Console]::OutputEncoding = [Text.UTF8Encoding]::new($false)
|
||||
$appRoot = [IO.Path]::GetFullPath((Split-Path -Parent $PSScriptRoot))
|
||||
if ($Port -eq 0) { $Port = if ($env:AGENT_WORKBENCH_PORT) { [int]$env:AGENT_WORKBENCH_PORT } else { 4318 } }
|
||||
if ($Port -lt 1 -or $Port -gt 65535) { throw 'Please use a port between 1 and 65535.' }
|
||||
$workbenchUrl = "http://127.0.0.1:$Port"
|
||||
|
||||
function Read-WorkbenchHealth {
|
||||
try { return Invoke-RestMethod -Uri "$workbenchUrl/api/health" -TimeoutSec 2 }
|
||||
catch { return $null }
|
||||
}
|
||||
|
||||
$health = Read-WorkbenchHealth
|
||||
if ($health) {
|
||||
if ($health.app -ne 'agent-workbench' -or -not $health.ready) { throw "The port is in use by another service: $Port" }
|
||||
Write-Output "Agent Workbench is already running: $workbenchUrl"
|
||||
if (-not $NoBrowser) { Start-Process -FilePath $workbenchUrl }
|
||||
exit 0
|
||||
}
|
||||
|
||||
$serverFile = Join-Path $appRoot 'dist-server\server.mjs'
|
||||
if (-not (Test-Path -LiteralPath $serverFile)) { throw 'Build the source first with npm.cmd run build, or use the portable package.' }
|
||||
$nodeFile = Join-Path $appRoot 'runtime\node.exe'
|
||||
if (-not (Test-Path -LiteralPath $nodeFile)) {
|
||||
$installedNode = Get-Command node.exe -ErrorAction SilentlyContinue
|
||||
if (-not $installedNode) { throw 'Node.js 24 was not found. Use the portable package with its bundled runtime.' }
|
||||
$nodeFile = $installedNode.Source
|
||||
}
|
||||
$dataRoot = if ($env:AGENT_WORKBENCH_DATA_DIR) { [IO.Path]::GetFullPath($env:AGENT_WORKBENCH_DATA_DIR) } else { Join-Path $env:LOCALAPPDATA 'AgentWorkbench' }
|
||||
$logsRoot = Join-Path $dataRoot 'logs'
|
||||
[IO.Directory]::CreateDirectory($logsRoot) | Out-Null
|
||||
$stdoutFile = Join-Path $logsRoot 'service.stdout.log'
|
||||
$stderrFile = Join-Path $logsRoot 'service.stderr.log'
|
||||
$env:AGENT_WORKBENCH_APP_DIR = $appRoot
|
||||
$env:AGENT_WORKBENCH_DATA_DIR = $dataRoot
|
||||
$env:AGENT_WORKBENCH_PORT = [string]$Port
|
||||
$childProcess = Start-Process -FilePath $nodeFile -ArgumentList ('"' + $serverFile + '"') -WorkingDirectory $appRoot -WindowStyle Hidden -PassThru -RedirectStandardOutput $stdoutFile -RedirectStandardError $stderrFile
|
||||
$deadline = [DateTime]::UtcNow.AddSeconds(15)
|
||||
do {
|
||||
Start-Sleep -Milliseconds 200
|
||||
$childProcess.Refresh()
|
||||
if ($childProcess.HasExited) {
|
||||
$diagnostic = if (Test-Path -LiteralPath $stderrFile) { (Get-Content -LiteralPath $stderrFile -Tail 8) -join "`n" } else { '' }
|
||||
throw "Agent Workbench could not start. $diagnostic"
|
||||
}
|
||||
$health = Read-WorkbenchHealth
|
||||
} while ((-not $health -or -not $health.ready) -and [DateTime]::UtcNow -lt $deadline)
|
||||
if (-not $health -or $health.app -ne 'agent-workbench' -or -not $health.ready) { throw "Service did not become ready. See $stderrFile" }
|
||||
$serviceInfo = @{ app = 'agent-workbench'; pid = $childProcess.Id; port = $Port; appRoot = $appRoot; dataRoot = $dataRoot; startedAt = [DateTime]::UtcNow.ToString('o') } | ConvertTo-Json
|
||||
[IO.File]::WriteAllText((Join-Path $dataRoot 'service-info.json'), $serviceInfo, [Text.UTF8Encoding]::new($false))
|
||||
Write-Output "Agent Workbench is ready: $workbenchUrl"
|
||||
Write-Output "Data: $dataRoot"
|
||||
if (-not $NoBrowser) { Start-Process -FilePath $workbenchUrl }
|
||||
@@ -0,0 +1,14 @@
|
||||
[CmdletBinding()]
|
||||
param([int]$Port = 0)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
[Console]::OutputEncoding = [Text.UTF8Encoding]::new($false)
|
||||
if ($Port -eq 0) { $Port = if ($env:AGENT_WORKBENCH_PORT) { [int]$env:AGENT_WORKBENCH_PORT } else { 4318 } }
|
||||
if ($Port -lt 1 -or $Port -gt 65535) { throw 'Please use a port between 1 and 65535.' }
|
||||
$workbenchUrl = "http://127.0.0.1:$Port"
|
||||
try { $health = Invoke-RestMethod -Uri "$workbenchUrl/api/health" -TimeoutSec 2 }
|
||||
catch { Write-Output "Agent Workbench is not running on port $Port."; exit 0 }
|
||||
if ($health.app -ne 'agent-workbench' -or -not $health.ready) { throw "This port is occupied by another service: $Port" }
|
||||
$bootstrap = Invoke-RestMethod -Uri "$workbenchUrl/api/bootstrap" -TimeoutSec 3
|
||||
Invoke-RestMethod -Uri "$workbenchUrl/api/shutdown" -Method Post -ContentType 'application/json' -Body '{}' -Headers @{ 'X-Workbench-Token' = $bootstrap.token } -TimeoutSec 15 | Out-Null
|
||||
Write-Output "Agent Workbench is stopping: $workbenchUrl"
|
||||
@@ -0,0 +1,8 @@
|
||||
import { build } from 'esbuild';
|
||||
import fs from 'node:fs';
|
||||
fs.mkdirSync('dist-server', { recursive: true });
|
||||
await build({ entryPoints: ['src/server/index.mjs'], outfile: 'dist-server/server.mjs', bundle: true,
|
||||
platform: 'node', target: 'node24', format: 'esm', sourcemap: false, legalComments: 'eof' });
|
||||
await build({ entryPoints: ['src/server/hot-upgrade.mjs'], outfile: 'dist-server/hot-upgrade.mjs', bundle: true,
|
||||
platform: 'node', target: 'node24', format: 'esm', sourcemap: false, legalComments: 'eof' });
|
||||
console.log('Server bundle built.');
|
||||
@@ -0,0 +1,19 @@
|
||||
import fs from 'node:fs';
|
||||
import { chromium } from 'playwright';
|
||||
|
||||
const url = process.env.AGENT_WORKBENCH_URL || 'http://127.0.0.1:4319';
|
||||
fs.mkdirSync('.qa/screenshots', { recursive: true });
|
||||
const browser = await chromium.launch({ channel: 'msedge', headless: true });
|
||||
try {
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 960 }, deviceScaleFactor: 1 });
|
||||
const errors = [];
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
||||
await page.waitForLoadState('networkidle', { timeout: 6000 }).catch(() => {});
|
||||
await page.locator('.connection.connected').waitFor({ timeout: 8000 });
|
||||
await page.screenshot({ path: '.qa/screenshots/initial-desktop.png', fullPage: true });
|
||||
fs.writeFileSync('.qa/initial-dom.html', await page.content());
|
||||
console.log(JSON.stringify({ url, errors, buttons: await page.getByRole('button').allTextContents(),
|
||||
labeledButtons: await page.locator('button[aria-label]').evaluateAll(nodes => nodes.map(node => node.getAttribute('aria-label'))),
|
||||
text: (await page.locator('body').innerText()).slice(0, 3500) }, null, 2));
|
||||
} finally { await browser.close(); }
|
||||
@@ -0,0 +1,104 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
const root = process.cwd();
|
||||
const meta = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
||||
const lock = JSON.parse(fs.readFileSync('package-lock.json', 'utf8'));
|
||||
const releases = path.resolve(root, 'releases');
|
||||
fs.mkdirSync(releases, { recursive: true });
|
||||
const baseName = 'Agent-Workbench-' + meta.version;
|
||||
const refresh = process.argv.includes('--refresh');
|
||||
const buildSuffix = !refresh && fs.existsSync(path.join(releases, baseName + '-win-x64')) ? '-' + new Date().toISOString().replace(/[-:TZ.]/g, '') : '';
|
||||
const portableRoot = path.join(releases, baseName + '-win-x64' + buildSuffix);
|
||||
const sourceRoot = path.join(releases, baseName + '-source' + buildSuffix);
|
||||
for (const target of [portableRoot, sourceRoot]) {
|
||||
if (!path.resolve(target).startsWith(releases + path.sep) || (fs.existsSync(target) && !refresh)) throw new Error('Release output must be a new folder under releases.');
|
||||
fs.mkdirSync(target, { recursive: true });
|
||||
}
|
||||
|
||||
const portableFiles = ['dist-client', 'dist-server', 'docs', 'examples', 'README.md', 'CHANGELOG.md', 'DESIGN.md', 'Start-Workbench.cmd', 'Stop-Workbench.cmd'];
|
||||
const sourceFiles = ['src', 'public', 'scripts', 'tests', 'docs', 'examples', 'package.json', 'package-lock.json', 'vite.config.ts', 'tsconfig.json', 'index.html', '.gitignore', 'README.md', 'CHANGELOG.md', 'DESIGN.md', 'task_plan.md', 'findings.md', 'progress.md', 'Start-Workbench.cmd', 'Stop-Workbench.cmd'];
|
||||
const copyTree = (source, destination) => fs.cpSync(source, destination, { recursive: true, filter: (from, to) => {
|
||||
if (!fs.statSync(from).isFile() || !fs.existsSync(to)) return true;
|
||||
return !fs.readFileSync(from).equals(fs.readFileSync(to));
|
||||
} });
|
||||
for (const name of portableFiles) copyTree(path.join(root, name), path.join(portableRoot, name));
|
||||
fs.mkdirSync(path.join(portableRoot, 'scripts'), { recursive: true });
|
||||
for (const name of ['Start-Workbench.ps1', 'Stop-Workbench.ps1', 'upgrade-running.mjs']) fs.copyFileSync(path.join(root, 'scripts', name), path.join(portableRoot, 'scripts', name));
|
||||
for (const name of sourceFiles) copyTree(path.join(root, name), path.join(sourceRoot, name));
|
||||
|
||||
const preferredNode = path.resolve(root, '..', 'tools', 'node-v24.22.1-win-x64', 'node.exe');
|
||||
const nodeBinary = process.env.AGENT_WORKBENCH_NODE_PATH || (fs.existsSync(preferredNode) ? preferredNode : process.execPath);
|
||||
const nodeLicense = path.join(path.dirname(nodeBinary), 'LICENSE');
|
||||
if (!fs.existsSync(nodeLicense)) throw new Error('The bundled Node runtime requires its complete LICENSE next to node.exe.');
|
||||
const nodeVersion = execFileSync(nodeBinary, ['--version'], { encoding: 'utf8', windowsHide: true }).trim();
|
||||
if (!/^v24\./.test(nodeVersion)) throw new Error('This package was validated with Node 24.');
|
||||
fs.mkdirSync(path.join(portableRoot, 'runtime'), { recursive: true });
|
||||
const runtimeDestination = path.join(portableRoot, 'runtime', 'node.exe');
|
||||
const digest = file => createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
||||
if (!fs.existsSync(runtimeDestination) || digest(runtimeDestination) !== digest(nodeBinary)) fs.copyFileSync(nodeBinary, runtimeDestination);
|
||||
|
||||
const notices = ['Agent Workbench third-party notices', '',
|
||||
'Original product code is supplied for the project owner. Its redistribution terms are determined by the project owner.',
|
||||
'Third-party components remain governed by their own licenses. Full available license texts are reproduced below and in licenses/.', '',
|
||||
'The release does not contain Claude Code or Cursor client binaries or recovered application source.', ''];
|
||||
const licenseRoot = path.join(root, 'licenses'); fs.mkdirSync(licenseRoot, { recursive: true });
|
||||
let licenseCount = 0;
|
||||
for (const [location, entry] of Object.entries(lock.packages).sort(([a], [b]) => a.localeCompare(b))) {
|
||||
if (!location.startsWith('node_modules/')) continue;
|
||||
const packageRoot = path.resolve(root, location);
|
||||
if (!packageRoot.startsWith(path.join(root, 'node_modules') + path.sep) || !fs.existsSync(packageRoot)) continue;
|
||||
const pkg = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
|
||||
const files = fs.readdirSync(packageRoot).filter(name => /^(licen[cs]e|copying)([.-].*)?$/i.test(name) && fs.statSync(path.join(packageRoot, name)).isFile());
|
||||
notices.push('='.repeat(72), (pkg.name || location) + ' ' + (pkg.version || entry.version),
|
||||
'License: ' + (typeof pkg.license === 'object' ? JSON.stringify(pkg.license) : pkg.license || entry.license || 'see upstream package'),
|
||||
'Source package: ' + location, '');
|
||||
if (!files.length) notices.push('License metadata is recorded above; associated parent package license text is included where supplied.', '');
|
||||
for (const file of files) {
|
||||
const text = fs.readFileSync(path.join(packageRoot, file), 'utf8');
|
||||
notices.push(file, '', text, '');
|
||||
fs.writeFileSync(path.join(licenseRoot, (pkg.name + '-' + pkg.version + '-' + file).replace(/[^a-z0-9_.-]/gi, '_') + '.txt'), text);
|
||||
licenseCount++;
|
||||
}
|
||||
}
|
||||
const nodeLicenseText = fs.readFileSync(nodeLicense, 'utf8');
|
||||
fs.writeFileSync(path.join(licenseRoot, 'Node-' + nodeVersion + '-LICENSE.txt'), nodeLicenseText);
|
||||
notices.push('='.repeat(72), 'Node.js ' + nodeVersion, '', nodeLicenseText);
|
||||
fs.writeFileSync(path.join(root, 'THIRD_PARTY_NOTICES.txt'), notices.join('\n'));
|
||||
for (const output of [portableRoot, sourceRoot]) {
|
||||
fs.cpSync(licenseRoot, path.join(output, 'licenses'), { recursive: true });
|
||||
fs.copyFileSync(path.join(root, 'THIRD_PARTY_NOTICES.txt'), path.join(output, 'THIRD_PARTY_NOTICES.txt'));
|
||||
}
|
||||
|
||||
function filesIn(directory, relative = '') {
|
||||
return fs.readdirSync(path.join(directory, relative), { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name)).flatMap(entry => {
|
||||
const file = path.join(relative, entry.name);
|
||||
return entry.isDirectory() ? filesIn(directory, file) : [file];
|
||||
});
|
||||
}
|
||||
function manifest(directory, kind) {
|
||||
const files = filesIn(directory).filter(file => file !== 'MANIFEST.json').map(file => {
|
||||
const bytes = fs.readFileSync(path.join(directory, file));
|
||||
return { path: file.replaceAll('\\', '/'), bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex') };
|
||||
});
|
||||
const result = { app: 'agent-workbench', version: meta.version, kind, platform: 'win32-x64', nodeVersion,
|
||||
createdAt: new Date().toISOString(), files };
|
||||
fs.writeFileSync(path.join(directory, 'MANIFEST.json'), JSON.stringify(result, null, 2));
|
||||
return result;
|
||||
}
|
||||
const portableManifest = manifest(portableRoot, 'portable');
|
||||
manifest(sourceRoot, 'source');
|
||||
const quote = value => "'" + value.replaceAll("'", "''") + "'";
|
||||
function archive(directory) {
|
||||
const destination = directory + '.zip';
|
||||
if (!destination.startsWith(releases + path.sep)) throw new Error('Archive path is outside releases.');
|
||||
if (fs.existsSync(destination)) fs.unlinkSync(destination);
|
||||
const command = "$ErrorActionPreference='Stop'; Add-Type -AssemblyName System.IO.Compression.FileSystem; [IO.Compression.ZipFile]::CreateFromDirectory(" + quote(directory) + ', ' + quote(destination) + ', [IO.Compression.CompressionLevel]::Optimal, $true)';
|
||||
execFileSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', command], { windowsHide: true, stdio: 'pipe' });
|
||||
return { path: destination, bytes: fs.statSync(destination).size, sha256: createHash('sha256').update(fs.readFileSync(destination)).digest('hex') };
|
||||
}
|
||||
const result = { portableRoot, sourceRoot, portable: archive(portableRoot), source: archive(sourceRoot), nodeVersion, portableFiles: portableManifest.files.length, licenseTexts: licenseCount + 1 };
|
||||
fs.writeFileSync(path.join(releases, 'latest.json'), JSON.stringify(result, null, 2));
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
@@ -0,0 +1,23 @@
|
||||
import fs from 'node:fs';
|
||||
import postcss from 'postcss';
|
||||
|
||||
const file = 'src/client/styles.css';
|
||||
const root = postcss.parse(fs.readFileSync(file, 'utf8'));
|
||||
const rgb = hex => hex.match(/../g).map(value => parseInt(value, 16));
|
||||
const luminance = color => color.map(value => value / 255).map(value => value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4)
|
||||
.reduce((sum, value, index) => sum + value * [0.2126, 0.7152, 0.0722][index], 0);
|
||||
const ink = rgb('1c2e32');
|
||||
const background = luminance(rgb('edf3f1'));
|
||||
root.walkDecls(declaration => {
|
||||
if (declaration.prop === 'font-size' && /^\d+px$/.test(declaration.value) && parseInt(declaration.value) < 11) declaration.value = '11px';
|
||||
if (declaration.prop !== 'color' || !/^#[0-9a-f]{6}$/i.test(declaration.value)) return;
|
||||
if (/\.toast|\.brand-mark|\.send-button/.test(declaration.parent.selector ?? '')) return;
|
||||
const original = rgb(declaration.value.slice(1));
|
||||
let color = original;
|
||||
for (let mix = 0; (background + 0.05) / (luminance(color) + 0.05) < 4.7 && mix <= 1; mix += 0.03) {
|
||||
color = original.map((value, index) => Math.round(value * (1 - mix) + ink[index] * mix));
|
||||
}
|
||||
declaration.value = '#' + color.map(value => value.toString(16).padStart(2, '0')).join('');
|
||||
});
|
||||
fs.writeFileSync(file, root.toString(), 'utf8');
|
||||
console.log('Text contrast and minimum caption sizes calibrated.');
|
||||
@@ -0,0 +1,129 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { setTimeout as delay } from 'node:timers/promises';
|
||||
|
||||
function localUrl(value) {
|
||||
const url = new URL(value);
|
||||
if (url.protocol !== 'http:' || url.hostname !== '127.0.0.1' || url.username || url.password || url.search || url.hash) throw new Error('Upgrade only accepts the local Workbench address.');
|
||||
return url.origin;
|
||||
}
|
||||
|
||||
async function within(promise, milliseconds, label) {
|
||||
let timer;
|
||||
try { return await Promise.race([promise, new Promise((_, reject) => { timer = setTimeout(() => reject(new Error(label + ' timed out.')), milliseconds); })]); }
|
||||
finally { clearTimeout(timer); }
|
||||
}
|
||||
|
||||
class Protocol {
|
||||
constructor(socket) {
|
||||
this.socket = socket; this.nextId = 1; this.pending = new Map(); this.listeners = new Map();
|
||||
socket.addEventListener('message', event => {
|
||||
const message = JSON.parse(String(event.data));
|
||||
if (message.id) {
|
||||
const pending = this.pending.get(message.id); if (!pending) return;
|
||||
this.pending.delete(message.id);
|
||||
if (message.error) pending.reject(new Error(message.error.message)); else pending.resolve(message.result);
|
||||
} else for (const listener of this.listeners.get(message.method) ?? []) listener(message.params);
|
||||
});
|
||||
socket.addEventListener('close', () => { for (const pending of this.pending.values()) pending.reject(new Error('Inspector connection closed.')); this.pending.clear(); });
|
||||
}
|
||||
on(method, listener) { this.listeners.set(method, [...(this.listeners.get(method) ?? []), listener]); }
|
||||
send(method, params = {}) {
|
||||
return within(new Promise((resolve, reject) => {
|
||||
const id = this.nextId++; this.pending.set(id, { resolve, reject }); this.socket.send(JSON.stringify({ id, method, params }));
|
||||
}), 10000, method);
|
||||
}
|
||||
}
|
||||
|
||||
function sameFile(url, file) {
|
||||
try { return path.resolve(fileURLToPath(url)).toLowerCase() === path.resolve(file).toLowerCase(); } catch { return false; }
|
||||
}
|
||||
function sameTarget(target, file) {
|
||||
if (sameFile(target.url, file)) return true;
|
||||
const displayName = path.resolve(file).replaceAll('\\', '_').replaceAll('/', '_');
|
||||
return target.title === displayName && target.url === 'file://' + displayName;
|
||||
}
|
||||
|
||||
export async function upgradeRunning({ url, pid, currentRoot, newRoot }) {
|
||||
const origin = localUrl(url), original = fs.realpathSync.native(currentRoot), next = fs.realpathSync.native(newRoot);
|
||||
const originalScript = path.join(original, 'dist-server', 'server.mjs');
|
||||
const upgradeScript = path.join(next, 'dist-server', 'hot-upgrade.mjs');
|
||||
if (!fs.existsSync(originalScript) || !fs.existsSync(upgradeScript) || !fs.existsSync(path.join(next, 'dist-client', 'index.html'))) throw new Error('Upgrade bundles are incomplete.');
|
||||
if (!Number.isInteger(pid) || pid < 1 || pid === process.pid) throw new Error('Invalid target process.');
|
||||
const before = await (await fetch(origin + '/api/bootstrap', { signal: AbortSignal.timeout(5000) })).json();
|
||||
if (!before.token || before.version !== '0.1.0') throw new Error('This migration accepts an existing 0.1.0 Workbench.');
|
||||
if (before.sessions.some(session => ['running', 'awaiting_approval', 'stopping'].includes(session.status))) throw new Error('Wait for existing tasks and approvals before upgrading.');
|
||||
let protocol, socket, enabledHere = false, paused = false, breakpoint;
|
||||
try {
|
||||
let targets;
|
||||
try { targets = await (await fetch('http://127.0.0.1:9229/json/list', { signal: AbortSignal.timeout(500) })).json(); } catch {}
|
||||
if (targets && !targets.some(target => sameTarget(target, originalScript))) throw new Error('The local inspector port belongs to another process.');
|
||||
if (!targets) {
|
||||
process._debugProcess(pid); enabledHere = true;
|
||||
for (let attempt = 0; attempt < 40 && !targets; attempt++) {
|
||||
await delay(100);
|
||||
try { targets = await (await fetch('http://127.0.0.1:9229/json/list', { signal: AbortSignal.timeout(500) })).json(); } catch {}
|
||||
}
|
||||
}
|
||||
const target = targets?.find(item => sameTarget(item, originalScript));
|
||||
if (!target || !target.webSocketDebuggerUrl?.startsWith('ws://127.0.0.1:9229/')) throw new Error('The expected Workbench inspector was not found.');
|
||||
socket = new WebSocket(target.webSocketDebuggerUrl);
|
||||
await within(new Promise((resolve, reject) => { socket.addEventListener('open', resolve, { once: true }); socket.addEventListener('error', reject, { once: true }); }), 10000, 'Inspector connection');
|
||||
protocol = new Protocol(socket);
|
||||
const scripts = [];
|
||||
protocol.on('Debugger.scriptParsed', script => scripts.push(script));
|
||||
let pausedResolve;
|
||||
const pausedEvent = new Promise(resolve => { pausedResolve = resolve; });
|
||||
protocol.on('Debugger.paused', event => { paused = true; pausedResolve(event); });
|
||||
await protocol.send('Runtime.enable');
|
||||
const identity = await protocol.send('Runtime.evaluate', { expression: 'process.pid', returnByValue: true });
|
||||
if (identity.result.value !== pid) throw new Error('The inspector belongs to a different process.');
|
||||
await protocol.send('Debugger.enable');
|
||||
const script = scripts.find(item => sameFile(item.url, originalScript));
|
||||
if (!script) throw new Error('The existing server module is missing from inspector metadata.');
|
||||
const { scriptSource } = await protocol.send('Debugger.getScriptSource', { scriptId: script.scriptId });
|
||||
const lines = scriptSource.split('\n');
|
||||
const locations = lines.flatMap((line, index) => line.includes('const url = new URL(request.url') ? [index] : []);
|
||||
if (locations.length !== 1) throw new Error('The existing request handler could not be identified uniquely.');
|
||||
breakpoint = (await protocol.send('Debugger.setBreakpoint', { location: { scriptId: script.scriptId, lineNumber: locations[0] } })).breakpointId;
|
||||
const probe = fetch(origin + '/api/health', { signal: AbortSignal.timeout(15000) });
|
||||
probe.catch(() => {});
|
||||
const event = await within(pausedEvent, 10000, 'Workbench request observation');
|
||||
const captured = await protocol.send('Debugger.evaluateOnCallFrame', { callFrameId: event.callFrames[0].callFrameId,
|
||||
expression: "globalThis.__awUpgradeContext = { server, store, provider, runtime, token, clients, started, exampleProject, shutdown }; 'context-ready'", returnByValue: true });
|
||||
if (captured.exceptionDetails || captured.result.value !== 'context-ready') throw new Error('Could not retain the existing runtime objects.');
|
||||
await protocol.send('Debugger.removeBreakpoint', { breakpointId: breakpoint }); breakpoint = null;
|
||||
await protocol.send('Debugger.resume'); paused = false; await probe;
|
||||
const expression = '(() => { try { const module = process.getBuiltinModule("module").createRequire(' + JSON.stringify(upgradeScript) + ')(' + JSON.stringify(upgradeScript) + '); return module.installUpgrade(globalThis.__awUpgradeContext, { appDirectory: ' + JSON.stringify(next) + ' }); } finally { delete globalThis.__awUpgradeContext; } })()';
|
||||
const upgraded = await protocol.send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true });
|
||||
if (upgraded.exceptionDetails) throw new Error('Runtime upgrade failed: ' + (upgraded.exceptionDetails.exception?.description ?? upgraded.exceptionDetails.text));
|
||||
const result = upgraded.result.value;
|
||||
const after = await (await fetch(origin + '/api/bootstrap', { signal: AbortSignal.timeout(5000) })).json();
|
||||
const health = await (await fetch(origin + '/api/health', { signal: AbortSignal.timeout(5000) })).json();
|
||||
if (health.pid !== pid || result.pid !== pid || after.version !== result.version || after.config.hasKey !== before.config.hasKey
|
||||
|| after.config.model !== before.config.model || after.config.baseUrl !== before.config.baseUrl
|
||||
|| JSON.stringify(after.projects) !== JSON.stringify(before.projects)
|
||||
|| JSON.stringify(after.sessions) !== JSON.stringify(before.sessions)) throw new Error('The upgraded runtime did not preserve the existing state.');
|
||||
return { ...result, verified: true, connectionPreserved: true, url: origin };
|
||||
} finally {
|
||||
if (protocol) {
|
||||
try { if (breakpoint) await protocol.send('Debugger.removeBreakpoint', { breakpointId: breakpoint }); } catch {}
|
||||
try { if (paused) await protocol.send('Debugger.resume'); } catch {}
|
||||
try { await protocol.send('Runtime.evaluate', { expression: 'delete globalThis.__awUpgradeContext; true', returnByValue: true }); } catch {}
|
||||
if (enabledHere) {
|
||||
try { await protocol.send('Runtime.evaluate', { expression: "setTimeout(() => process.getBuiltinModule('inspector').close(), 25); true", returnByValue: true }); } catch {}
|
||||
}
|
||||
}
|
||||
socket?.close();
|
||||
if (enabledHere) await delay(150);
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
const args = Object.fromEntries(process.argv.slice(2).reduce((items, value, index, all) => {
|
||||
if (value.startsWith('--')) items.push([value.slice(2), all[index + 1]]); return items;
|
||||
}, []));
|
||||
const result = await upgradeRunning({ url: args.url || 'http://127.0.0.1:4318', pid: Number(args.pid), currentRoot: args['current-root'], newRoot: args['new-root'] });
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import http from 'node:http';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { chromium } from 'playwright';
|
||||
|
||||
const url = process.env.AGENT_WORKBENCH_URL || 'http://127.0.0.1:4319';
|
||||
const root = fs.mkdtempSync(path.resolve('.qa', 'diagnostics-ui-'));
|
||||
const projectRoot = path.join(root, 'project'); fs.mkdirSync(projectRoot);
|
||||
fs.writeFileSync(path.join(projectRoot, 'README.md'), '# Diagnostics UI fixture\n');
|
||||
fs.mkdirSync('.qa/screenshots', { recursive: true });
|
||||
const bootstrap = await (await fetch(url + '/api/bootstrap')).json();
|
||||
assert.equal(bootstrap.config.mode, 'demo', 'Diagnostics UI validation requires an independent demo service.');
|
||||
assert.equal(bootstrap.config.hasKey, false, 'Diagnostics UI validation must not replace a configured model connection.');
|
||||
const api = async (route, input) => {
|
||||
const response = await fetch(url + '/api' + route, { method: input === undefined ? 'GET' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'X-Workbench-Token': bootstrap.token }, ...(input === undefined ? {} : { body: JSON.stringify(input) }) });
|
||||
const value = await response.json(); assert.ok(response.ok, value.error); return value;
|
||||
};
|
||||
let mode = 'failure', requestCount = 0, sessionId = '', page;
|
||||
const passed = [], pageErrors = [], networkErrors = [];
|
||||
const model = http.createServer(async (request, response) => {
|
||||
try {
|
||||
const chunks = []; for await (const chunk of request) chunks.push(chunk);
|
||||
if (request.url === '/v1/models') { response.writeHead(200, { 'Content-Type': 'application/json' }); return response.end(JSON.stringify({ data: [{ id: 'ui-diagnostics-fixture' }] })); }
|
||||
const input = JSON.parse(Buffer.concat(chunks).toString('utf8')); requestCount++;
|
||||
assert.equal(request.headers.authorization, 'Bearer ui-fixture-memory-key');
|
||||
const answer = content => { response.writeHead(200, { 'Content-Type': 'application/json' }); response.end(JSON.stringify({ choices: [{ message: { role: 'assistant', content }, finish_reason: 'stop' }] })); };
|
||||
const tool = (name, args) => { response.writeHead(200, { 'Content-Type': 'application/json' }); response.end(JSON.stringify({ choices: [{ message: { role: 'assistant', content: '', tool_calls: [{ id: 'ui-' + randomUUID(), type: 'function', function: { name, arguments: JSON.stringify(args) } }] }, finish_reason: 'tool_calls' }] })); };
|
||||
const failure = (status, headers = {}) => { response.writeHead(status, { 'Content-Type': 'application/json', ...headers }); response.end(JSON.stringify({ error: { message: 'Controlled model-service failure' } })); };
|
||||
if (!input.tools) return answer('OK');
|
||||
const lastUser = input.messages.findLastIndex(message => message.role === 'user');
|
||||
const results = input.messages.slice(lastUser + 1).filter(message => message.role === 'tool');
|
||||
if (mode === 'failure') return results.length ? failure(503) : tool('read_file', { path: 'README.md' });
|
||||
if (mode === 'recover') { assert.equal(input.messages.at(-1).role, 'tool'); return answer('**模型请求已恢复**,已完成的读取结果保留。'); }
|
||||
if (mode === 'question') {
|
||||
assert.match(input.messages[0].content, /model_connection/); assert.match(input.messages[0].content, /503/);
|
||||
if (!results.length) return tool('inspect_session', {});
|
||||
const snapshot = JSON.parse(results.at(-1).content); assert.equal(snapshot.lastFailure.httpStatus, 503);
|
||||
return answer('已读取工作台执行记录。上次错误发生在请求模型服务时:**HTTP 503**。项目读取已经成功,文件未改动。');
|
||||
}
|
||||
if (mode === 'proposal') {
|
||||
if (!results.length) return tool('propose_file', { path: 'REVIEWED.md', content: '# Reviewed through the UI\n', reason: 'UI review fixture' });
|
||||
await new Promise(resolve => setTimeout(resolve, 700)); return answer('改动已准备好,请查看差异后应用。');
|
||||
}
|
||||
if (mode === 'command') {
|
||||
if (!results.length) return tool('run_command', { command: "@'\nconsole.log('中文输入与输出正确');\n'@ | node --input-type=module\nexit $LASTEXITCODE", reason: '验证中文通过项目终端进入 Node。' });
|
||||
const result = JSON.parse(results.at(-1).content); assert.equal(result.status, 'completed'); assert.match(result.stdout, /中文输入与输出正确/);
|
||||
return answer('**UTF-8 验证通过**:中文输入与输出正确。');
|
||||
}
|
||||
if (mode === 'authentication') return failure(401);
|
||||
if (mode === 'backoff') return failure(503, { 'Retry-After': '3' });
|
||||
if (mode === 'transient') return requestCount === 1 ? failure(503) : answer('临时连接错误已自动恢复。');
|
||||
throw new Error('Unknown fixture mode');
|
||||
} catch (error) { if (!response.headersSent) response.writeHead(500, { 'Content-Type': 'application/json' }); response.end(JSON.stringify({ error: { message: error.message } })); }
|
||||
});
|
||||
await new Promise(resolve => model.listen(0, '127.0.0.1', resolve));
|
||||
const browser = await chromium.launch({ executablePath: path.join(process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)', 'Microsoft', 'Edge', 'Application', 'msedge.exe'), headless: true });
|
||||
const mark = text => { passed.push(text); console.log('PASS ' + text); };
|
||||
const state = async () => api('/sessions/' + sessionId);
|
||||
const waitState = async status => {
|
||||
await page.waitForFunction(expected => document.querySelector('.task-toolbar .status')?.classList.contains('status-' + expected), status);
|
||||
};
|
||||
const checkViewport = async () => {
|
||||
const bounds = await page.evaluate(() => {
|
||||
const header = document.querySelector('.work-header').getBoundingClientRect(), composer = document.querySelector('.composer-wrap').getBoundingClientRect();
|
||||
return { width: innerWidth, height: innerHeight, scrollWidth: document.documentElement.scrollWidth, scrollHeight: document.documentElement.scrollHeight, headerTop: header.top, composerBottom: composer.bottom };
|
||||
});
|
||||
assert.ok(bounds.scrollWidth <= bounds.width + 1 && bounds.scrollHeight <= bounds.height + 1, JSON.stringify(bounds));
|
||||
assert.ok(bounds.headerTop >= -1 && bounds.composerBottom <= bounds.height + 1, JSON.stringify(bounds));
|
||||
};
|
||||
const screenshot = async name => { await checkViewport(); await page.screenshot({ path: '.qa/screenshots/' + name + '.png', scale: 'css' }); };
|
||||
const task = async content => {
|
||||
const newTask = page.getByRole('button', { name: '新建任务', exact: true });
|
||||
if (!await newTask.isVisible()) await page.getByRole('button', { name: '展开项目栏', exact: true }).click();
|
||||
await newTask.click();
|
||||
await page.getByLabel('任务内容').fill(content); await page.getByRole('button', { name: '发送任务', exact: true }).click();
|
||||
await page.waitForFunction(() => !!localStorage.getItem('awb-session')); sessionId = await page.evaluate(() => localStorage.getItem('awb-session'));
|
||||
};
|
||||
const settings = async () => { await page.getByRole('button', { name: '模型连接', exact: true }).click(); return page.getByRole('dialog', { name: '模型连接' }); };
|
||||
try {
|
||||
page = await browser.newPage({ viewport: { width: 1440, height: 960 }, deviceScaleFactor: 1 }); page.setDefaultTimeout(15000);
|
||||
page.on('pageerror', error => pageErrors.push(error.message));
|
||||
page.on('requestfailed', request => { if (!request.url().includes('/api/events')) networkErrors.push(request.failure()?.errorText); });
|
||||
await page.goto(url, { waitUntil: 'domcontentloaded' }); await page.locator('.connection.connected').waitFor();
|
||||
await page.getByRole('button', { name: '打开项目', exact: true }).click();
|
||||
const projectDialog = page.getByRole('dialog', { name: '打开项目' });
|
||||
await projectDialog.getByLabel('项目文件夹路径').fill(projectRoot); await projectDialog.getByRole('button', { name: '打开项目', exact: true }).click();
|
||||
await projectDialog.waitFor({ state: 'hidden' });
|
||||
const connection = await settings(); await connection.getByRole('button', { name: '兼容模型服务' }).click();
|
||||
await connection.getByLabel('接口根地址', { exact: true }).fill('http://127.0.0.1:' + model.address().port + '/v1');
|
||||
await connection.getByLabel('API Key(按服务要求填写)').fill('ui-fixture-memory-key');
|
||||
await connection.getByLabel('模型名称').fill('ui-diagnostics-fixture');
|
||||
await connection.getByRole('button', { name: '验证模型响应', exact: true }).click();
|
||||
await connection.getByText(/模型响应验证通过/).waitFor(); assert.equal((await api('/diagnostics')).connection.mode, 'demo');
|
||||
await connection.getByRole('button', { name: '保存连接', exact: true }).click(); await connection.waitFor({ state: 'hidden' });
|
||||
mark('model response validation checks the tentative connection before saving');
|
||||
|
||||
requestCount = 0; await task('制造读取成功后的模型服务错误'); await waitState('failed');
|
||||
const failed = await state(); assert.equal(failed.failure.source, 'model_connection'); assert.equal(failed.failure.httpStatus, 503); assert.equal(failed.failure.attempts, 3);
|
||||
assert.equal(failed.events.filter(event => event.tool === 'read_file').length, 1);
|
||||
await page.locator('.failure-card').waitFor(); await screenshot('formal-model-error');
|
||||
await page.locator('.failure-card').getByRole('button', { name: '查看运行诊断' }).click();
|
||||
const diagnostic = page.getByRole('dialog', { name: '运行诊断' }); await diagnostic.getByText('Windows PowerShell 5.1', { exact: true }).waitFor();
|
||||
await diagnostic.getByText(/HTTP 503/).first().waitFor(); await screenshot('formal-diagnostics');
|
||||
assert.ok(!(await diagnostic.innerText()).includes('ui-fixture-memory-key'));
|
||||
await diagnostic.getByRole('button', { name: '关闭窗口', exact: true }).click();
|
||||
mark('a model failure after successful tools shows source, attempts and local runtime diagnosis');
|
||||
|
||||
mode = 'recover'; await page.locator('.failure-card').getByRole('button', { name: '重试模型请求', exact: true }).click(); await waitState('completed');
|
||||
const recovered = await state(); assert.equal(recovered.events.filter(event => event.tool === 'read_file').length, 1);
|
||||
assert.equal(recovered.messages.filter(message => message.role === 'user').length, 1);
|
||||
mark('explicit retry preserves the completed tool result without replaying the task');
|
||||
|
||||
mode = 'question'; await page.getByLabel('任务内容').fill('刚才工作台报错怎么回事?请查执行记录。'); await page.getByRole('button', { name: '发送任务', exact: true }).click();
|
||||
await page.getByText(/已读取工作台执行记录/).waitFor(); await waitState('completed');
|
||||
const answered = await state(); assert.ok(answered.events.some(event => event.tool === 'inspect_session' && event.phase === 'completed'));
|
||||
assert.equal(answered.events.filter(event => event.tool === 'search_files').length, 0);
|
||||
assert.ok(!await page.locator('.message-assistant .message-text').last().innerText().then(text => text.includes('**')));
|
||||
await screenshot('formal-diagnostic-answer'); mark('an error question receives the actual session diagnosis and formatted answer');
|
||||
|
||||
mode = 'proposal'; await task('准备一个可审查文件'); await page.getByRole('button', { name: '审核 1 项', exact: true }).waitFor();
|
||||
await page.getByRole('button', { name: '审核 1 项', exact: true }).click();
|
||||
const apply = page.getByRole('button', { name: '应用这项改动', exact: true }); assert.ok(await apply.isDisabled());
|
||||
assert.equal(fs.existsSync(path.join(projectRoot, 'REVIEWED.md')), false);
|
||||
await waitState('needs_review'); assert.equal(await page.getByRole('button', { name: '继续任务', exact: true }).count(), 0);
|
||||
await screenshot('formal-review'); await apply.click(); await waitState('completed');
|
||||
assert.equal(fs.readFileSync(path.join(projectRoot, 'REVIEWED.md'), 'utf8'), '# Reviewed through the UI\n');
|
||||
mark('review state exposes the review action and prevents application during a running request');
|
||||
|
||||
mode = 'command'; await task('验证中文终端输入输出'); await waitState('awaiting_approval');
|
||||
await page.locator('.approval-shell').getByText(/PowerShell 5.1/).waitFor(); await screenshot('formal-command-approval');
|
||||
await page.getByRole('button', { name: '确认执行', exact: true }).click(); await waitState('completed');
|
||||
assert.match((await state()).events.find(event => event.tool === 'run_command').output, /中文输入与输出正确/);
|
||||
mark('approved Unicode commands execute in the declared shell and retain Chinese output');
|
||||
|
||||
mode = 'authentication'; requestCount = 0; await task('验证身份失败的处理'); await waitState('failed'); assert.equal(requestCount, 1);
|
||||
assert.match(await page.locator('.failure-card').innerText(), /HTTP 401/);
|
||||
await page.setViewportSize({ width: 390, height: 844 }); await screenshot('formal-mobile-error');
|
||||
await page.locator('.failure-card').getByRole('button', { name: '查看运行诊断' }).click();
|
||||
await page.getByRole('dialog', { name: '运行诊断' }).getByText('Windows PowerShell 5.1', { exact: true }).waitFor();
|
||||
const box = await page.getByRole('dialog', { name: '运行诊断' }).boundingBox(); assert.ok(box.x >= 0 && box.x + box.width <= 391);
|
||||
await screenshot('formal-mobile-diagnostics'); await page.getByRole('button', { name: '关闭窗口', exact: true }).click();
|
||||
await page.setViewportSize({ width: 1440, height: 960 }); mark('authentication errors do not retry and error/diagnostic controls fit a 390 px viewport');
|
||||
|
||||
mode = 'backoff'; requestCount = 0; await task('停止自动重试'); await page.getByText('正在重试模型连接', { exact: true }).waitFor();
|
||||
await page.getByRole('button', { name: '停止', exact: true }).click(); await waitState('paused'); assert.equal(requestCount, 1);
|
||||
assert.equal((await state()).events.find(event => event.kind === 'model').phase, 'interrupted');
|
||||
assert.equal((await api('/diagnostics')).connection.lastRequest.status, 'interrupted');
|
||||
await page.locator('.task-toolbar').getByRole('button', { name: '运行诊断', exact: true }).click();
|
||||
const stoppedDiagnostic = page.getByRole('dialog', { name: '运行诊断' });
|
||||
await stoppedDiagnostic.getByText(/最近请求:已停止/).waitFor();
|
||||
await screenshot('formal-stopped-diagnostics');
|
||||
await stoppedDiagnostic.getByRole('button', { name: '关闭窗口', exact: true }).click();
|
||||
mark('stop cancels pending retry and clears running model state');
|
||||
|
||||
mode = 'transient'; requestCount = 0; await task('验证自动恢复'); await waitState('completed'); assert.equal(requestCount, 2);
|
||||
await screenshot('formal-desktop'); mark('a transient service failure recovers within the bounded retry policy');
|
||||
assert.deepEqual(pageErrors, []); assert.deepEqual(networkErrors, []);
|
||||
const result = { success: true, version: '1.0.0', url, date: new Date().toISOString(), passed, pageErrors, requestFailures: networkErrors, modelValidation: 'controlled local HTTP fixture; actual configured model is verified separately' };
|
||||
fs.writeFileSync('.qa/diagnostics-ui-validation.json', JSON.stringify(result, null, 2)); console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
if (page) await page.screenshot({ path: '.qa/screenshots/formal-ui-failure.png', scale: 'css' }).catch(() => {});
|
||||
console.error(error); throw error;
|
||||
} finally {
|
||||
await browser.close();
|
||||
await api('/config', { ...bootstrap.config, mode: 'demo', apiKey: '' }).catch(() => {});
|
||||
model.closeAllConnections(); await new Promise(resolve => model.close(resolve));
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
const url = process.env.AGENT_WORKBENCH_URL || 'http://127.0.0.1:4318';
|
||||
const bootstrapResponse = await fetch(url + '/api/bootstrap');
|
||||
assert.ok(bootstrapResponse.ok, '工作台未连接');
|
||||
const bootstrap = await bootstrapResponse.json();
|
||||
assert.equal(bootstrap.config.mode, 'compatible', '请先保存兼容模型配置');
|
||||
assert.ok(bootstrap.config.model, '没有选择模型');
|
||||
const root = path.resolve('.qa', 'live-model-' + randomUUID(), '模型连接验证');
|
||||
const proof = randomUUID();
|
||||
fs.mkdirSync(root, { recursive: true });
|
||||
fs.writeFileSync(path.join(root, 'facts.txt'), 'PROOF_TOKEN=' + proof + '\nINPUT_NUMBER=21\n', 'utf8');
|
||||
fs.writeFileSync(path.join(root, 'README.md'), '# 模型连接验证\n\n此目录只有自动化验证的合成数据。\n', 'utf8');
|
||||
const api = async (route, input) => {
|
||||
const response = await fetch(url + '/api' + route, { method: input === undefined ? 'GET' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'X-Workbench-Token': bootstrap.token },
|
||||
...(input === undefined ? {} : { body: JSON.stringify(input) }) });
|
||||
const body = await response.json();
|
||||
if (!response.ok) throw new Error(body.error || ('请求失败 ' + response.status));
|
||||
return body;
|
||||
};
|
||||
const project = await api('/projects', { root });
|
||||
const created = await api('/sessions', { projectId: project.id });
|
||||
let completed = false;
|
||||
const started = Date.now();
|
||||
try {
|
||||
await api('/sessions/' + created.id + '/messages', { content:
|
||||
'这是工作台的真实模型连接验证。请先调用 read_file 读取 facts.txt,取得 PROOF_TOKEN 和 INPUT_NUMBER;不能从猜测得出内容。' +
|
||||
'随后调用 propose_file,提出新文件 MODEL-RESULT.md,内容包含读取到的完整 PROOF_TOKEN,以及 INPUT_NUMBER 乘以 2 的值,格式写成 PROOF_TOKEN=... 和 DOUBLED_NUMBER=...。' +
|
||||
'只产生提案,不能声称文件已经写入。最后用一句中文说明结果。不要运行终端命令,不要读取其他项目,不要重复提出相同提案。' });
|
||||
let state, lastProgress = '';
|
||||
while (Date.now() - started < 120000) {
|
||||
state = await api('/sessions/' + created.id);
|
||||
const progress = state.status + '|' + state.events.length;
|
||||
if (progress !== lastProgress) {
|
||||
console.log(JSON.stringify({ status: state.status, tools: state.events.filter(event => event.kind === 'tool').map(event => ({ tool: event.tool, phase: event.phase })), elapsedSeconds: Math.round((Date.now() - started) / 1000) }));
|
||||
lastProgress = progress;
|
||||
}
|
||||
for (const approval of state.approvals.filter(approval => approval.status === 'pending')) {
|
||||
await api('/sessions/' + created.id + '/approvals/' + approval.id, { allow: false });
|
||||
}
|
||||
if (!['running', 'awaiting_approval', 'stopping'].includes(state.status)) break;
|
||||
if (state.events.filter(event => event.kind === 'tool').length > 6) throw new Error('验证任务超出预期工具次数,已停止');
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
if (!state || ['running', 'awaiting_approval', 'stopping'].includes(state.status)) throw new Error('模型验证超时');
|
||||
if (state.status === 'failed') throw new Error(state.messages.filter(message => message.role === 'system').at(-1)?.content || '模型请求失败');
|
||||
assert.equal(state.executionMode, 'compatible');
|
||||
assert.ok(state.events.some(event => event.tool === 'read_file' && event.phase === 'completed' && event.input?.path === 'facts.txt'), '未取得真实文件读取结果');
|
||||
const proposal = state.changes.find(change => change.path === 'MODEL-RESULT.md' && change.status === 'pending');
|
||||
assert.ok(proposal, '模型没有生成预期文件提案');
|
||||
assert.ok(proposal.content.includes(proof), '提案没有包含实际读取的 token');
|
||||
assert.match(proposal.content, /DOUBLED_NUMBER\s*=\s*42/);
|
||||
assert.equal(fs.existsSync(path.join(root, 'MODEL-RESULT.md')), false, '审核前文件不应写入');
|
||||
await api('/sessions/' + created.id + '/changes/' + proposal.id + '/apply', {});
|
||||
assert.equal(fs.readFileSync(path.join(root, 'MODEL-RESULT.md'), 'utf8'), proposal.content);
|
||||
state = await api('/sessions/' + created.id);
|
||||
completed = true;
|
||||
const result = { success: true, testedAt: new Date().toISOString(), endpoint: bootstrap.config.baseUrl,
|
||||
model: bootstrap.config.model, projectRoot: root, projectId: project.id, sessionId: created.id,
|
||||
status: state.status, elapsedSeconds: Math.round((Date.now() - started) / 1000), usage: state.usage,
|
||||
tools: state.events.filter(event => event.kind === 'tool').map(event => ({ tool: event.tool, phase: event.phase })),
|
||||
evidence: ['真实配置的模型服务响应', 'read_file 读取随机合成数据', 'propose_file 使用读取结果', '审核前不写盘', '核对提案后应用成功'],
|
||||
credentialsHandling: '验证脚本使用服务内存中的连接配置,没有读取或记录 API Key' };
|
||||
fs.writeFileSync('.qa/live-model-validation.json', JSON.stringify(result, null, 2));
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
fs.writeFileSync('.qa/live-model-validation.json', JSON.stringify({ success: false, testedAt: new Date().toISOString(), model: bootstrap.config.model,
|
||||
sessionId: created.id, projectRoot: root, error: error.message, elapsedSeconds: Math.round((Date.now() - started) / 1000) }, null, 2));
|
||||
throw error;
|
||||
} finally {
|
||||
if (!completed) { try { await api('/sessions/' + created.id + '/stop', {}); } catch {} }
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
const url = process.env.AGENT_WORKBENCH_URL || 'http://127.0.0.1:4318';
|
||||
const sessionId = process.env.AGENT_WORKBENCH_SESSION || '569c9457-d399-46e6-b53e-4b1fdbb02109';
|
||||
const bootstrap = await (await fetch(url + '/api/bootstrap')).json();
|
||||
assert.equal(bootstrap.version, '1.0.0');
|
||||
assert.equal(bootstrap.config.mode, 'compatible');
|
||||
assert.ok(bootstrap.config.hasKey, 'The existing in-memory connection must be present.');
|
||||
const api = async (route, input) => {
|
||||
const response = await fetch(url + '/api' + route, { method: input === undefined ? 'GET' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'X-Workbench-Token': bootstrap.token },
|
||||
...(input === undefined ? {} : { body: JSON.stringify(input) }) });
|
||||
const value = await response.json(); assert.ok(response.ok, value.error); return value;
|
||||
};
|
||||
const before = await api('/sessions/' + sessionId);
|
||||
assert.equal(before.status, 'completed', 'Finish the original session before a read-only validation.');
|
||||
const project = bootstrap.projects.find(item => item.id === before.projectId);
|
||||
assert.ok(project);
|
||||
const approved = before.changes.filter(change => change.status === 'applied');
|
||||
assert.equal(approved.length, 2, 'This validation targets the original two applied changes.');
|
||||
const hash = file => createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
||||
const hashes = approved.map(change => ({ path: change.path, sha256: hash(path.join(project.root, change.path)) }));
|
||||
const digest = value => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
||||
const route = '/sessions/' + sessionId;
|
||||
const prompt = '刚才工作台里的 fetch failed 到底是怎么回事,跟项目的修改有关吗?src/catalog.js 和 tests/catalog.test.mjs 现在到底是什么状态?'
|
||||
+ '这次请只读诊断,不修改文件、不提出新改动、不运行终端命令。';
|
||||
const started = Date.now(); let done = false;
|
||||
fs.mkdirSync('.qa', { recursive: true });
|
||||
fs.writeFileSync('.qa/live-session-baseline.json', JSON.stringify({ sessionId, capturedAt: new Date().toISOString(),
|
||||
messageCount: before.messages.length, messagesSha256: digest(before.messages), eventCount: before.events.length,
|
||||
changesSha256: digest(before.changes), files: hashes }, null, 2));
|
||||
try {
|
||||
await api(route + '/messages', { content: prompt });
|
||||
let current, lastProgress = '';
|
||||
while (Date.now() - started < 180000) {
|
||||
current = await api(route);
|
||||
const tools = current.events.slice(before.events.length).filter(event => event.kind === 'tool');
|
||||
const progress = current.status + '|' + current.events.length;
|
||||
if (progress !== lastProgress) {
|
||||
console.log(JSON.stringify({ status: current.status, tools: tools.map(event => ({ tool: event.tool, phase: event.phase })), elapsedSeconds: Math.round((Date.now() - started) / 1000) }));
|
||||
lastProgress = progress;
|
||||
}
|
||||
assert.equal(current.approvals.filter(approval => approval.status === 'pending').length, 0, 'Read-only diagnosis must not request a terminal command.');
|
||||
assert.ok(tools.length <= 4, 'Diagnosis exceeded its bounded read-only scope.');
|
||||
if (!['running', 'awaiting_approval', 'stopping'].includes(current.status)) break;
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
assert.ok(current && !['running', 'awaiting_approval', 'stopping'].includes(current.status), 'Actual model validation timed out.');
|
||||
assert.equal(current.status, 'completed', current.failure?.message || 'Read-only diagnosis did not complete.');
|
||||
const tools = current.events.slice(before.events.length).filter(event => event.kind === 'tool');
|
||||
assert.ok(tools.some(event => event.tool === 'inspect_session' && event.phase === 'completed'), 'The model did not inspect the actual session.');
|
||||
assert.ok(tools.every(event => event.tool === 'inspect_session'
|
||||
|| (event.tool === 'read_file' && approved.some(change => change.path === event.input?.path))),
|
||||
'Diagnosis may inspect the runtime and the named applied files; unrelated searches and mutations are outside scope.');
|
||||
assert.deepEqual(current.changes, before.changes, 'Diagnosis must preserve file proposals and their current states.');
|
||||
assert.deepEqual(current.messages.slice(0, before.messages.length), before.messages, 'Existing conversation history must be preserved.');
|
||||
for (const file of hashes) assert.equal(hash(path.join(project.root, file.path)), file.sha256);
|
||||
const answer = current.messages.slice(before.messages.length).filter(message => message.role === 'assistant').at(-1)?.content || '';
|
||||
assert.match(answer, /模型/); assert.match(answer, /请求|连接/); assert.match(answer, /已应用|applied/);
|
||||
assert.ok(!/请.{0,12}(提供|上传).{0,15}(工作台|会话|工具).{0,6}(日志|记录)/.test(answer), 'The model must use workbench records already available.');
|
||||
const health = await (await fetch(url + '/api/health')).json();
|
||||
const result = { success: true, version: bootstrap.version, testedAt: new Date().toISOString(), url, pid: health.pid,
|
||||
sessionId, projectRoot: project.root, model: bootstrap.config.model, endpoint: bootstrap.config.baseUrl,
|
||||
elapsedSeconds: Math.round((Date.now() - started) / 1000), status: current.status,
|
||||
tools: tools.map(event => ({ tool: event.tool, phase: event.phase })), fileStates: current.changes.map(change => ({ path: change.path, status: change.status })),
|
||||
answer, preservedHistory: { messageCount: before.messages.length, sha256: digest(current.messages.slice(0, before.messages.length)) }, files: hashes,
|
||||
evidence: ['Actual configured model inspected the original session', 'Historical fetch failure attributed to the model request',
|
||||
'Current applied states used; optional reads limited to the two named applied files', 'No project searches, new proposals or terminal commands', 'Original messages and file hashes preserved'],
|
||||
credentialsHandling: 'The script used the existing in-memory connection through the local service; no API Key was accessed or recorded.' };
|
||||
fs.writeFileSync('.qa/live-session-validation.json', JSON.stringify(result, null, 2)); done = true;
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
fs.writeFileSync('.qa/live-session-validation.json', JSON.stringify({ success: false, version: bootstrap.version,
|
||||
testedAt: new Date().toISOString(), sessionId, model: bootstrap.config.model, error: error.message,
|
||||
elapsedSeconds: Math.round((Date.now() - started) / 1000) }, null, 2));
|
||||
throw error;
|
||||
} finally {
|
||||
if (!done) await api(route + '/stop', {}).catch(() => {});
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
import { spawn } from 'node:child_process';
|
||||
|
||||
const release = JSON.parse(fs.readFileSync('releases/latest.json', 'utf8'));
|
||||
const appRoot = release.portableRoot;
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(appRoot, 'MANIFEST.json'), 'utf8'));
|
||||
for (const file of manifest.files) {
|
||||
const absolute = path.resolve(appRoot, file.path);
|
||||
assert.ok(absolute.startsWith(appRoot + path.sep));
|
||||
const bytes = fs.readFileSync(absolute);
|
||||
assert.equal(bytes.length, file.bytes);
|
||||
assert.equal(createHash('sha256').update(bytes).digest('hex'), file.sha256, file.path);
|
||||
}
|
||||
const data = path.resolve('.qa', 'release-' + randomUUID());
|
||||
fs.mkdirSync(data, { recursive: true });
|
||||
const env = { ...process.env, AGENT_WORKBENCH_DATA_DIR: data, AGENT_WORKBENCH_PORT: '4320' };
|
||||
delete env.AGENT_WORKBENCH_API_KEY;
|
||||
for (const name of Object.keys(env)) if (name.toLowerCase() === 'path') delete env[name];
|
||||
const windowsRoot = process.env.SystemRoot || 'C:\\Windows';
|
||||
env.PATH = [windowsRoot, path.join(windowsRoot, 'System32'), path.join(windowsRoot, 'System32', 'WindowsPowerShell', 'v1.0')].join(path.delimiter);
|
||||
function runPowerShell(script, extra = []) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', path.join(appRoot, 'scripts', script), '-Port', '4320', ...extra], { windowsHide: true, env, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
let output = '', errors = '';
|
||||
child.stdout.on('data', bytes => { output += bytes.toString('utf8'); });
|
||||
child.stderr.on('data', bytes => { errors += bytes.toString('utf8'); });
|
||||
const timeout = setTimeout(() => { child.kill(); reject(new Error('Launcher did not exit in time.')); }, 20000);
|
||||
child.on('error', error => { clearTimeout(timeout); reject(error); });
|
||||
// Windows descendants can inherit pipe handles after the launcher exits.
|
||||
// Wait for the launcher itself, then close this test's readers.
|
||||
child.on('exit', code => {
|
||||
clearTimeout(timeout); child.stdout.destroy(); child.stderr.destroy();
|
||||
if (code === 0) resolve(output); else reject(new Error('Launcher failed: ' + errors));
|
||||
});
|
||||
});
|
||||
}
|
||||
const launch = () => runPowerShell('Start-Workbench.ps1', ['-NoBrowser']);
|
||||
const stop = () => runPowerShell('Stop-Workbench.ps1');
|
||||
const url = 'http://127.0.0.1:4320';
|
||||
const until = async predicate => {
|
||||
const deadline = Date.now() + 10000;
|
||||
while (!(await predicate())) {
|
||||
if (Date.now() > deadline) throw new Error('Release state timeout');
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
}
|
||||
};
|
||||
let started = false;
|
||||
try {
|
||||
console.log((await launch()).trim()); started = true;
|
||||
const bootstrap = await (await fetch(url + '/api/bootstrap')).json();
|
||||
const api = async (route, input) => {
|
||||
const response = await fetch(url + '/api' + route, { method: input === undefined ? 'GET' : 'POST', headers: { 'Content-Type': 'application/json', 'X-Workbench-Token': bootstrap.token },
|
||||
...(input === undefined ? {} : { body: JSON.stringify(input) }) });
|
||||
const result = await response.json(); assert.ok(response.ok, result.error); return result;
|
||||
};
|
||||
assert.equal(bootstrap.version, manifest.version); assert.equal(bootstrap.config.mode, 'demo');
|
||||
const firstInfo = JSON.parse(fs.readFileSync(path.join(data, 'service-info.json'), 'utf8'));
|
||||
console.log((await launch()).trim());
|
||||
assert.equal(JSON.parse(fs.readFileSync(path.join(data, 'service-info.json'), 'utf8')).pid, firstInfo.pid);
|
||||
const example = bootstrap.projects.find(project => project.id === bootstrap.exampleProjectId);
|
||||
assert.ok(example.root.toLowerCase().startsWith(appRoot.toLowerCase() + path.sep));
|
||||
const session = await api('/sessions', { projectId: example.id });
|
||||
await api('/sessions/' + session.id + '/messages', { content: '便携包工具与随附 Node 验证' });
|
||||
let current;
|
||||
await until(async () => { current = await api('/sessions/' + session.id); return current.status === 'awaiting_approval'; });
|
||||
assert.equal(current.approvals[0].command, 'node --version');
|
||||
assert.equal(fs.existsSync(path.join(example.root, 'WORKBENCH-NOTES.md')), false);
|
||||
await api('/sessions/' + session.id + '/approvals/' + current.approvals[0].id, { allow: true });
|
||||
await until(async () => { current = await api('/sessions/' + session.id); return current.status === 'needs_review'; });
|
||||
const command = current.events.find(event => event.tool === 'run_command');
|
||||
assert.equal(command.phase, 'completed'); assert.match(command.output, new RegExp(manifest.nodeVersion.replaceAll('.', '\\.')));
|
||||
assert.equal((await api('/research')).length, 4);
|
||||
const page = await fetch(url); assert.equal(page.status, 200);
|
||||
assert.match(await page.text(), /Agent Workbench/);
|
||||
console.log((await stop()).trim()); started = false;
|
||||
await until(async () => { try { await fetch(url + '/api/health'); return false; } catch { return true; } });
|
||||
const result = { success: true, date: new Date().toISOString(), appRoot, version: manifest.version, nodeVersion: manifest.nodeVersion,
|
||||
verifiedFiles: manifest.files.length, url, reusedPid: firstInfo.pid, steps: ['manifest hashes', 'bundled Node launch', 'same-service reuse', 'packaged example and static page', 'explicit command consent', 'actual bundled Node version', 'report availability', 'graceful stop'], realModel: false };
|
||||
fs.writeFileSync('.qa/release-validation.json', JSON.stringify(result, null, 2));
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
} finally { if (started) { try { await stop(); } catch {} } }
|
||||
@@ -0,0 +1,257 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import http from 'node:http';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { chromium, expect } from 'playwright/test';
|
||||
|
||||
const url = process.env.AGENT_WORKBENCH_URL || 'http://127.0.0.1:4319';
|
||||
const caseRoot = path.resolve('.qa', 'ui-' + randomUUID());
|
||||
const projectRoot = path.join(caseRoot, 'ui-project');
|
||||
const secondaryRoot = path.join(caseRoot, 'other-project');
|
||||
fs.mkdirSync(caseRoot, { recursive: true });
|
||||
fs.cpSync('examples/starter-project', projectRoot, { recursive: true });
|
||||
fs.mkdirSync(secondaryRoot);
|
||||
fs.writeFileSync(path.join(secondaryRoot, 'SECONDARY.md'), '# Another project\n');
|
||||
fs.mkdirSync('.qa/screenshots', { recursive: true });
|
||||
const bootstrap = await (await fetch(url + '/api/bootstrap')).json();
|
||||
assert.equal(bootstrap.config.mode, 'demo', 'UI validation requires an independent demo service.');
|
||||
assert.equal(bootstrap.config.hasKey, false, 'UI validation must not replace a configured model connection.');
|
||||
const api = async (route, input) => {
|
||||
const response = await fetch(url + '/api' + route, { method: input === undefined ? 'GET' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json', 'X-Workbench-Token': bootstrap.token },
|
||||
...(input === undefined ? {} : { body: JSON.stringify(input) }) });
|
||||
const result = await response.json();
|
||||
assert.ok(response.ok, result.error); return result;
|
||||
};
|
||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||
const passed = [], errors = [], networkErrors = [];
|
||||
const mark = value => { passed.push(value); console.log('PASS ' + value); };
|
||||
let stage = 'initial', page;
|
||||
let modelRequests = 0;
|
||||
const model = http.createServer(async (request, response) => {
|
||||
const chunks = []; for await (const chunk of request) chunks.push(chunk);
|
||||
response.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
if (request.url === '/v1/models') return response.end(JSON.stringify({ data: [{ id: 'fixture-ui-agent' }] }));
|
||||
const input = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
||||
const lastUser = input.messages.findLastIndex(message => message.role === 'user');
|
||||
const count = input.messages.slice(lastUser + 1).filter(message => message.role === 'tool').length;
|
||||
modelRequests++;
|
||||
const tool = count === 0 ? { name: 'list_files', arguments: JSON.stringify({ path: '', depth: 2 }) }
|
||||
: count === 1 ? { name: 'propose_file', arguments: JSON.stringify({ path: 'COMPATIBLE-TEST.md', content: '# 本地兼容协议验证\n\n本文件来自受控接口测试,没有使用真实大模型。\n', reason: '浏览器端到端兼容协议测试' }) } : null;
|
||||
response.end(JSON.stringify({ choices: [{ message: { role: 'assistant', content: tool ? '本地兼容接口测试。' : '兼容协议流程已完成,本次没有使用真实大模型。',
|
||||
...(tool ? { tool_calls: [{ id: 'ui-' + randomUUID(), type: 'function', function: tool }] } : {}) }, finish_reason: tool ? 'tool_calls' : 'stop' }], usage: { prompt_tokens: 99, completion_tokens: 30 } }));
|
||||
});
|
||||
await new Promise(resolve => model.listen(0, '127.0.0.1', resolve));
|
||||
const browser = await chromium.launch({ channel: 'msedge', headless: true });
|
||||
const openProject = async root => {
|
||||
await page.getByRole('button', { name: '打开项目', exact: true }).click();
|
||||
const dialog = page.getByRole('dialog', { name: '打开项目' });
|
||||
await dialog.getByLabel('项目文件夹路径').fill(root);
|
||||
await dialog.getByRole('button', { name: '打开项目', exact: true }).click();
|
||||
await expect(dialog).not.toBeVisible();
|
||||
};
|
||||
const assertViewport = async () => {
|
||||
const bounds = await page.evaluate(() => {
|
||||
const header = document.querySelector('.work-header').getBoundingClientRect();
|
||||
const composer = document.querySelector('.composer-wrap').getBoundingClientRect();
|
||||
return { scrollY: window.scrollY, top: header.top, bottom: composer.bottom, height: window.innerHeight,
|
||||
scrollHeight: document.documentElement.scrollHeight, scrollWidth: document.documentElement.scrollWidth, width: window.innerWidth };
|
||||
});
|
||||
assert.equal(bounds.scrollY, 0, 'The document should not scroll');
|
||||
assert.ok(bounds.top >= -1 && bounds.bottom <= bounds.height + 1, 'Header and composer must stay in the viewport: ' + JSON.stringify(bounds));
|
||||
assert.ok(bounds.scrollHeight <= bounds.height + 1 && bounds.scrollWidth <= bounds.width + 1, 'The page should not overflow');
|
||||
};
|
||||
const screenshot = async name => {
|
||||
const toastClose = page.locator('.toast').getByRole('button', { name: '关闭提示', exact: true });
|
||||
if (await toastClose.isVisible()) await toastClose.click();
|
||||
await assertViewport();
|
||||
return page.screenshot({ path: '.qa/screenshots/' + name + '.png', fullPage: true });
|
||||
};
|
||||
const newTask = async content => {
|
||||
await page.getByRole('button', { name: '新建任务', exact: true }).click();
|
||||
await page.getByLabel('任务内容').fill(content);
|
||||
await page.getByRole('button', { name: '发送任务', exact: true }).click();
|
||||
};
|
||||
try {
|
||||
page = await browser.newPage({ viewport: { width: 1440, height: 960 }, deviceScaleFactor: 1, acceptDownloads: true });
|
||||
page.setDefaultTimeout(10000);
|
||||
page.on('pageerror', error => errors.push(error.message));
|
||||
page.on('requestfailed', request => { if (!request.url().includes('/api/events')) networkErrors.push(request.url() + ': ' + request.failure()?.errorText); });
|
||||
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
||||
await page.waitForLoadState('networkidle', { timeout: 6000 }).catch(() => {});
|
||||
await page.locator('.connection.connected').waitFor();
|
||||
stage = 'open project'; await openProject(projectRoot);
|
||||
await expect(page.locator('.tree-row[title="src/catalog.js"]')).toBeVisible();
|
||||
const selectedProject = (await api('/bootstrap')).projects.find(project => project.root.toLowerCase() === projectRoot.toLowerCase());
|
||||
assert.ok(selectedProject);
|
||||
await screenshot('desktop-ready');
|
||||
stage = 'file preview'; await page.locator('.tree-row[title="README.md"]').click();
|
||||
await expect(page.locator('.file-heading > span')).toHaveText('README.md');
|
||||
await expect(page.locator('.code-view')).toContainText('研究任务看板');
|
||||
mark('project selection and real file preview');
|
||||
|
||||
stage = 'offline task'; await newTask('UI 验证:读取项目并提出改动');
|
||||
await page.locator('.approval-card').waitFor();
|
||||
await expect(page.locator('.approval-card > pre')).toHaveText('node --version');
|
||||
assert.equal(fs.existsSync(path.join(projectRoot, 'WORKBENCH-NOTES.md')), false);
|
||||
await page.locator('.inspector-tabs').getByRole('button', { name: /^改动/ }).click();
|
||||
await expect(page.locator('.diff-view')).toContainText('工作台验证记录');
|
||||
await screenshot('command-approval');
|
||||
stage = 'approval delayed snapshot';
|
||||
const approvalRoute = '**/api/sessions/*/approvals/*';
|
||||
await page.route(approvalRoute, async route => { const response = await route.fetch(); await sleep(700); await route.fulfill({ response }); });
|
||||
await page.getByRole('button', { name: '确认执行', exact: true }).click();
|
||||
await expect(page.locator('.task-toolbar .status')).toHaveText('待审查');
|
||||
await sleep(800); await expect(page.locator('.task-toolbar .status')).toHaveText('待审查');
|
||||
await page.unroute(approvalRoute);
|
||||
await page.locator('.inline-event .tool-row').filter({ hasText: 'node --version' }).click();
|
||||
await expect(page.locator('.event-details')).toContainText(/v\d+\.\d+\.\d+/);
|
||||
mark('real command consent, execution and stale snapshot rejection');
|
||||
stage = 'apply proposal'; await page.locator('.review-callout').click();
|
||||
await screenshot('desktop-diff-review');
|
||||
await page.getByRole('button', { name: '应用这项改动', exact: true }).click();
|
||||
await expect(page.locator('.change-summary .status')).toHaveText('已应用');
|
||||
await expect(page.locator('.task-toolbar .status')).toHaveText('已完成');
|
||||
assert.match(fs.readFileSync(path.join(projectRoot, 'WORKBENCH-NOTES.md'), 'utf8'), /没有调用大模型/);
|
||||
mark('diff review and verified file application');
|
||||
|
||||
stage = 'manual edit'; await page.locator('.tree-row[title="README.md"]').click();
|
||||
await page.getByRole('button', { name: '编辑文件', exact: true }).click();
|
||||
const original = await page.getByLabel('编辑文件内容').inputValue();
|
||||
await page.getByLabel('编辑文件内容').fill(original + '\n## UI 验证\n手动编辑已通过差异审查。\n');
|
||||
await page.getByRole('button', { name: '保存为提案', exact: true }).click();
|
||||
await expect(page.locator('.task-toolbar .status')).toHaveText('待审查');
|
||||
assert.ok(!fs.readFileSync(path.join(projectRoot, 'README.md'), 'utf8').includes('手动编辑已通过'));
|
||||
await page.getByRole('button', { name: '应用这项改动', exact: true }).click();
|
||||
await expect(page.locator('.change-summary .status')).toHaveText('已应用');
|
||||
assert.match(fs.readFileSync(path.join(projectRoot, 'README.md'), 'utf8'), /手动编辑已通过/);
|
||||
mark('manual editor creates a reviewable proposal');
|
||||
|
||||
stage = 'file response ordering';
|
||||
const delayedFile = '**/api/projects/' + selectedProject.id + '/file?path=README.md';
|
||||
await page.route(delayedFile, async route => { const response = await route.fetch(); await sleep(450); await route.fulfill({ response }); });
|
||||
await page.locator('.tree-row[title="README.md"]').click();
|
||||
await page.locator('.tree-row[title="src/catalog.js"]').click();
|
||||
await expect(page.locator('.file-heading > span')).toHaveText('src/catalog.js');
|
||||
await sleep(550); await expect(page.locator('.file-heading > span')).toHaveText('src/catalog.js');
|
||||
await page.unroute(delayedFile); mark('file responses stay with the current selection');
|
||||
|
||||
stage = 'session persistence and ordering'; await newTask('UI 第二任务:拒绝演示命令');
|
||||
await page.locator('.approval-card').waitFor();
|
||||
await page.getByRole('button', { name: '拒绝执行', exact: true }).click();
|
||||
await expect(page.locator('.task-toolbar .status')).toHaveText('待审查');
|
||||
const sessions = await api('/sessions');
|
||||
const first = sessions.find(session => session.title.startsWith('UI 验证:'));
|
||||
const second = sessions.find(session => session.title.startsWith('UI 第二任务:'));
|
||||
assert.ok(first && second);
|
||||
const delayedSession = '**/api/sessions/' + first.id;
|
||||
await page.route(delayedSession, async route => { const response = await route.fetch(); await sleep(450); await route.fulfill({ response }); });
|
||||
await page.locator('.session-select').filter({ hasText: 'UI 验证:' }).click();
|
||||
await page.locator('.session-select').filter({ hasText: 'UI 第二任务:' }).click();
|
||||
await expect(page.locator('.work-title h1')).toHaveText(second.title);
|
||||
await sleep(550); await expect(page.locator('.work-title h1')).toHaveText(second.title);
|
||||
await page.unroute(delayedSession);
|
||||
await page.reload({ waitUntil: 'domcontentloaded' });
|
||||
await expect(page.locator('.work-title h1')).toHaveText(second.title);
|
||||
const downloadPromise = page.waitForEvent('download');
|
||||
await page.getByRole('button', { name: '导出会话', exact: true }).click();
|
||||
const download = await downloadPromise; await download.saveAs(path.join(caseRoot, 'session-export.json'));
|
||||
assert.equal(JSON.parse(fs.readFileSync(path.join(caseRoot, 'session-export.json'), 'utf8')).session.id, second.id);
|
||||
mark('denial, session selection, reload, stale response rejection and export');
|
||||
|
||||
stage = 'project response ordering'; await openProject(secondaryRoot);
|
||||
await expect(page.locator('.tree-row[title="SECONDARY.md"]')).toBeVisible();
|
||||
const otherProject = (await api('/bootstrap')).projects.find(project => project.root.toLowerCase() === secondaryRoot.toLowerCase());
|
||||
const delayedInventory = '**/api/projects/' + selectedProject.id + '/files';
|
||||
await page.route(delayedInventory, async route => { const response = await route.fetch(); await sleep(450); await route.fulfill({ response }); });
|
||||
await page.getByLabel('当前项目').selectOption(selectedProject.id);
|
||||
await page.getByLabel('当前项目').selectOption(otherProject.id);
|
||||
await expect(page.locator('.tree-row[title="SECONDARY.md"]')).toBeVisible();
|
||||
await sleep(550); await expect(page.locator('.tree-row[title="src/catalog.js"]')).toHaveCount(0);
|
||||
await page.unroute(delayedInventory);
|
||||
await page.getByLabel('当前项目').selectOption(selectedProject.id);
|
||||
await expect(page.locator('.tree-row[title="src/catalog.js"]')).toBeVisible();
|
||||
mark('project inventory responses cannot replace another project');
|
||||
|
||||
stage = 'narrow and mobile'; await page.setViewportSize({ width: 780, height: 960 });
|
||||
await page.getByRole('button', { name: '查看改动', exact: true }).click();
|
||||
await expect(page.locator('.inspector')).toBeVisible();
|
||||
await screenshot('tablet-diff');
|
||||
await page.getByRole('button', { name: '关闭检视区', exact: true }).click();
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await expect(page.locator('.workbench')).toHaveClass(/sidebar-hidden/);
|
||||
await expect(page.locator('.project-sidebar')).not.toBeVisible();
|
||||
await expect(page.getByRole('button', { name: '展开项目栏', exact: true })).toBeVisible();
|
||||
await page.getByRole('button', { name: '展开项目栏', exact: true }).click();
|
||||
await expect(page.locator('.project-sidebar')).toBeVisible();
|
||||
await page.locator('.tree-row[title="README.md"]').click();
|
||||
await expect(page.locator('.inspector')).toBeVisible();
|
||||
await expect(page.locator('.file-heading > span')).toHaveText('README.md');
|
||||
await screenshot('mobile-file');
|
||||
await page.getByRole('button', { name: '关闭检视区', exact: true }).click();
|
||||
await page.getByRole('button', { name: '查看执行轨迹', exact: true }).click();
|
||||
await expect(page.locator('.trace-list')).toBeVisible();
|
||||
await screenshot('mobile-trace');
|
||||
await page.getByRole('button', { name: '关闭检视区', exact: true }).click();
|
||||
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth));
|
||||
await screenshot('mobile-conversation');
|
||||
mark('780 and 390 px: project drawer, file, diff and trace controls, no page overflow');
|
||||
|
||||
stage = 'research'; await page.setViewportSize({ width: 1440, height: 960 });
|
||||
if (!(await page.locator('.project-sidebar').isVisible())) await page.getByRole('button', { name: '展开项目栏', exact: true }).click();
|
||||
await page.getByRole('button', { name: '机制研究与设计', exact: true }).click();
|
||||
const research = page.getByRole('dialog', { name: '机制研究与独立设计' });
|
||||
await expect(research.locator('.research-content')).toContainText('统一机制报告');
|
||||
assert.ok(await research.locator('table').count() >= 2);
|
||||
await screenshot('research-overview');
|
||||
await research.locator('nav').getByRole('button', { name: /Claude Code:工具循环/ }).click();
|
||||
await expect(research.locator('.research-content')).toContainText('工具调度、权限与结果机制');
|
||||
await research.locator('nav').getByRole('button', { name: /Claude Code:上下文与恢复/ }).click();
|
||||
await expect(research.locator('.research-content')).toContainText('上下文压缩与会话恢复');
|
||||
await research.locator('nav').getByRole('button', { name: /Cursor:执行与编辑/ }).click();
|
||||
await expect(research.locator('.research-content')).toContainText('本地工具执行与恢复机制');
|
||||
await research.getByRole('button', { name: '关闭窗口', exact: true }).click();
|
||||
mark('unified and detailed research reports render');
|
||||
|
||||
stage = 'compatible model settings';
|
||||
await page.getByRole('button', { name: '模型连接', exact: true }).click();
|
||||
const settings = page.getByRole('dialog', { name: '模型连接' });
|
||||
await settings.getByRole('button', { name: /兼容模型服务/ }).click();
|
||||
await settings.getByLabel('接口根地址', { exact: true }).fill('http://127.0.0.1:' + model.address().port + '/v1');
|
||||
await settings.getByLabel('API Key(按服务要求填写)', { exact: true }).fill('fixture-ui-key');
|
||||
await settings.getByRole('button', { name: '读取模型列表', exact: true }).click();
|
||||
await expect(settings.getByLabel('模型名称', { exact: true })).toHaveValue('fixture-ui-agent');
|
||||
assert.equal((await api('/bootstrap')).config.hasKey, false);
|
||||
await settings.getByRole('button', { name: '保存连接', exact: true }).click();
|
||||
await expect(page.getByRole('button', { name: 'fixture-ui-agent', exact: true })).toBeVisible();
|
||||
await newTask('UI 兼容接口验证');
|
||||
await expect(page.locator('.conversation')).toContainText('兼容协议流程已完成');
|
||||
await expect(page.locator('.task-toolbar .status')).toHaveText('待审查');
|
||||
assert.equal(modelRequests, 3);
|
||||
await page.locator('.review-callout').click();
|
||||
await page.getByRole('button', { name: '应用这项改动', exact: true }).click();
|
||||
await expect(page.locator('.change-summary .status')).toHaveText('已应用');
|
||||
assert.match(fs.readFileSync(path.join(projectRoot, 'COMPATIBLE-TEST.md'), 'utf8'), /没有使用真实大模型/);
|
||||
await screenshot('compatible-fixture');
|
||||
await page.getByRole('button', { name: '模型连接', exact: true }).click();
|
||||
await settings.getByRole('button', { name: '清除 Key', exact: true }).click();
|
||||
await settings.getByRole('button', { name: /离线演示/ }).click();
|
||||
await settings.getByRole('button', { name: '保存连接', exact: true }).click();
|
||||
assert.equal((await api('/bootstrap')).config.hasKey, false);
|
||||
mark('model list, ephemeral key, compatible fixture tool loop and return to offline mode');
|
||||
|
||||
stage = 'complete'; assert.deepEqual(errors, []); assert.deepEqual(networkErrors, []);
|
||||
const summary = { success: true, url, browser: 'Microsoft Edge ' + browser.version(), date: new Date().toISOString(), projectRoot,
|
||||
viewports: [1440, 780, 390], passed, pageErrors: errors, requestFailures: networkErrors, modelValidation: 'controlled local HTTP fixture; no real model' };
|
||||
fs.writeFileSync('.qa/ui-validation.json', JSON.stringify(summary, null, 2));
|
||||
console.log(JSON.stringify(summary, null, 2));
|
||||
} catch (error) {
|
||||
if (page) { await screenshot('failure-' + stage.replace(/[^a-z0-9]+/gi, '-')).catch(() => {}); fs.writeFileSync('.qa/failure-dom.html', await page.content().catch(() => '')); }
|
||||
fs.writeFileSync('.qa/ui-validation.json', JSON.stringify({ success: false, stage, error: error.message, passed, pageErrors: errors }, null, 2));
|
||||
throw error;
|
||||
} finally {
|
||||
await browser.close();
|
||||
await api('/config', { ...bootstrap.config, mode: 'demo', apiKey: '' }).catch(() => {});
|
||||
model.closeAllConnections(); await new Promise(resolve => model.close(resolve));
|
||||
}
|
||||
Reference in New Issue
Block a user