test(release): validate contained companion runtime and mobile inputs

This commit is contained in:
Agent Workbench Dev
2026-10-31 19:02:17 +08:00
parent 73aa717c89
commit 0cc8b4c170
7 changed files with 38 additions and 12 deletions
+12 -5
View File
@@ -2,19 +2,25 @@ import fs from 'node:fs';
import path from 'node:path';
import http from 'node:http';
import https from 'node:https';
import { X509Certificate, randomUUID } from 'node:crypto';
import { X509Certificate, randomUUID, createHash } from 'node:crypto';
import assert from 'node:assert/strict';
import { chromium, expect } from 'playwright/test';
import { fixture, launchWorkbench, until } from '../tests/helpers.mjs';
if (process.argv.includes('--help')) { console.log('node scripts/verify-companion-ui.mjs - isolated desktop and mobile UI via a loopback QA relay that verifies the actual gateway CA; does not modify certificate trust or substitute for iPhone Safari acceptance.'); process.exit(0); }
if (process.argv.length > 2) throw new Error('Unsupported arguments.');
if (process.argv.includes('--help')) { console.log('node scripts/verify-companion-ui.mjs [--app-root <package>] - isolated desktop/mobile UI; an explicit package runs its contained Node and actual server. Loopback relay verifies the gateway CA; does not modify OS trust or substitute for iPhone acceptance.'); process.exit(0); }
const args = process.argv.slice(2);
if (args.length && (args.length !== 2 || args[0] !== '--app-root' || !path.isAbsolute(args[1]))) throw new Error('Use --app-root with an absolute package directory, or no arguments.');
const appRoot = fs.realpathSync.native(args.length ? args[1] : process.cwd());
const nodePath = args.length ? path.join(appRoot, 'runtime', 'node.exe') : process.execPath;
assert.ok(fs.existsSync(nodePath));
if (args.length) assert.ok(fs.existsSync(path.join(appRoot, 'runtime', 'node_modules', 'npm', 'bin', 'npm-cli.js')), 'The contained engineering runner requires bundled npm.');
const directory = path.resolve('.qa', 'companion-ui-' + randomUUID()); fs.mkdirSync(directory, { recursive: true });
const disposers = [], t = { after: action => disposers.push(action) }, f = fixture(t);
fs.writeFileSync(path.join(f.projectRoot, 'package.json'), JSON.stringify({ name: 'owned-companion-ui', private: true, type: 'module', scripts: { test: 'node --test fixture.test.mjs' } }));
fs.writeFileSync(path.join(f.projectRoot, 'fixture.test.mjs'), "import test from 'node:test';import assert from 'node:assert/strict';test('owned mobile fixture',()=>assert.equal(1+1,2));\n");
f.store.close();
const host = await launchWorkbench(t, f.data, { Path: path.dirname(process.execPath) + path.delimiter + process.env.Path });
const host = await launchWorkbench(t, f.data, { Path: path.dirname(nodePath) + path.delimiter + (process.env.Path || process.env.PATH || '') }, { appRoot, nodePath });
assert.equal(fs.realpathSync.native(host.bootstrap.runtimeRoot), appRoot, 'The isolated host must actually serve the selected package.');
await host.api('/sessions/' + f.session.id + '/messages', { content: '手机伴随端验收:读取项目、准备原差异并等待手机审批。明确为本地离线夹具。' });
await until(async () => (await host.api('/sessions/' + f.session.id)).status === 'awaiting_approval');
const before = await host.api('/sessions/' + f.session.id), browser = await chromium.launch({ channel: 'msedge', headless: true });
@@ -114,7 +120,8 @@ try {
assert.equal((await host.api('/sessions/' + f.session.id)).events.filter(item => item.tool === 'run_command').length, 1);
mark('desktop revocation removes mobile project content immediately on the next read while preserving the original completed tool');
assert.deepEqual(errors, []);
const result = { success: true, passed, screenshots, errors, viewports: [1440, 390, 768], browser: 'Microsoft Edge via Playwright; owned loopback QA relay with actual CA verification',
const result = { success: true, version: host.bootstrap.version, appRoot, nodePath, nodeSha256: createHash('sha256').update(fs.readFileSync(nodePath)).digest('hex'), containedRuntime: args.length > 0,
passed, screenshots, errors, viewports: [1440, 390, 768], browser: 'Microsoft Edge via Playwright; owned loopback QA relay with actual CA verification',
nativeSafariTrustCookiePWA: 'pending-real-iPhone', osTrustChanged: false, certificateWarningsBypassed: false, realModelRequests: 0, taskId: before.taskId, runId: before.runId };
fs.writeFileSync(path.join(directory, 'result.json'), JSON.stringify(result, null, 2));
} catch (error) {
+13 -2
View File
@@ -30,7 +30,7 @@ const directory = path.join(sourceRoot, '.qa', 'package-validation-' + randomUUI
fs.mkdirSync(directory, { recursive: true });
const inputFolders = ['src', 'tests', 'scripts', ...['benchmarks', 'public', 'examples', 'research'].filter(folder => fs.existsSync(path.join(sourceRoot, folder)))];
const inputNames = [...inputFolders.flatMap(folder => files(path.join(sourceRoot, folder)).map(relative => path.join(folder, relative))),
'package.json', 'package-lock.json', 'vite.config.ts', 'tsconfig.json', 'index.html', ...['.gitattributes', '.gitignore', 'Start-Desktop.cmd', 'Start-Workbench.cmd', 'Stop-Workbench.cmd'].filter(name => fs.existsSync(path.join(sourceRoot, name)))].sort();
'package.json', 'package-lock.json', 'vite.config.ts', 'tsconfig.json', 'index.html', ...(evidence.version === '1.16.0' ? ['mobile.html'] : []), ...['.gitattributes', '.gitignore', 'Start-Desktop.cmd', 'Start-Workbench.cmd', 'Stop-Workbench.cmd'].filter(name => fs.existsSync(path.join(sourceRoot, name)))].sort();
const snapshot = () => inputNames.map(relative => ({ path: relative.replaceAll('\\', '/'), bytes: fs.statSync(path.join(sourceRoot, relative)).size, sha256: digest(path.join(sourceRoot, relative)) }));
const inputs = snapshot(); fs.writeFileSync(path.join(directory, 'inputs.json'), JSON.stringify(inputs, null, 2));
let stage = 'environment preflight', python = null;
@@ -116,6 +116,17 @@ try {
assert.equal(actualControlled.success, true); assert.equal(actualControlled.version, evidence.version); assert.equal(actualControlled.rootExited, true);
assert.equal(actualControlled.realModelRequests, 0); assert.equal(actualControlled.cases, 4); assert.ok(actualControlled.fixtureModelRequests > 0);
}
let actualCompanion = null;
if (evidence.version === '1.16.0') {
stage = 'contained companion gateway and UI';
const output = await run(['scripts/verify-companion-ui.mjs', '--app-root', sourceRoot], 'companion-ui.log');
const location = [...output.matchAll(/^EVIDENCE (.+)\r?$/gm)].at(-1)?.[1]?.trim();
assert.ok(location && path.resolve(location).startsWith(path.join(sourceRoot, '.qa') + path.sep));
actualCompanion = JSON.parse(fs.readFileSync(path.join(location, 'result.json'), 'utf8'));
assert.equal(actualCompanion.success, true); assert.equal(actualCompanion.version, evidence.version);
assert.equal(fs.realpathSync.native(actualCompanion.appRoot), sourceRoot); assert.equal(actualCompanion.containedRuntime, true);
assert.equal(actualCompanion.passed.length, 7); assert.deepEqual(actualCompanion.errors, []); assert.equal(actualCompanion.realModelRequests, 0);
}
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])]));
@@ -136,7 +147,7 @@ try {
}
assert.deepEqual(snapshot(), inputs, 'Source package inputs changed during validation.');
const result = { success: true, version: evidence.version, testedAt: new Date().toISOString(), sourceRoot, directory, nodeVersion: process.version, python, offlineInstall: true,
inputs, inputFiles: inputs.length, logs, buildMatchedFiles: Object.keys(expected).length, buildFiles: Object.entries(expected).map(([path, sha256]) => ({ path: path.replaceAll('\\', '/'), sha256 })), tests: stats, actualRea, actualEngine, actualBrowser, actualControlled, actualDesktop, credentialsHandling: 'Only build/runtime environment paths are inherited; no configured model credentials are used. The controlled-engine stage supplies a declared owned local response fixture.' };
inputs, inputFiles: inputs.length, logs, buildMatchedFiles: Object.keys(expected).length, buildFiles: Object.entries(expected).map(([path, sha256]) => ({ path: path.replaceAll('\\', '/'), sha256 })), tests: stats, actualRea, actualEngine, actualBrowser, actualControlled, actualDesktop, actualCompanion, credentialsHandling: 'Only build/runtime environment paths are inherited; no configured model credentials are used. The controlled-engine stage supplies a declared owned local response fixture.' };
save(result); console.log(JSON.stringify({ success: true, version: result.version, sourceRoot, directory, tests: stats, nodeVersion: process.version, python, inputFiles: inputs.length, buildMatchedFiles: result.buildMatchedFiles, rea: !!actualRea?.success, engine: !!actualEngine?.success, browser: !!actualBrowser?.success, controlled: !!actualControlled?.success }));
} catch (error) {
save({ success: false, version: evidence.version, testedAt: new Date().toISOString(), stage, error: error.message, sourceRoot, directory, nodeVersion: process.version, python, inputs, logs });