feat: integrate task-bound REA research and portable runtime
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { REA_VERSION, REA_PROTOCOL, resolveReaInstallation } from '../src/core/tools/rea-adapter.mjs';
|
||||
|
||||
const digest = file => createHash('sha256').update(fs.readFileSync(file)).digest('hex');
|
||||
const inside = (root, filename) => path.resolve(filename).startsWith(path.resolve(root) + path.sep);
|
||||
const packageMetadata = root => JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
||||
|
||||
export function planReaBundle(appRoot) {
|
||||
const installation = resolveReaInstallation(appRoot);
|
||||
if (installation.status !== 'available') throw new Error('REA release dependency is unavailable: ' + installation.message);
|
||||
const modules = path.dirname(installation.packageRoot), sourceRoot = path.dirname(modules);
|
||||
const originalLock = path.join(sourceRoot, 'package-lock.json'), lockPath = fs.existsSync(originalLock) ? originalLock : path.join(sourceRoot, 'REA-PACKAGE-LOCK.json');
|
||||
if (path.basename(modules) !== 'node_modules' || !fs.existsSync(lockPath)) throw new Error('Use the isolated, locked REA production installation when packaging.');
|
||||
const lock = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
|
||||
if (lock.packages?.['node_modules/rea-agents']?.version !== REA_VERSION || lock.packages['']?.dependencies?.['rea-agents'] !== REA_VERSION) throw new Error('REA installation lock does not match the fixed release contract.');
|
||||
const packages = [], absentOptional = [];
|
||||
for (const [relative, expected] of Object.entries(lock.packages)) {
|
||||
if (!relative.startsWith('node_modules/')) continue;
|
||||
const absolute = path.resolve(sourceRoot, relative);
|
||||
if (!inside(modules, absolute)) throw new Error('REA dependency escapes its installation: ' + relative);
|
||||
if (!fs.existsSync(path.join(absolute, 'package.json'))) {
|
||||
if (expected.optional || expected.dev) { if (expected.optional) absentOptional.push(relative); continue; }
|
||||
throw new Error('REA required installed dependency is missing: ' + relative);
|
||||
}
|
||||
if (expected.dev) throw new Error('REA release input must contain only production dependencies: ' + relative);
|
||||
if (fs.lstatSync(absolute).isSymbolicLink() || !inside(modules, fs.realpathSync.native(absolute))) throw new Error('REA release dependencies must be regular contained directories.');
|
||||
const metadata = packageMetadata(absolute);
|
||||
if (metadata.version !== expected.version) throw new Error('REA installed dependency declaration differs from its lock: ' + relative);
|
||||
const licenseFiles = fs.readdirSync(absolute).filter(name => /^(licen[cs]e|copying)([.-].*)?$/i.test(name) && fs.statSync(path.join(absolute, name)).isFile());
|
||||
packages.push({ path: relative, name: metadata.name, version: metadata.version, license: metadata.license ?? expected.license ?? null,
|
||||
integrity: expected.integrity ?? null, licenseFiles });
|
||||
}
|
||||
const topLevel = packages.filter(item => !packages.some(parent => item !== parent && item.path.startsWith(parent.path + '/')));
|
||||
if (!packages.some(item => item.name === 'rea-agents' && item.version === REA_VERSION)) throw new Error('REA package is absent from the installed production graph.');
|
||||
return { installation, sourceRoot, lockPath, lockSha256: digest(lockPath), packages, topLevel, absentOptional, builtAt: new Date().toISOString() };
|
||||
}
|
||||
|
||||
export function copyReaBundle(destinationRuntime, plan) {
|
||||
fs.mkdirSync(destinationRuntime, { recursive: true });
|
||||
for (const item of plan.topLevel) {
|
||||
const destination = path.join(destinationRuntime, item.path);
|
||||
if (!inside(destinationRuntime, destination)) throw new Error('REA destination is outside the new release runtime.');
|
||||
if (fs.existsSync(destination)) throw new Error('Refusing to overwrite a runtime dependency: ' + item.path);
|
||||
fs.cpSync(path.join(plan.sourceRoot, item.path), destination, { recursive: true, filter: file => {
|
||||
if (fs.lstatSync(file).isSymbolicLink()) throw new Error('REA runtime contains an unsupported link: ' + file);
|
||||
return true;
|
||||
} });
|
||||
}
|
||||
fs.copyFileSync(plan.lockPath, path.join(destinationRuntime, 'REA-PACKAGE-LOCK.json'));
|
||||
const files = [];
|
||||
const walk = relative => {
|
||||
for (const entry of fs.readdirSync(path.join(destinationRuntime, relative), { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
||||
const filename = path.join(relative, entry.name);
|
||||
if (entry.isDirectory()) walk(filename);
|
||||
else if (entry.isFile()) files.push({ path: filename.replaceAll('\\', '/'), bytes: fs.statSync(path.join(destinationRuntime, filename)).size,
|
||||
sha256: digest(path.join(destinationRuntime, filename)) });
|
||||
else throw new Error('REA runtime contains a non-regular entry: ' + filename);
|
||||
}
|
||||
};
|
||||
for (const item of plan.topLevel) walk(item.path);
|
||||
const manifest = { schemaVersion: 1, name: 'rea-agents', version: REA_VERSION, protocolVersion: REA_PROTOCOL, builtAt: plan.builtAt,
|
||||
installationLock: { path: 'REA-PACKAGE-LOCK.json', sha256: plan.lockSha256 }, packages: plan.packages,
|
||||
absentOptional: plan.absentOptional, files,
|
||||
identityScope: 'Copied installed production package declarations and file snapshots; MCP handshake and static operations are independently verified.',
|
||||
capabilities: ['javascript-asar-static', 'pe-imports-static', 'pe-resources-static'] };
|
||||
fs.writeFileSync(path.join(destinationRuntime, 'REA-RUNTIME.json'), JSON.stringify(manifest, null, 2) + '\n');
|
||||
return { version: manifest.version, protocolVersion: manifest.protocolVersion, packages: manifest.packages.length,
|
||||
files: files.length, bytes: files.reduce((sum, item) => sum + item.bytes, 0), lockSha256: plan.lockSha256 };
|
||||
}
|
||||
+10
-1
@@ -2,10 +2,12 @@ import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { planReaBundle, copyReaBundle } from './bundle-rea.mjs';
|
||||
|
||||
const root = process.cwd();
|
||||
const meta = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
||||
const lock = JSON.parse(fs.readFileSync('package-lock.json', 'utf8'));
|
||||
const reaPlan = planReaBundle(root);
|
||||
const releases = path.resolve(root, 'releases');
|
||||
fs.mkdirSync(releases, { recursive: true });
|
||||
const baseName = 'Agent-Workbench-' + meta.version;
|
||||
@@ -42,6 +44,8 @@ if (!fs.existsSync(runtimeDestination) || digest(runtimeDestination) !== digest(
|
||||
const npmRoot = path.join(path.dirname(nodeBinary), 'node_modules', 'npm');
|
||||
if (!fs.existsSync(path.join(npmRoot, 'bin', 'npm-cli.js'))) throw new Error('The portable engineering runner requires the npm shipped with this Node distribution.');
|
||||
copyTree(npmRoot, path.join(portableRoot, 'runtime', 'node_modules', 'npm'));
|
||||
const reaRuntime = copyReaBundle(path.join(portableRoot, 'runtime'), reaPlan);
|
||||
copyReaBundle(path.join(sourceRoot, 'runtime'), reaPlan);
|
||||
|
||||
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.',
|
||||
@@ -67,6 +71,11 @@ for (const [location, entry] of Object.entries(lock.packages).sort(([a], [b]) =>
|
||||
}
|
||||
}
|
||||
const nodeLicenseText = fs.readFileSync(nodeLicense, 'utf8');
|
||||
const reaLicenseText = fs.readFileSync(path.join(reaPlan.installation.packageRoot, 'LICENSE'), 'utf8');
|
||||
fs.writeFileSync(path.join(licenseRoot, 'REA-' + reaRuntime.version + '-LICENSE.txt'), reaLicenseText);
|
||||
notices.push('='.repeat(72), 'REA (rea-agents) ' + reaRuntime.version, 'License: MIT', 'Source: https://github.com/morluto/rea', '', reaLicenseText,
|
||||
'The fixed production dependency declarations, integrity metadata and file hashes are recorded in runtime/REA-RUNTIME.json.',
|
||||
'Original package and dependency license texts remain under runtime/node_modules/. REA additional notices are retained at runtime/node_modules/rea-agents/THIRD_PARTY_NOTICES.md.', '');
|
||||
fs.writeFileSync(path.join(licenseRoot, 'Node-' + nodeVersion + '-LICENSE.txt'), nodeLicenseText);
|
||||
notices.push('='.repeat(72), 'Node.js ' + nodeVersion, '', nodeLicenseText);
|
||||
notices.push('='.repeat(72), 'npm bundled with Node.js', 'Complete package and dependency licenses are retained under runtime/node_modules/npm/.', '', fs.readFileSync(path.join(npmRoot, 'LICENSE'), 'utf8'));
|
||||
@@ -103,6 +112,6 @@ function archive(directory) {
|
||||
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 };
|
||||
const result = { portableRoot, sourceRoot, portable: archive(portableRoot), source: archive(sourceRoot), nodeVersion, reaRuntime, portableFiles: portableManifest.files.length, licenseTexts: licenseCount + 2 };
|
||||
fs.writeFileSync(path.join(releases, 'latest.json'), JSON.stringify(result, null, 2));
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
// Self-owned inert artifact fixtures. These bytes are only parsed by REA;
|
||||
// neither the JavaScript bootstrap nor the synthetic PE image is executed.
|
||||
export function ownedAsar(files) {
|
||||
let offset = 0; const directory = { files: {} }, bodies = [];
|
||||
for (const [name, value] of Object.entries(files)) {
|
||||
const bytes = Buffer.from(value, 'utf8'); directory.files[name] = { size: bytes.length, offset: String(offset) };
|
||||
offset += bytes.length; bodies.push(bytes);
|
||||
}
|
||||
const json = Buffer.from(JSON.stringify(directory)), header = Buffer.alloc(8 + Math.ceil(json.length / 4) * 4);
|
||||
header.writeUInt32LE(header.length - 4, 0); header.writeUInt32LE(json.length, 4); json.copy(header, 8);
|
||||
const size = Buffer.alloc(8); size.writeUInt32LE(4, 0); size.writeUInt32LE(header.length, 4);
|
||||
return Buffer.concat([size, header, ...bodies]);
|
||||
}
|
||||
|
||||
export function ownedPe() {
|
||||
const bytes = Buffer.alloc(1024), pe = 0x80, optional = pe + 24, section = optional + 0xf0;
|
||||
bytes.write('MZ'); bytes.writeUInt32LE(pe, 0x3c); bytes.write('PE\0\0', pe, 'ascii');
|
||||
bytes.writeUInt16LE(0x8664, pe + 4); bytes.writeUInt16LE(1, pe + 6); bytes.writeUInt16LE(0xf0, pe + 20); bytes.writeUInt16LE(0x2022, pe + 22);
|
||||
bytes.writeUInt16LE(0x20b, optional); bytes.writeBigUInt64LE(0x140000000n, optional + 24);
|
||||
bytes.writeUInt32LE(0x1000, optional + 32); bytes.writeUInt32LE(0x200, optional + 36);
|
||||
bytes.writeUInt16LE(6, optional + 40); bytes.writeUInt16LE(6, optional + 48);
|
||||
bytes.writeUInt32LE(0x2000, optional + 56); bytes.writeUInt32LE(0x200, optional + 60); bytes.writeUInt16LE(3, optional + 68);
|
||||
bytes.writeUInt32LE(16, optional + 108);
|
||||
bytes.writeUInt32LE(0x1000, optional + 120); bytes.writeUInt32LE(40, optional + 124);
|
||||
bytes.writeUInt32LE(0x1100, optional + 128); bytes.writeUInt32LE(0x80, optional + 132);
|
||||
bytes.write('.rdata', section, 'ascii'); bytes.writeUInt32LE(512, section + 8); bytes.writeUInt32LE(0x1000, section + 12);
|
||||
bytes.writeUInt32LE(512, section + 16); bytes.writeUInt32LE(0x200, section + 20); bytes.writeUInt32LE(0x40000040, section + 36);
|
||||
const raw = rva => rva - 0x1000 + 0x200;
|
||||
bytes.writeUInt32LE(0x1040, raw(0x1000)); bytes.writeUInt32LE(0x1080, raw(0x1000) + 12); bytes.writeUInt32LE(0x1060, raw(0x1000) + 16);
|
||||
bytes.writeBigUInt64LE(0x1090n, raw(0x1040)); bytes.writeBigUInt64LE(0x1090n, raw(0x1060));
|
||||
bytes.write('KERNEL32.dll\0', raw(0x1080), 'ascii'); bytes.write('ExitProcess\0', raw(0x1090) + 2, 'ascii');
|
||||
for (const [rva, name, child] of [[0x1100, 10, 0x80000020], [0x1120, 1, 0x80000040], [0x1140, 0x409, 0x60]]) {
|
||||
bytes.writeUInt16LE(1, raw(rva) + 14); bytes.writeUInt32LE(name, raw(rva) + 16); bytes.writeUInt32LE(child, raw(rva) + 20);
|
||||
}
|
||||
bytes.writeUInt32LE(0x1170, raw(0x1160)); bytes.writeUInt32LE(8, raw(0x1160) + 4); bytes.write('REA-DATA', raw(0x1170), 'ascii');
|
||||
return bytes;
|
||||
}
|
||||
|
||||
export function createResearchSamples(directory) {
|
||||
fs.mkdirSync(directory, { recursive: true });
|
||||
const marker = path.join(directory, 'bootstrap-executed.txt');
|
||||
const asar = path.join(directory, 'owned-agent.asar'), pe = path.join(directory, 'owned-imports-resources.dll');
|
||||
fs.writeFileSync(asar, ownedAsar({
|
||||
'package.json': JSON.stringify({ name: 'owned-agent-fixture', version: '1.0.0', main: 'main.js' }),
|
||||
'main.js': "const fs = require('node:fs');\nfs.writeFileSync(" + JSON.stringify(marker) + ", 'must not execute');\nexports.inspect = async file => fs.promises.readFile(file, 'utf8');\n",
|
||||
'preload.js': "export const contract = { approval: 'per-call', replay: false };\n",
|
||||
}), { flag: 'wx' });
|
||||
fs.writeFileSync(pe, ownedPe(), { flag: 'wx' });
|
||||
return { asar, pe, marker };
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export async function upgradeRunning({ url, pid, currentRoot, newRoot, handlerRo
|
||||
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 readUpgradeJson(origin + '/api/bootstrap', 5000, 'Read original Workbench');
|
||||
if (!before.token || !['0.1.0', '1.0.0', '1.1.0', '1.2.0', '1.3.0', '1.4.0', '1.5.0', '1.5.1', '1.6.0', '1.6.1', '1.6.2', '1.7.0'].includes(before.version)) throw new Error('This migration accepts a supported existing Workbench.');
|
||||
if (!before.token || !['0.1.0', '1.0.0', '1.1.0', '1.2.0', '1.3.0', '1.4.0', '1.5.0', '1.5.1', '1.6.0', '1.6.1', '1.6.2', '1.7.0', '1.8.0'].includes(before.version)) throw new Error('This migration accepts a supported existing 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;
|
||||
const breakpoints = [];
|
||||
|
||||
@@ -6,16 +6,17 @@ import { gitEnvironment } from '../src/core/git-process.mjs';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
const version = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
|
||||
assert.ok(['1.6.0', '1.6.1', '1.6.2', '1.7.0'].includes(version), 'Review evidence paths when introducing the next release.');
|
||||
const prefix = version === '1.6.0' ? 'workspaces' : version === '1.6.1' ? 'working-context' : version === '1.6.2' ? 'working-retention' : 'python-engine', resultFile = `.qa/${prefix}-all-ui-validation.json`, results = [];
|
||||
assert.ok(['1.6.0', '1.6.1', '1.6.2', '1.7.0', '1.8.0'].includes(version), 'Review evidence paths when introducing the next release.');
|
||||
const prefix = version === '1.6.0' ? 'workspaces' : version === '1.6.1' ? 'working-context' : version === '1.6.2' ? 'working-retention' : version === '1.7.0' ? 'python-engine' : 'rea-engine', resultFile = `.qa/${prefix}-all-ui-validation.json`, results = [];
|
||||
const cases = [
|
||||
['verify-ui.mjs', '.qa/ui-validation.json'], ['verify-diagnostics-ui.mjs', '.qa/diagnostics-ui-validation.json'],
|
||||
['verify-execution-ui.mjs', '.qa/execution-ui-validation.json'], ['verify-delivery-ui.mjs', '.qa/delivery-ui-validation.json'],
|
||||
['verify-index-ui.mjs', '.qa/index-ui-result.json'], ['verify-change-sets-ui.mjs', `docs/${prefix}-batch-ui-validation.json`],
|
||||
['verify-context-ui.mjs', `.qa/${version === '1.6.0' ? 'workspaces-context' : prefix}-ui-validation.json`],
|
||||
['verify-workspaces-ui.mjs', `docs/${prefix === 'workspaces' ? prefix : prefix + '-workspaces'}-ui-validation.json`],
|
||||
...(version === '1.7.0' ? [['verify-python-ui.mjs', 'docs/python-engine-python-ui-validation.json']] : []),
|
||||
...(version === '1.7.0' ? [['verify-react-delivery.mjs', 'docs/react-engine-delivery-validation.json']] : []),
|
||||
...(['1.7.0', '1.8.0'].includes(version) ? [['verify-python-ui.mjs', `docs/${prefix}-python-ui-validation.json`]] : []),
|
||||
...(['1.7.0', '1.8.0'].includes(version) ? [['verify-react-delivery.mjs', version === '1.7.0' ? 'docs/react-engine-delivery-validation.json' : 'docs/rea-engine-react-delivery-validation.json']] : []),
|
||||
...(version === '1.8.0' ? [['verify-research-ui.mjs', 'docs/rea-engine-research-ui-validation.json']] : []),
|
||||
];
|
||||
fs.mkdirSync('.qa', { recursive: true });
|
||||
const externalHost = new Set(['verify-ui.mjs', 'verify-diagnostics-ui.mjs', 'verify-execution-ui.mjs', 'verify-index-ui.mjs']);
|
||||
|
||||
@@ -33,8 +33,8 @@ child.stdout.on('data', value => { output += value; for (const line of output.sp
|
||||
child.stderr.on('data', value => { errors += value; });
|
||||
const wait = async predicate => { const deadline = Date.now() + 15000; while (!await predicate()) { if (Date.now() > deadline) throw new Error('UI fixture timed out: ' + errors); await new Promise(resolve => setTimeout(resolve, 40)); } };
|
||||
await wait(() => url); const bootstrap = await (await fetch(url + '/api/bootstrap')).json();
|
||||
assert.ok(['1.4.0', '1.5.0', '1.5.1', '1.6.0', '1.6.1', '1.6.2', '1.7.0'].includes(bootstrap.version)); assert.equal(bootstrap.config.mode, 'demo'); assert.equal(bootstrap.config.hasKey, false);
|
||||
const proofPrefix = bootstrap.version === '1.4.0' ? 'm2-batch' : bootstrap.version === '1.5.0' ? 'context-batch' : bootstrap.version === '1.5.1' ? 'context-fix-batch' : bootstrap.version === '1.6.0' ? 'workspaces-batch' : bootstrap.version === '1.6.1' ? 'working-context-batch' : bootstrap.version === '1.6.2' ? 'working-retention-batch' : 'python-engine-batch';
|
||||
assert.ok(['1.4.0', '1.5.0', '1.5.1', '1.6.0', '1.6.1', '1.6.2', '1.7.0', '1.8.0'].includes(bootstrap.version)); assert.equal(bootstrap.config.mode, 'demo'); assert.equal(bootstrap.config.hasKey, false);
|
||||
const proofPrefix = bootstrap.version === '1.4.0' ? 'm2-batch' : bootstrap.version === '1.5.0' ? 'context-batch' : bootstrap.version === '1.5.1' ? 'context-fix-batch' : bootstrap.version === '1.6.0' ? 'workspaces-batch' : bootstrap.version === '1.6.1' ? 'working-context-batch' : bootstrap.version === '1.6.2' ? 'working-retention-batch' : bootstrap.version === '1.7.0' ? 'python-engine-batch' : 'rea-engine-batch';
|
||||
const screenshotPrefix = bootstrap.version === '1.4.0' ? '1.4-batch' : proofPrefix;
|
||||
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, Connection: 'close' },
|
||||
...(input === undefined ? {} : { body: JSON.stringify(input) }) }); const value = await response.json(); assert.ok(response.ok, value.error); return value; };
|
||||
|
||||
@@ -76,9 +76,9 @@ child.stderr.on('data', bytes => { errors += bytes.toString('utf8'); });
|
||||
const until = async predicate => { const deadline = Date.now() + 20000; while (!await predicate()) { if (Date.now() > deadline) throw new Error('Context UI fixture timeout: ' + errors); await new Promise(resolve => setTimeout(resolve, 40)); } };
|
||||
await until(() => url || child.exitCode !== null); assert.ok(url, errors);
|
||||
const bootstrap = await (await fetch(url + '/api/bootstrap', { headers: { Connection: 'close' } })).json();
|
||||
assert.ok(['1.5.0', '1.5.1', '1.6.0', '1.6.1', '1.6.2', '1.7.0'].includes(bootstrap.version)); assert.equal(bootstrap.config.mode, 'demo'); assert.equal(bootstrap.config.hasKey, false);
|
||||
assert.ok(['1.5.0', '1.5.1', '1.6.0', '1.6.1', '1.6.2', '1.7.0', '1.8.0'].includes(bootstrap.version)); assert.equal(bootstrap.config.mode, 'demo'); assert.equal(bootstrap.config.hasKey, false);
|
||||
const api = async route => { const response = await fetch(url + '/api' + route, { headers: { 'X-Workbench-Token': bootstrap.token, Connection: 'close' } }); const value = await response.json(); assert.ok(response.ok, value.error); return value; };
|
||||
const proofPrefix = bootstrap.version === '1.5.0' ? 'context' : bootstrap.version === '1.5.1' ? 'context-fix' : bootstrap.version === '1.6.0' ? 'workspaces-context' : bootstrap.version === '1.6.1' ? 'working-context' : bootstrap.version === '1.6.2' ? 'working-retention' : 'python-engine';
|
||||
const proofPrefix = bootstrap.version === '1.5.0' ? 'context' : bootstrap.version === '1.5.1' ? 'context-fix' : bootstrap.version === '1.6.0' ? 'workspaces-context' : bootstrap.version === '1.6.1' ? 'working-context' : bootstrap.version === '1.6.2' ? 'working-retention' : bootstrap.version === '1.7.0' ? 'python-engine' : 'rea-engine';
|
||||
const browser = await chromium.launch({ channel: 'msedge', headless: true }), page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
const passed = [], pageErrors = [], requestFailures = [], screenshots = [];
|
||||
page.on('pageerror', error => pageErrors.push(error.message));
|
||||
@@ -151,6 +151,7 @@ try {
|
||||
await choose('paused'); await expect(page.locator('.run-stop')).toContainText('完整任务要求超过请求上下文预算');
|
||||
await expect(page.getByRole('button', { name: '继续任务', exact: true })).toBeVisible(); mark('context-limit pause explains the intact requirement and explicit continuation');
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await expect(page.getByLabel('当前项目', { exact: true })).toBeHidden();
|
||||
await choose('paused-repeat'); await expect(page.locator('.run-stop')).toContainText('重复读取未推进任务');
|
||||
await page.locator('.run-stop').scrollIntoViewIfNeeded();
|
||||
assert.equal(await page.evaluate(() => window.innerWidth), 390);
|
||||
|
||||
@@ -12,6 +12,7 @@ const protectedFiles = createPythonDeliveryProject(f), source = captureWorkspace
|
||||
f.session.title = 'Python工程检查与交付'; f.store.core.task.get(f.session.taskId).goal = '修复三个Python模块,保护测试与声明,核对实际检查并交付本地Git报告。';
|
||||
f.store.save(f.session); f.store.close();
|
||||
const host = await launchWorkbench(t, f.data, process.env.AGENT_WORKBENCH_TEST_PYTHON ? { AGENT_WORKBENCH_PYTHON_PATH: process.env.AGENT_WORKBENCH_TEST_PYTHON } : {});
|
||||
const proofPrefix = host.bootstrap.version === '1.8.0' ? 'rea-engine' : 'python-engine';
|
||||
assert.notEqual(new URL(host.url).port, '4318'); assert.equal(host.bootstrap.config.hasKey, false);
|
||||
fs.mkdirSync('.qa/screenshots', { recursive: true });
|
||||
const browser = await chromium.launch({ channel: 'msedge', headless: true }), page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
|
||||
@@ -21,7 +22,7 @@ page.on('requestfailed', request => requestFailures.push(request.url() + ': ' +
|
||||
const state = () => host.api(route), panel = () => page.getByLabel('任务记录', { exact: true });
|
||||
const artifact = () => page.getByRole('dialog', { name: '执行结果工件', exact: true });
|
||||
const mark = text => { passed.push(text); console.log('PASS ' + text); };
|
||||
const screenshot = name => page.screenshot({ path: '.qa/screenshots/python-engine-' + name + '.png', scale: 'css' });
|
||||
const screenshot = name => page.screenshot({ path: '.qa/screenshots/' + proofPrefix + '-python-' + name + '.png', scale: 'css' });
|
||||
const choose = (name, selected) => panel().getByLabel('启用检查 ' + name, { exact: true }).setChecked(selected);
|
||||
async function executeChecks() {
|
||||
await panel().getByRole('button', { name: '执行这些检查', exact: true }).click();
|
||||
@@ -119,7 +120,7 @@ try {
|
||||
const result = { success: true, version: host.bootstrap.version, at: new Date().toISOString(), browser: browser.version(), passed, pageErrors, requestFailures,
|
||||
checks: { before: failed.results[0].tests, after: session.execution.checks.at(-1).results[0].tests }, commit: job.commit,
|
||||
scope: 'Independent host and owned fixture. Real Python processes, reviewed API repairs and actual local Git. No configured model requests or production credentials.' };
|
||||
fs.writeFileSync('docs/python-engine-python-ui-validation.json', JSON.stringify(result, null, 2) + '\n'); console.log(JSON.stringify(result, null, 2));
|
||||
fs.writeFileSync('docs/' + proofPrefix + '-python-ui-validation.json', JSON.stringify(result, null, 2) + '\n'); console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
await screenshot('python-ui-failure').catch(() => {});
|
||||
fs.writeFileSync('.qa/python-ui-failure-dom.html', await page.content().catch(() => ''));
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
import { ResearchManager } from '../src/core/research-manager.mjs';
|
||||
import { Store } from '../src/server/store.mjs';
|
||||
import { APP_VERSION } from '../src/server/diagnostics.mjs';
|
||||
import { createResearchSamples } from './research-fixtures.mjs';
|
||||
|
||||
if (process.argv.includes('--help')) { console.log('node scripts/verify-rea.mjs [--app-root <source-or-release-directory>] [--contained]'); process.exit(0); }
|
||||
const rootIndex = process.argv.indexOf('--app-root');
|
||||
const appDirectory = path.resolve(rootIndex >= 0 ? process.argv[rootIndex + 1] : '.');
|
||||
const qaRoot = path.resolve('.qa'); fs.mkdirSync(qaRoot, { recursive: true });
|
||||
const directory = path.join(qaRoot, 'rea-integration-' + randomUUID()); fs.mkdirSync(directory);
|
||||
const projectRoot = path.join(directory, 'project'); fs.mkdirSync(projectRoot); fs.writeFileSync(path.join(projectRoot, 'README.md'), '# Owned REA fixture project\n');
|
||||
const samples = createResearchSamples(path.join(directory, 'samples')), store = new Store(path.join(directory, 'data'));
|
||||
const manager = new ResearchManager(store, { appDirectory });
|
||||
const results = []; let result;
|
||||
try {
|
||||
assert.equal(manager.availability().status, 'available', manager.availability().message);
|
||||
if (process.argv.includes('--contained')) assert.equal(manager.availability().packageRoot,
|
||||
fs.realpathSync.native(path.join(appDirectory, 'runtime/node_modules/rea-agents')), 'Release verification must use its contained REA installation.');
|
||||
const project = store.addProject(projectRoot), session = store.createSession(project.id);
|
||||
for (const [operation, file] of [['javascript', samples.asar], ['pe-imports', samples.pe], ['pe-resources', samples.pe]]) {
|
||||
const target = await manager.register(session, { path: file, label: '自有 ' + operation + ' 验收工件' });
|
||||
const { job, promise } = manager.start(session, target.id, operation); await promise;
|
||||
assert.equal(job.status, 'completed', job.summary); assert.equal(job.cleanup.rootExited, true);
|
||||
const evidence = manager.verifiedEvidence(session, job), text = JSON.stringify(evidence.normalized_result);
|
||||
assert.equal(evidence.subject.digest.sha256, target.sha256); assert.equal(job.evidenceId, evidence.evidence_id);
|
||||
if (operation === 'javascript') assert.equal(evidence.normalized_result.statistics.parsed_javascript_files, 2);
|
||||
if (operation === 'pe-imports') { assert.match(text, /KERNEL32\.dll/); assert.match(text, /ExitProcess/); }
|
||||
if (operation === 'pe-resources') assert.match(text, new RegExp(createHash('sha256').update('REA-DATA').digest('hex')));
|
||||
const trace = JSON.parse(store.artifactStore.read(store.owned('artifact', job.traceArtifactId, session.id)));
|
||||
assert.equal(trace.trace.filter(record => record.method === 'tools/call').length, 2, 'One analysis and one export; no repeated producer.');
|
||||
assert.ok(trace.trace.every(record => record.status === 'completed'));
|
||||
const reused = manager.start(session, target.id, operation); await reused.promise;
|
||||
assert.equal(reused.job.status, 'completed'); assert.equal(reused.job.reusedFromJobId, job.id); assert.equal(reused.job.traceArtifactId, undefined);
|
||||
results.push({ operation, targetSha256: target.sha256, bytes: target.bytes, evidenceId: job.evidenceId,
|
||||
originalOperation: evidence.operation, normalizedFields: Object.keys(evidence.normalized_result),
|
||||
bundleSha256: job.bundle.documentSha256, evidenceSha256: job.evidence.documentSha256, rawSha256: job.raw.documentSha256,
|
||||
advertisedTools: JSON.parse(store.artifactStore.read(store.core.artifact.get(job.contractArtifactId))).advertisedTools,
|
||||
cleanup: job.cleanup, reusedFromJobId: reused.job.reusedFromJobId, verification: 'actual-REA-6.8.0; owned inert artifacts' });
|
||||
}
|
||||
assert.equal(fs.existsSync(samples.marker), false, 'Target JavaScript must never execute.');
|
||||
assert.equal(store.core.task.get(session.taskId).usage.requests, 0);
|
||||
result = { success: true, version: APP_VERSION, testedAt: new Date().toISOString(), directory, appDirectory,
|
||||
installation: manager.availability(), taskId: session.taskId, sessionId: session.id, modelRequests: 0, targetExecution: false, results,
|
||||
credentialsHandling: 'No model connection, login state, key lookup or client MCP configuration changes.' };
|
||||
} catch (error) { result = { success: false, version: APP_VERSION, testedAt: new Date().toISOString(), directory, results, error: error.stack }; process.exitCode = 1; }
|
||||
finally { await manager.stopAll(); store.close(); }
|
||||
fs.writeFileSync(path.join(directory, 'result.json'), JSON.stringify(result, null, 2) + '\n');
|
||||
fs.writeFileSync(path.join(qaRoot, 'rea-integration-validation.json'), JSON.stringify(result, null, 2) + '\n');
|
||||
console.log(JSON.stringify({ success: result.success, version: result.version, directory, results: result.results.map(value => ({ operation: value.operation, evidenceId: value.evidenceId, targetSha256: value.targetSha256, advertisedTools: value.advertisedTools, rootExited: value.cleanup.rootExited })), error: result.error }));
|
||||
@@ -117,7 +117,7 @@ try {
|
||||
checks: actual.results.map(result => ({ name: result.name, status: result.status, exitCode: result.exitCode, tests: result.tests })),
|
||||
commit: job.commit, changes: job.paths, protectedFiles: Object.fromEntries(Object.entries(protectedBytes).map(([relative, bytes]) => [relative, sha(bytes)])),
|
||||
scope: 'Owned frozen React TypeScript project with offline-installed fixed dependencies, real npm/typecheck/build/browser and Workbench review/Git/report. API fixtures supply repairs; configured-model success is separate.' };
|
||||
fs.writeFileSync('docs/react-engine-delivery-validation.json', JSON.stringify(result, null, 2) + '\n'); console.log(JSON.stringify(result, null, 2));
|
||||
fs.writeFileSync(host.bootstrap.version === '1.8.0' ? 'docs/rea-engine-react-delivery-validation.json' : 'docs/react-engine-delivery-validation.json', JSON.stringify(result, null, 2) + '\n'); console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
await snapshot('failure').catch(() => {});
|
||||
fs.writeFileSync('.qa/react-engine-delivery-failure.json', JSON.stringify({ error: error.message, passed, pageErrors, requestFailures, session }, null, 2)); throw error;
|
||||
|
||||
@@ -4,6 +4,7 @@ import path from 'node:path';
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
import { spawn } from 'node:child_process';
|
||||
import net from 'node:net';
|
||||
import { createResearchSamples } from './research-fixtures.mjs';
|
||||
|
||||
const release = JSON.parse(fs.readFileSync('releases/latest.json', 'utf8'));
|
||||
const appRoot = release.portableRoot;
|
||||
@@ -45,8 +46,8 @@ function runPowerShell(script, extra = []) {
|
||||
const launch = () => runPowerShell('Start-Workbench.ps1', ['-NoBrowser']);
|
||||
const stop = () => runPowerShell('Stop-Workbench.ps1');
|
||||
const url = 'http://127.0.0.1:' + port;
|
||||
const until = async predicate => {
|
||||
const deadline = Date.now() + 10000;
|
||||
const until = async (predicate, timeoutMs = 10000) => {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
while (!(await predicate())) {
|
||||
if (Date.now() > deadline) throw new Error('Release state timeout');
|
||||
await new Promise(resolve => setTimeout(resolve, 50));
|
||||
@@ -62,7 +63,7 @@ try {
|
||||
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 },
|
||||
const response = await fetch(url + '/api' + route, { method: input === undefined ? 'GET' : 'POST', headers: { 'Content-Type': 'application/json', 'X-Workbench-Token': bootstrap.token, Connection: 'close' },
|
||||
...(input === undefined ? {} : { body: JSON.stringify(input) }) });
|
||||
const result = await response.json(); assert.ok(response.ok, result.error); return result;
|
||||
};
|
||||
@@ -89,13 +90,46 @@ try {
|
||||
assert.equal(checked.status, 'passed'); assert.equal(checked.results[0].tests.total, 4); assert.equal(checked.results[0].tests.passed, 4);
|
||||
const checkLog = await api('/artifacts/' + checked.results[0].logArtifactId + '?session=' + session.id); assert.match(checkLog.content, /tests 4/);
|
||||
assert.ok(fs.existsSync(path.join(appRoot, 'runtime/node_modules/npm/bin/npm-cli.js')));
|
||||
const actualRea = [];
|
||||
if (manifest.version === '1.8.0') {
|
||||
const installation = await api('/research/availability'); assert.equal(installation.status, 'available'); assert.equal(installation.version, '6.8.0');
|
||||
assert.equal(fs.realpathSync.native(installation.packageRoot), fs.realpathSync.native(path.join(appRoot, 'runtime/node_modules/rea-agents')));
|
||||
assert.equal(fs.realpathSync.native(installation.node.path), fs.realpathSync.native(path.join(appRoot, 'runtime/node.exe')));
|
||||
const runtimeManifest = JSON.parse(fs.readFileSync(path.join(appRoot, 'runtime/REA-RUNTIME.json'), 'utf8'));
|
||||
assert.equal(runtimeManifest.version, '6.8.0'); assert.equal(runtimeManifest.protocolVersion, '2025-03-26');
|
||||
assert.equal(createHash('sha256').update(fs.readFileSync(path.join(appRoot, 'runtime', runtimeManifest.installationLock.path))).digest('hex'), runtimeManifest.installationLock.sha256);
|
||||
const projectRoot = path.join(data, 'research-project'); fs.mkdirSync(projectRoot); fs.writeFileSync(path.join(projectRoot, 'README.md'), '# Owned portable REA project\n');
|
||||
const samples = createResearchSamples(path.join(data, 'research-samples')), researchProject = await api('/projects', { root: projectRoot });
|
||||
const researchSession = await api('/sessions', { projectId: researchProject.id }), researchRoute = '/sessions/' + researchSession.id;
|
||||
for (const [operation, filename] of [['javascript', samples.asar], ['pe-imports', samples.pe], ['pe-resources', samples.pe]]) {
|
||||
const registered = await api(researchRoute + '/research/targets', { path: filename, label: 'Owned portable ' + operation });
|
||||
const target = registered.target, startedJob = await api(researchRoute + '/research/jobs', { targetId: target.id, operation });
|
||||
let job; await until(async () => { job = await api(researchRoute + '/research/jobs/' + startedJob.job.id); return !!job.finishedAt; }, 45000);
|
||||
assert.equal(job.status, 'completed', job.summary); assert.equal(job.cleanup.rootExited, true);
|
||||
const response = await fetch(url + '/api' + researchRoute + '/research/jobs/' + job.id + '/download?kind=bundle', { headers: { 'X-Workbench-Token': bootstrap.token, Connection: 'close' } });
|
||||
assert.equal(response.status, 200); const bytes = Buffer.from(await response.arrayBuffer());
|
||||
assert.equal(createHash('sha256').update(bytes).digest('hex'), job.bundle.documentSha256);
|
||||
const evidence = JSON.parse(bytes.toString('utf8')).records.find(record => record.evidence_id === job.evidenceId);
|
||||
assert.equal(evidence.subject.digest.sha256, target.sha256);
|
||||
if (operation === 'javascript') assert.equal(evidence.normalized_result.statistics.parsed_javascript_files, 2);
|
||||
if (operation === 'pe-imports') { assert.match(JSON.stringify(evidence.normalized_result), /KERNEL32\.dll/); assert.match(JSON.stringify(evidence.normalized_result), /ExitProcess/); }
|
||||
if (operation === 'pe-resources') assert.match(JSON.stringify(evidence.normalized_result), new RegExp(createHash('sha256').update('REA-DATA').digest('hex')));
|
||||
const reused = await api(researchRoute + '/research/jobs', { targetId: target.id, operation });
|
||||
let reuseJob; await until(async () => { reuseJob = await api(researchRoute + '/research/jobs/' + reused.job.id); return !!reuseJob.finishedAt; });
|
||||
assert.equal(reuseJob.reusedFromJobId, job.id); assert.equal(reuseJob.traceArtifactId, undefined);
|
||||
actualRea.push({ operation, jobId: job.id, evidenceId: job.evidenceId, targetSha256: target.sha256, bundleSha256: job.bundle.documentSha256, rootExited: true, reusedJobId: reuseJob.id });
|
||||
}
|
||||
assert.equal((await api(researchRoute)).execution.task.usage.requests, 0); assert.equal(fs.existsSync(samples.marker), false);
|
||||
console.log('PASS actual contained REA: ASAR, PE imports and PE resources; zero target execution/model requests');
|
||||
}
|
||||
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, checks: { jobId, status: checked.status, tests: checked.results[0].tests }, steps: ['manifest hashes', 'bundled Node launch', 'same-service reuse', 'packaged example and static page', 'explicit command consent', 'actual bundled Node version', 'actual bundled npm check without system Node/npm', 'check log artifact', 'report availability', 'graceful stop'], realModel: false };
|
||||
verifiedFiles: manifest.files.length, url, reusedPid: firstInfo.pid, checks: { jobId, status: checked.status, tests: checked.results[0].tests }, actualRea,
|
||||
steps: ['manifest hashes', 'bundled Node launch', 'same-service reuse', 'packaged example and static page', 'explicit command consent', 'actual bundled Node version', 'actual bundled npm check without system Node/npm', 'check log artifact', ...(actualRea.length ? ['contained REA installation and Node identity', 'actual ASAR/imports/resources', 'original Bundle and target hash binding', 'verified reuse without producer replay'] : []), '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,180 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
import { chromium, expect } from 'playwright/test';
|
||||
import { Store } from '../src/server/store.mjs';
|
||||
import { launchWorkbench } from '../tests/helpers.mjs';
|
||||
import { createResearchSamples, ownedAsar } from './research-fixtures.mjs';
|
||||
|
||||
if (process.argv.includes('--help')) { console.log('node scripts/verify-research-ui.mjs — independent owned projects, real REA static operations and a declared stdio stop fixture'); process.exit(0); }
|
||||
const root = path.resolve('.qa', 'research-ui-' + randomUUID()), data = path.join(root, 'data'), projectRoot = path.join(root, 'project');
|
||||
fs.mkdirSync(projectRoot, { recursive: true }); fs.mkdirSync('.qa/screenshots', { recursive: true });
|
||||
const projectBytes = Buffer.from('# Owned REA UI project\n'); fs.writeFileSync(path.join(projectRoot, 'README.md'), projectBytes);
|
||||
const store = new Store(data), project = store.addProject(projectRoot), original = store.createSession(project.id);
|
||||
original.title = 'REA工件与原证据验收'; store.save(original); store.close();
|
||||
const samples = createResearchSamples(path.join(root, 'samples')), disposers = [], t = { after: fn => disposers.push(fn) };
|
||||
let host = await launchWorkbench(t, data), route = '/sessions/' + original.id, deliberateNavigation = false;
|
||||
const browser = await chromium.launch({ channel: 'msedge', headless: true }), page = await browser.newPage({ viewport: { width: 1440, height: 1050 } });
|
||||
const passed = [], pageErrors = [], requestFailures = [], expectedRequestFailures = [], screenshots = [], analysisRequests = [];
|
||||
const sha = bytes => createHash('sha256').update(bytes).digest('hex'), state = () => host.api(route);
|
||||
const panel = () => page.getByRole('dialog', { name: 'REA 工件研究', exact: true });
|
||||
const view = () => page.getByRole('dialog', { name: '原 Evidence 字段', exact: true });
|
||||
const jobCard = job => panel().locator('[data-research-job="' + job.id + '"]');
|
||||
const mark = text => { passed.push(text); console.log('PASS ' + text); };
|
||||
page.on('pageerror', error => pageErrors.push(error.message));
|
||||
page.on('requestfailed', request => {
|
||||
const failure = { url: request.url(), error: request.failure()?.errorText };
|
||||
(deliberateNavigation && failure.error?.includes('ERR_ABORTED') ? expectedRequestFailures : requestFailures).push(failure);
|
||||
});
|
||||
page.on('request', request => { if (request.method() === 'POST' && request.url().endsWith('/research/jobs')) analysisRequests.push({ url: request.url(), input: request.postDataJSON() }); });
|
||||
async function screenshot(name) { const filename = '.qa/screenshots/rea-engine-' + name + '.png'; await page.screenshot({ path: filename, scale: 'css' }); screenshots.push(filename); }
|
||||
async function openProject(projectId = project.id, title = original.title) {
|
||||
await page.goto(host.url); await page.waitForLoadState('networkidle');
|
||||
await page.getByLabel('当前项目').selectOption(projectId); await page.locator('.session-list button').filter({ hasText: title }).click();
|
||||
await page.getByRole('button', { name: 'REA 工件研究', exact: true }).click(); await expect(panel()).toBeVisible();
|
||||
}
|
||||
async function register(filename, label) {
|
||||
const before = (await state()).execution.researchTargets.length;
|
||||
await panel().getByLabel('REA工件路径').fill(filename); await panel().getByLabel('REA工件名称').fill(label);
|
||||
await panel().getByRole('button', { name: '登记工件', exact: true }).click();
|
||||
await expect.poll(async () => (await state()).execution.researchTargets.length).toBe(before + 1);
|
||||
const target = (await state()).execution.researchTargets.at(-1); await expect(panel().locator('.rea-target').filter({ hasText: label })).toBeVisible(); return target;
|
||||
}
|
||||
async function analyze(target, operation) {
|
||||
const before = (await state()).execution.researchJobs.length, card = panel().locator('.rea-target').filter({ hasText: target.label });
|
||||
await card.getByRole('combobox').selectOption(operation); await card.getByRole('button', { name: '分析', exact: true }).click();
|
||||
await expect.poll(async () => (await state()).execution.researchJobs.length).toBe(before + 1);
|
||||
await expect.poll(async () => (await state()).execution.researchJobs.at(-1).finishedAt, { timeout: 45000 }).toBeTruthy();
|
||||
const job = (await state()).execution.researchJobs.at(-1); await expect(jobCard(job)).toContainText(job.status === 'completed' ? '原证据已核验' : '工件版本变化'); return job;
|
||||
}
|
||||
async function downloaded(job) {
|
||||
const pending = page.waitForEvent('download'); await jobCard(job).getByRole('button', { name: '完整证据', exact: true }).click();
|
||||
const download = await pending, filename = path.join(root, job.id + '-bundle.json'); await download.saveAs(filename);
|
||||
const bytes = fs.readFileSync(filename); assert.equal(sha(bytes), job.bundle.documentSha256);
|
||||
const bundle = JSON.parse(bytes.toString('utf8')), evidence = bundle.records.find(value => value.evidence_id === job.evidenceId);
|
||||
assert.equal(evidence.subject.digest.sha256, job.targetSha256); return evidence;
|
||||
}
|
||||
let result;
|
||||
try {
|
||||
assert.notEqual(new URL(host.url).port, '4318'); assert.equal(host.bootstrap.config.hasKey, false);
|
||||
await openProject(); await expect(panel()).toContainText('已找到 REA 6.8.0');
|
||||
mark('independent desktop research entry detects the installed fixed REA version');
|
||||
const target = await register(samples.asar, '自有 Electron 代理工件');
|
||||
assert.equal(target.sha256, sha(fs.readFileSync(samples.asar))); assert.equal((await state()).execution.task.usage.requests, 0);
|
||||
assert.equal(target.sessionId, original.id); assert.equal(target.projectId, project.id);
|
||||
mark('UI registration seals the artifact identity in the current project and creates no model request');
|
||||
const first = await analyze(target, 'javascript'); assert.equal(first.status, 'completed'); assert.equal(first.cleanup.rootExited, true);
|
||||
await expect(jobCard(first).getByLabel('已核验原证据来源')).toContainText(target.sha256.slice(0, 12));
|
||||
const firstEvidence = await downloaded(first); assert.equal(firstEvidence.normalized_result.statistics.parsed_javascript_files, 2);
|
||||
mark('actual REA ASAR analysis renders the verified source chain and downloads the exact original Bundle');
|
||||
await jobCard(first).getByRole('button', { name: '查看原字段', exact: true }).click(); await expect(view()).toBeVisible();
|
||||
await view().getByRole('button', { name: 'statistics', exact: true }).click();
|
||||
await expect(view().locator('.rea-pointer > code')).toHaveText('/normalized_result/statistics');
|
||||
await expect.poll(async () => JSON.parse(await view().getByLabel('原Evidence内容').innerText()).parsed_javascript_files).toBe(2);
|
||||
await page.keyboard.press('Escape'); await expect(view()).toHaveCount(0); await expect(panel()).toBeVisible();
|
||||
await jobCard(first).getByRole('button', { name: '查看原字段', exact: true }).click(); await expect(view()).toBeVisible();
|
||||
const firstPage = await host.api(route + '/research/jobs/' + first.id + '/evidence?offset=0&limit=4000');
|
||||
assert.equal(await view().getByLabel('原Evidence内容').innerText(), firstPage.content);
|
||||
if (firstPage.truncated) {
|
||||
await view().getByRole('button', { name: '下一页', exact: true }).click();
|
||||
const secondPage = await host.api(route + '/research/jobs/' + first.id + '/evidence?offset=' + firstPage.next_offset + '&limit=4000');
|
||||
await expect(view().getByLabel('原Evidence内容')).toHaveText(secondPage.content);
|
||||
await view().getByRole('button', { name: '回到首页', exact: true }).click(); await expect(view().getByLabel('原Evidence内容')).toHaveText(firstPage.content);
|
||||
}
|
||||
await view().getByRole('button', { name: '关闭窗口', exact: true }).click();
|
||||
await jobCard(first).getByRole('button', { name: '原限制', exact: true }).click();
|
||||
await expect(view().locator('.rea-pointer > code')).toHaveText('/limitations');
|
||||
await expect.poll(async () => JSON.parse(await view().getByLabel('原Evidence内容').innerText())).toEqual(firstEvidence.limitations ?? []);
|
||||
await view().getByRole('button', { name: '关闭窗口', exact: true }).click();
|
||||
mark('original field selection, paging and limitations retain exact bytes; Escape closes only the top dialog');
|
||||
for (const [name, title] of [['原响应', 'REA 原响应'], ['连接记录', 'REA 连接记录']]) {
|
||||
await jobCard(first).getByRole('button', { name, exact: true }).click();
|
||||
const dialog = page.getByRole('dialog', { name: title, exact: true }); await expect(dialog).toBeVisible();
|
||||
await expect(dialog.locator('pre')).not.toHaveText(''); await dialog.getByRole('button', { name: '关闭窗口', exact: true }).click();
|
||||
}
|
||||
const reused = await analyze(target, 'javascript'); assert.equal(reused.reusedFromJobId, first.id); assert.equal(reused.traceArtifactId, undefined);
|
||||
await expect(jobCard(reused)).toContainText('本次没有再次调用 REA'); await downloaded(reused);
|
||||
mark('raw responses and connection records are readable; repeat analysis reuses the verified original without dispatch');
|
||||
const pe = await register(samples.pe, '自有 PE 导入与资源工件');
|
||||
const imports = await analyze(pe, 'pe-imports'), importsEvidence = await downloaded(imports);
|
||||
assert.match(JSON.stringify(importsEvidence.normalized_result), /KERNEL32\.dll/); assert.match(JSON.stringify(importsEvidence.normalized_result), /ExitProcess/);
|
||||
const resources = await analyze(pe, 'pe-resources'), resourceEvidence = await downloaded(resources);
|
||||
assert.match(JSON.stringify(resourceEvidence.normalized_result), new RegExp(sha(Buffer.from('REA-DATA'))));
|
||||
assert.equal(imports.cleanup.rootExited, true); assert.equal(resources.cleanup.rootExited, true);
|
||||
await screenshot('research-desktop');
|
||||
mark('UI PE operation selection performs actual import and resource analysis with independently verified target hashes');
|
||||
fs.writeFileSync(samples.asar, ownedAsar({ 'package.json': '{"name":"owned-new-version","main":"main.js"}', 'main.js': 'exports.contract = { observed: "new static version" };' }));
|
||||
const stale = await analyze(target, 'javascript'); assert.equal(stale.status, 'stale'); assert.equal(stale.analysisDispatched, undefined);
|
||||
await expect(jobCard(stale).getByLabel('已核验原证据来源')).toHaveCount(0);
|
||||
await jobCard(stale).getByRole('button', { name: '重新分析', exact: true }).click();
|
||||
const retry = page.getByRole('dialog', { name: '重新运行静态分析', exact: true }); await expect(retry).toBeVisible();
|
||||
await retry.getByRole('button', { name: '返回原记录', exact: true }).click();
|
||||
const updated = await register(samples.asar, '自有代理新版本'); assert.notEqual(updated.sha256, target.sha256);
|
||||
const updatedJob = await analyze(updated, 'javascript'); assert.equal(updatedJob.status, 'completed');
|
||||
assert.ok((await state()).execution.researchJobs.some(value => value.id === stale.id && value.status === 'stale'));
|
||||
mark('changed artifact versions refuse dispatch, retain the stale record and require a separately registered version');
|
||||
await page.setViewportSize({ width: 390, height: 844 }); await jobCard(updatedJob).scrollIntoViewIfNeeded();
|
||||
assert.equal(await panel().evaluate(element => element.scrollWidth <= element.clientWidth), true); await screenshot('research-mobile');
|
||||
await jobCard(updatedJob).getByRole('button', { name: '查看原字段', exact: true }).click(); await expect(view()).toBeVisible();
|
||||
assert.equal(await view().evaluate(element => element.scrollWidth <= element.clientWidth), true); await screenshot('research-evidence-mobile');
|
||||
await page.keyboard.press('Escape'); await expect(panel()).toBeVisible();
|
||||
mark('390px research, long identities and original evidence dialogs fit the viewport and retain usable close controls');
|
||||
const recordBeforeRestart = (await state()).execution.researchJobs.map(value => ({ id: value.id, status: value.status, evidenceId: value.evidenceId }));
|
||||
deliberateNavigation = true; await page.goto('about:blank'); await host.close();
|
||||
host = await launchWorkbench(t, data); await page.setViewportSize({ width: 1440, height: 1050 }); await openProject(); deliberateNavigation = false;
|
||||
assert.deepEqual((await state()).execution.researchJobs.map(value => ({ id: value.id, status: value.status, evidenceId: value.evidenceId })), recordBeforeRestart);
|
||||
await expect(jobCard(updatedJob)).toContainText('原证据已核验'); await downloaded(updatedJob);
|
||||
mark('a real host restart preserves exact target/job identities and serves sealed Evidence without producer replay');
|
||||
let releaseView; const gate = new Promise(resolve => { releaseView = resolve; });
|
||||
await page.route('**/research/jobs/' + updatedJob.id + '/evidence?*', async intercepted => {
|
||||
const response = await intercepted.fetch(); await gate; await intercepted.fulfill({ response });
|
||||
});
|
||||
await jobCard(updatedJob).getByRole('button', { name: '查看原字段', exact: true }).click();
|
||||
await panel().getByRole('button', { name: '关闭窗口', exact: true }).click(); releaseView();
|
||||
await page.unrouteAll({ behavior: 'wait' }); await expect(view()).toHaveCount(0); await expect(panel()).toHaveCount(0);
|
||||
mark('a delayed evidence response cannot reopen a closed research panel or change another task');
|
||||
assert.deepEqual(fs.readFileSync(path.join(projectRoot, 'README.md')), projectBytes); assert.equal(fs.existsSync(samples.marker), false);
|
||||
assert.equal((await state()).execution.task.usage.requests, 0);
|
||||
|
||||
// Declared fault fixture: no claim that this second MCP process is the actual REA implementation.
|
||||
const faultRoot = path.join(root, 'stdio-stop-fixture'); fs.mkdirSync(path.join(faultRoot, 'scripts'), { recursive: true });
|
||||
fs.writeFileSync(path.join(faultRoot, 'package.json'), '{"name":"rea-agents","version":"6.8.0","type":"module"}');
|
||||
fs.writeFileSync(path.join(faultRoot, 'scripts/rea.mjs'), 'import readline from "node:readline"; readline.createInterface({input:process.stdin}).on("line",()=>{});');
|
||||
const faultData = path.join(root, 'fault-data'), faultStore = new Store(faultData), faultProject = faultStore.addProject(projectRoot), faultSession = faultStore.createSession(faultProject.id);
|
||||
faultSession.title = '声明的stdio停止故障验收'; faultStore.save(faultSession); faultStore.close();
|
||||
deliberateNavigation = true; await page.goto('about:blank'); await host.close();
|
||||
host = await launchWorkbench(t, faultData, { AGENT_WORKBENCH_REA_PACKAGE_ROOT: faultRoot }); route = '/sessions/' + faultSession.id;
|
||||
await openProject(faultProject.id, faultSession.title); deliberateNavigation = false;
|
||||
const faultTarget = await register(samples.asar, '停止握手的自有工件'), before = (await state()).execution.researchJobs.length;
|
||||
await panel().locator('.rea-target').filter({ hasText: faultTarget.label }).getByRole('button', { name: '分析', exact: true }).click();
|
||||
await expect.poll(async () => (await state()).execution.researchJobs.at(-1)?.connection?.pid).toBeTruthy();
|
||||
await expect(panel().getByRole('button', { name: '停止分析', exact: true })).toBeEnabled();
|
||||
await panel().getByRole('button', { name: '停止分析', exact: true }).click();
|
||||
await expect.poll(async () => (await state()).execution.researchJobs.at(-1)?.status).toBe('cancelled');
|
||||
await expect.poll(async () => (await state()).execution.researchJobs.at(-1)?.finishedAt).toBeTruthy();
|
||||
const stopped = (await state()).execution.researchJobs.at(-1); assert.equal(stopped.cleanup.rootExited, true);
|
||||
await expect(jobCard(stopped)).toContainText('已停止'); await jobCard(stopped).getByRole('button', { name: '重新分析', exact: true }).click();
|
||||
await page.getByRole('dialog', { name: '重新运行静态分析', exact: true }).getByRole('button', { name: '确认重新分析', exact: true }).click();
|
||||
await expect.poll(async () => (await state()).execution.researchJobs.length).toBe(before + 2);
|
||||
await expect.poll(async () => (await state()).execution.researchJobs.at(-1)?.connection?.pid).toBeTruthy();
|
||||
await expect(panel().getByRole('button', { name: '停止分析', exact: true })).toBeEnabled(); await panel().getByRole('button', { name: '停止分析', exact: true }).click();
|
||||
await expect.poll(async () => (await state()).execution.researchJobs.at(-1).status).toBe('cancelled');
|
||||
await expect.poll(async () => (await state()).execution.researchJobs.at(-1)?.finishedAt).toBeTruthy();
|
||||
assert.equal((await state()).execution.researchJobs.find(value => value.id === stopped.id).status, 'cancelled');
|
||||
assert.equal((await state()).execution.task.usage.requests, 0); await screenshot('research-stop-desktop');
|
||||
mark('declared owned stdio fault fixture stops its root process and explicit retry adds a new record without changing history');
|
||||
assert.equal(pageErrors.length, 0); assert.equal(requestFailures.length, 0);
|
||||
result = { success: true, version: host.bootstrap.version, at: new Date().toISOString(), browser: browser.version(), passed, pageErrors, requestFailures, expectedRequestFailures,
|
||||
root, actualRea: { version: '6.8.0', operations: ['javascript', 'pe-imports', 'pe-resources'], jobs: recordBeforeRestart, targetExecution: false, modelRequests: 0 },
|
||||
stopScope: 'explicitly declared private stdio handshake fault fixture', screenshots, analysisRequests,
|
||||
scope: 'Independent ports/data and self-owned inert artifacts. No production service, configured-model request or real key read/copied.' };
|
||||
} catch (error) {
|
||||
await screenshot('research-ui-failure').catch(() => {}); fs.writeFileSync(path.join(root, 'failure-dom.html'), await page.content().catch(() => ''));
|
||||
result = { success: false, version: host.bootstrap.version, at: new Date().toISOString(), error: error.stack, root, passed, pageErrors, requestFailures, expectedRequestFailures, screenshots }; process.exitCode = 1;
|
||||
} finally {
|
||||
deliberateNavigation = true; await browser.close(); for (const dispose of disposers.reverse()) await dispose();
|
||||
}
|
||||
fs.writeFileSync(path.join(root, 'result.json'), JSON.stringify(result, null, 2) + '\n');
|
||||
fs.writeFileSync('docs/rea-engine-research-ui-validation.json', JSON.stringify(result, null, 2) + '\n');
|
||||
console.log(JSON.stringify({ success: result.success, version: result.version, groups: passed.length, root, pageErrors, requestFailures, error: result.error }, null, 2));
|
||||
@@ -41,12 +41,20 @@ try {
|
||||
const actualFiles = ['dist-client', 'dist-server'].flatMap(folder => files(path.join(sourceRoot, folder)).map(relative => path.join(folder, relative)));
|
||||
assert.deepEqual(actualFiles.slice().sort(), Object.keys(expected).sort());
|
||||
for (const [relative, sha256] of Object.entries(expected)) assert.equal(digest(path.join(sourceRoot, relative)), sha256, relative);
|
||||
let actualRea = null;
|
||||
if (evidence.version === '1.8.0') {
|
||||
stage = 'contained REA';
|
||||
const reaOutput = await run(['scripts/verify-rea.mjs', '--app-root', sourceRoot, '--contained'], 'rea.log');
|
||||
actualRea = JSON.parse(reaOutput.trim().split('\n').at(-1));
|
||||
assert.equal(actualRea.success, true); assert.equal(actualRea.version, evidence.version); assert.equal(actualRea.results.length, 3);
|
||||
assert.ok(actualRea.results.every(item => item.rootExited === true));
|
||||
}
|
||||
stage = 'tests';
|
||||
const output = await run(['--test', '--test-concurrency=2', '--test-reporter=tap', ...files(path.join(sourceRoot, 'tests')).filter(file => !file.includes(path.sep) && file.endsWith('.test.mjs')).map(file => path.join('tests', file))], 'tests.tap');
|
||||
const stats = Object.fromEntries([...output.matchAll(/^# (tests|pass|fail|cancelled|skipped|todo) (\d+)\s*$/gm)].map(match => [match[1], Number(match[2])]));
|
||||
assert.ok(stats.tests > 0); assert.equal(stats.pass, stats.tests); for (const key of ['fail', 'cancelled', 'skipped', 'todo']) assert.equal(stats[key], 0);
|
||||
const result = { success: true, version: evidence.version, testedAt: new Date().toISOString(), sourceRoot, offlineInstall: true,
|
||||
buildMatchedFiles: Object.keys(expected).length, tests: stats, credentialsHandling: 'Only build/runtime environment paths are inherited; no model configuration or credentials are used.' };
|
||||
buildMatchedFiles: Object.keys(expected).length, tests: stats, actualRea, credentialsHandling: 'Only build/runtime environment paths are inherited; no model configuration or credentials are used.' };
|
||||
fs.writeFileSync(resultFile, JSON.stringify(result, null, 2)); console.log(JSON.stringify(result, null, 2));
|
||||
} catch (error) {
|
||||
fs.writeFileSync(resultFile, JSON.stringify({ success: false, version: evidence.version, stage, error: error.message, sourceRoot }, null, 2));
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createHash, randomUUID } from 'node:crypto';
|
||||
import { spawn } from 'node:child_process';
|
||||
|
||||
if (process.argv.includes('--help')) { console.log('node scripts/verify-tests.mjs — complete regression with frozen input/log hashes'); process.exit(0); }
|
||||
const root = process.cwd(), version = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
|
||||
const directory = path.resolve('.qa', 'tests-' + version + '-' + randomUUID()); fs.mkdirSync(directory, { recursive: true });
|
||||
const hash = filename => createHash('sha256').update(fs.readFileSync(filename)).digest('hex');
|
||||
function filesIn(relative) {
|
||||
return fs.readdirSync(path.join(root, relative), { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name)).flatMap(entry => {
|
||||
const filename = path.join(relative, entry.name); if (entry.isSymbolicLink()) throw new Error('Regression input cannot be a link: ' + filename);
|
||||
return entry.isDirectory() ? filesIn(filename) : [filename];
|
||||
});
|
||||
}
|
||||
const paths = ['src', 'tests', 'scripts'].flatMap(filesIn).concat(['package.json', 'package-lock.json', 'vite.config.ts', 'tsconfig.json', 'index.html']).sort();
|
||||
const snapshot = () => paths.map(filename => ({ path: filename.replaceAll('\\', '/'), bytes: fs.statSync(filename).size, sha256: hash(filename) }));
|
||||
const inputs = snapshot(), tests = fs.readdirSync('tests').filter(name => name.endsWith('.test.mjs')).sort().map(name => path.join('tests', name));
|
||||
assert.ok(tests.length); fs.writeFileSync(path.join(directory, 'inputs.json'), JSON.stringify(inputs, null, 2) + '\n');
|
||||
const allowed = /^(path|pathext|systemroot|systemdrive|windir|comspec|temp|tmp|userprofile|homedrive|homepath|home|appdata|localappdata|programfiles(?:\(x86\))?|commonprogramfiles(?:\(x86\))?|lang|lc_all|AGENT_WORKBENCH_TEST_PYTHON)$/i;
|
||||
const env = Object.fromEntries(Object.entries(process.env).filter(([name]) => allowed.test(name)));
|
||||
const logPath = path.join(directory, 'tests.tap'), output = fs.createWriteStream(logPath), startedAt = new Date().toISOString(); let result, failure;
|
||||
try {
|
||||
await new Promise((resolve, reject) => {
|
||||
const child = spawn(process.execPath, ['--test', '--test-concurrency=2', '--test-reporter=tap', ...tests], { cwd: root, env, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
||||
child.stdout.pipe(output, { end: false }); child.stderr.pipe(output, { end: false });
|
||||
const timer = setTimeout(() => child.kill(), 600000);
|
||||
child.once('error', error => { clearTimeout(timer); reject(error); });
|
||||
child.once('close', code => { clearTimeout(timer); code === 0 ? resolve() : reject(new Error('Regression process exit: ' + code)); });
|
||||
});
|
||||
} catch (error) { failure = error; }
|
||||
await new Promise(resolve => output.end(resolve));
|
||||
try {
|
||||
const text = fs.readFileSync(logPath, 'utf8'), stats = Object.fromEntries([...text.matchAll(/^# (tests|pass|fail|cancelled|skipped|todo) (\d+)\s*$/gm)].map(match => [match[1], Number(match[2])]));
|
||||
if (failure) throw Object.assign(failure, { tail: text.slice(-16000) });
|
||||
assert.ok(stats.tests > 0); assert.equal(stats.pass, stats.tests); for (const key of ['fail', 'cancelled', 'skipped', 'todo']) assert.equal(stats[key], 0);
|
||||
assert.deepEqual(snapshot(), inputs, 'Inputs changed during regression; this is not final-source evidence.');
|
||||
result = { success: true, version, startedAt, finishedAt: new Date().toISOString(), tests: stats, directory, nodeVersion: process.version, inputFiles: inputs.length, inputs,
|
||||
log: { path: logPath, bytes: fs.statSync(logPath).size, sha256: hash(logPath) }, credentialsHandling: 'Only runtime/system paths and the independent QA Python path are inherited; no real model configuration or credentials.' };
|
||||
} catch (error) {
|
||||
result = { success: false, version, startedAt, finishedAt: new Date().toISOString(), directory, error: error.stack, tail: error.tail, inputs, log: { path: logPath, sha256: hash(logPath) } }; process.exitCode = 1;
|
||||
}
|
||||
fs.writeFileSync(path.join(directory, 'result.json'), JSON.stringify(result, null, 2) + '\n'); fs.writeFileSync('.qa/tests-validation.json', JSON.stringify(result, null, 2) + '\n');
|
||||
if (version === '1.8.0') fs.writeFileSync('docs/rea-engine-tests-validation.json', JSON.stringify(result, null, 2) + '\n');
|
||||
console.log(JSON.stringify({ success: result.success, version, tests: result.tests, inputFiles: result.inputFiles, directory, error: result.error, tail: result.tail }, null, 2));
|
||||
@@ -12,7 +12,7 @@ import { captureWorkspaceSource, assertWorkspaceSource } from '../tests/fixtures
|
||||
// Every host/project is synthetic and independently owned. Never uses 4318.
|
||||
const root = path.resolve('.qa', 'workspace-ui-' + randomUUID()), data = path.join(root, 'data');
|
||||
const version = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
|
||||
const proofPrefix = version === '1.6.0' ? 'workspaces' : version === '1.6.1' ? 'working-context-workspaces' : version === '1.6.2' ? 'working-retention-workspaces' : 'python-engine-workspaces';
|
||||
const proofPrefix = version === '1.6.0' ? 'workspaces' : version === '1.6.1' ? 'working-context-workspaces' : version === '1.6.2' ? 'working-retention-workspaces' : version === '1.7.0' ? 'python-engine-workspaces' : 'rea-engine-workspaces';
|
||||
fs.mkdirSync(root, { recursive: true }); fs.mkdirSync('.qa/screenshots', { recursive: true });
|
||||
const store = new Store(data), cases = {}, passed = [], pageErrors = [], requestFailures = [], screenshots = [], createPosts = [];
|
||||
for (const name of ['normal', 'mobile', 'recovery', 'late-success', 'late-failure']) {
|
||||
|
||||
Reference in New Issue
Block a user