feat(runtime): default to passthrough and persist execution permissions
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import net from 'node:net';
|
||||
import assert from 'node:assert/strict';
|
||||
import { spawn, execFileSync } from 'node:child_process';
|
||||
import { publicSnapshot, hash, canonical } from './retained-host-state.mjs';
|
||||
import { HostController } from '../src/core/desktop/host-controller.mjs';
|
||||
import { inspectHostInstallation } from '../src/core/desktop/app-installation.mjs';
|
||||
import { openDefaults } from '../src/shared/contracts/execution-policy.mjs';
|
||||
|
||||
// One write-once receipt per explicit operation. Never replay a failed installer
|
||||
// or resume a user project. Only public configuration and row/byte hashes leave
|
||||
// the host; private Provider credentials are not read or saved.
|
||||
const mode = process.argv[2], attempt = process.argv[3] ?? 'formal';
|
||||
if (mode === '--help') { console.log('node scripts/open-permissions-formal-1.25.5.mjs before|upgrade|configure|restart|final [formal[-attempt-N]]'); process.exit(0); }
|
||||
assert.ok(['before', 'upgrade', 'configure', 'restart', 'final'].includes(mode));
|
||||
assert.match(attempt, /^formal(?:-attempt-\d+)?$/);
|
||||
const root = path.resolve('.qa/unrestricted-1.25.5', attempt), url = 'http://127.0.0.1:4318';
|
||||
const read = file => JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
|
||||
fs.mkdirSync(root, { recursive: true });
|
||||
const save = (name, value) => fs.writeFileSync(path.join(root, name), JSON.stringify(value, null, 2) + '\n', { flag: 'wx' });
|
||||
assert.equal(fs.existsSync(path.join(root, mode + '.json')), false, 'Preserve the original operation receipt.');
|
||||
assert.equal(execFileSync('git', ['status', '--porcelain'], { encoding: 'utf8', windowsHide: true }).trim(), '', 'Use reviewed, committed inputs.');
|
||||
const sourceCommit = execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8', windowsHide: true }).trim();
|
||||
async function api(route, input) {
|
||||
const boot = await (await fetch(url + '/api/bootstrap', { headers: { Connection: 'close' }, signal: AbortSignal.timeout(30000) })).json();
|
||||
const response = await fetch(url + '/api' + route, { method: input === undefined ? 'GET' : 'POST', headers: { 'X-Workbench-Token': boot.token,
|
||||
Connection: 'close', ...(input === undefined ? {} : { 'Content-Type': 'application/json' }) }, body: input === undefined ? undefined : JSON.stringify(input), signal: AbortSignal.timeout(60000) });
|
||||
const result = await response.json(); assert.equal(response.ok, true, route + ': ' + JSON.stringify(result)); return result;
|
||||
}
|
||||
async function inspectorClosed() {
|
||||
await new Promise((resolve, reject) => { const socket = net.createConnection({ host: '127.0.0.1', port: 9229 }); socket.setTimeout(1500);
|
||||
socket.once('connect', () => { socket.destroy(); reject(Error('Inspector is open.')); });
|
||||
socket.once('error', error => { socket.destroy(); error.code === 'ECONNREFUSED' ? resolve() : reject(error); });
|
||||
socket.once('timeout', () => { socket.destroy(); reject(Error('Inspector state unknown.')); }); });
|
||||
}
|
||||
async function state() {
|
||||
const host = await api('/host/status'); assert.equal(host.activity.active, false, 'Do not stop an active user task.');
|
||||
const snapshot = await publicSnapshot(url, host.identity.dataRoot), boot = await api('/bootstrap');
|
||||
assert.deepEqual(snapshot.active, []); return { ...snapshot, host, publicConfig: boot.config };
|
||||
}
|
||||
function sameBusiness(before, after, { configuration = false } = {}) {
|
||||
for (const key of ['projectsSha256', 'sessionsSha256', 'eventCursor']) assert.equal(after[key], before[key], key);
|
||||
assert.deepEqual(after.database.sessionIds, before.database.sessionIds); assert.deepEqual(after.exports, before.exports, 'Every original session export');
|
||||
assert.deepEqual(Object.keys(after.database.tables), Object.keys(before.database.tables));
|
||||
for (const [name, table] of Object.entries(before.database.tables)) {
|
||||
const next = after.database.tables[name]; assert.equal(next.count, table.count, name); assert.equal(next.schemaSha256, table.schemaSha256, name);
|
||||
const rows = value => configuration && name === 'metadata' ? value.rows.filter(row => row.id !== 'config') : value.rows;
|
||||
assert.deepEqual(rows(next), rows(table), 'All original rows: ' + name);
|
||||
}
|
||||
assert.deepEqual(after.persistent.artifacts, before.persistent.artifacts, 'Every original artifact byte');
|
||||
const files = value => configuration ? value.filter(row => row.path !== 'config.json') : value;
|
||||
assert.deepEqual(files(after.persistent.files), files(before.persistent.files), 'Original compatibility files');
|
||||
return { originalRows: configuration ? 'exact except explicitly saved metadata/config' : 'exact', originalExports: 'exact', originalArtifactBytes: 'exact',
|
||||
originalFiles: configuration ? 'exact except explicitly saved config.json' : 'exact' };
|
||||
}
|
||||
let result; const startedAt = new Date().toISOString();
|
||||
try {
|
||||
await inspectorClosed(); const current = await state(); assert.equal(current.host.desktopWindows.count, 0);
|
||||
const dataRoot = current.host.identity.dataRoot, installRoot = path.dirname(path.dirname(current.runtimeRoot));
|
||||
assert.equal(path.basename(path.dirname(current.runtimeRoot)), 'versions');
|
||||
if (mode === 'before') {
|
||||
assert.equal(current.version, '1.25.4'); save('state-before.json', current); save('pointer-before.json', read(path.join(installRoot, 'current.json')));
|
||||
result = { success: true, version: current.version, pid: current.pid, instanceId: current.host.identity.instanceId, projects: current.projects,
|
||||
sessions: current.database.sessionIds.length, hasKey: current.hasKey, dataRoot, installRoot };
|
||||
} else if (mode === 'upgrade') {
|
||||
const before = read(path.join(root, 'state-before.json')); sameBusiness(before, current); assert.equal(current.pid, before.pid);
|
||||
assert.deepEqual(read(path.join(installRoot, 'current.json')), read(path.join(root, 'pointer-before.json')));
|
||||
const candidate = read('releases/latest.json'); assert.equal(candidate.documentation.sourceCommit, sourceCommit);
|
||||
const manifest = read(path.join(candidate.portableRoot, 'MANIFEST.json')); assert.equal(manifest.version, '1.25.5');
|
||||
assert.equal(hash(fs.readFileSync(candidate.installer.path)), candidate.installer.sha256); save('candidate.json', candidate);
|
||||
const fd = fs.openSync(path.join(root, 'installer-process.log'), 'wx'), began = Date.now(); let code;
|
||||
try { code = await new Promise((resolve, reject) => { const child = spawn(candidate.installer.path,
|
||||
['/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART', '/LOG=' + path.join(root, 'installer.log'), '/DIR=' + installRoot, '/DATA_ROOT=' + dataRoot, '/PORT=4318'],
|
||||
{ windowsHide: true, stdio: ['ignore', fd, fd] }); child.once('error', reject); child.once('close', resolve); }); } finally { fs.closeSync(fd); }
|
||||
save('installer-exit.json', { code, elapsedMs: Date.now() - began }); assert.equal(code, 0, 'Do not replay the installer.');
|
||||
const after = await state(); const retention = sameBusiness(before, after);
|
||||
assert.equal(after.version, '1.25.5'); assert.equal(after.pid, before.pid); assert.equal(after.host.identity.instanceId, before.host.identity.instanceId);
|
||||
assert.equal(after.hasKey, before.hasKey); assert.equal(after.configSha256, before.configSha256);
|
||||
const installed = path.join(installRoot, 'versions', path.basename(candidate.portableRoot)), identity = inspectHostInstallation(installed);
|
||||
assert.equal(fs.realpathSync.native(after.runtimeRoot), fs.realpathSync.native(installed));
|
||||
const pointer = read(path.join(installRoot, 'current.json')); assert.equal(pointer.active.manifestSha256, identity.manifestSha256);
|
||||
save('state-upgraded.json', after); result = { success: true, pid: after.pid, version: after.version, retention, runtimeRoot: after.runtimeRoot, pointerRevision: pointer.revision };
|
||||
} else if (mode === 'configure') {
|
||||
assert.equal(read(path.join(root, 'upgrade.json')).success, true);
|
||||
const before = read(path.join(root, 'state-upgraded.json')); sameBusiness(before, current); assert.equal(current.pid, before.pid);
|
||||
await api('/model-center/runtime-budgets', { executionMode: 'unrestricted' });
|
||||
await api('/model-center/permissions', { approvalMode: 'full' });
|
||||
const after = await state(), retention = sameBusiness(before, after, { configuration: true });
|
||||
const expected = { ...before.publicConfig, ...openDefaults, approvalMode: 'full', configRevision: before.publicConfig.configRevision + 2 };
|
||||
assert.deepEqual(canonical(after.publicConfig), canonical(expected), 'Only the requested defaults and saved permission change');
|
||||
assert.equal(after.pid, before.pid); assert.equal(after.hasKey, before.hasKey); save('state-configured.json', after);
|
||||
result = { success: true, pid: after.pid, version: after.version, retention, policy: openDefaults, approvalMode: after.publicConfig.approvalMode,
|
||||
configRevision: after.publicConfig.configRevision, selected: after.modelCenter.selected };
|
||||
} else if (mode === 'restart') {
|
||||
assert.equal(read(path.join(root, 'configure.json')).success, true);
|
||||
const before = read(path.join(root, 'state-configured.json')); sameBusiness(before, current); assert.equal(current.pid, before.pid); assert.equal(current.configSha256, before.configSha256);
|
||||
const controller = new HostController({ appRoot: current.runtimeRoot, dataRoot, port: 4318, timeoutMs: 60000 });
|
||||
const connection = await controller.connect(); assert.equal(connection.identity.pid, before.pid);
|
||||
const stopped = await controller.stop(); save('stopped.json', stopped); assert.equal(stopped.processExited, true);
|
||||
const launched = await controller.start(); save('started.json', launched);
|
||||
const after = await state(), retention = sameBusiness(before, after); assert.equal(after.version, '1.25.5'); assert.notEqual(after.pid, before.pid);
|
||||
assert.notEqual(after.host.identity.instanceId, before.host.identity.instanceId);
|
||||
const expected = { ...before.publicConfig, hasKey: after.publicConfig.hasKey }; assert.deepEqual(after.publicConfig, expected);
|
||||
assert.equal(after.publicConfig.approvalMode, 'full'); save('state-restarted.json', after);
|
||||
result = { success: true, version: after.version, previousPid: before.pid, pid: after.pid, previousInstanceId: before.host.identity.instanceId,
|
||||
instanceId: after.host.identity.instanceId, retention, hasKeyBefore: before.hasKey, hasKeyAfter: after.hasKey,
|
||||
publicCredentialPresence: after.modelCenter.connections.map(({ id, name, hasKey }) => ({ id, name, hasKey })), approvalMode: after.publicConfig.approvalMode };
|
||||
} else {
|
||||
assert.equal(read(path.join(root, 'restart.json')).success, true);
|
||||
const before = read(path.join(root, 'state-restarted.json')), retention = sameBusiness(before, current);
|
||||
assert.equal(current.pid, before.pid); assert.equal(current.host.identity.instanceId, before.host.identity.instanceId); assert.equal(current.configSha256, before.configSha256);
|
||||
assert.equal(current.publicConfig.approvalMode, 'full'); save('state-final.json', current);
|
||||
result = { success: true, version: current.version, pid: current.pid, projects: current.projects, sessions: current.database.sessionIds.length,
|
||||
hasKey: current.hasKey, retention, runtimeRoot: current.runtimeRoot, approvalMode: current.publicConfig.approvalMode, desktopWindows: current.host.desktopWindows.count };
|
||||
}
|
||||
await inspectorClosed();
|
||||
} catch (error) { result = { success: false, error: error.stack }; process.exitCode = 1; }
|
||||
result = { ...result, mode, sourceCommit, startedAt, finishedAt: new Date().toISOString(), realModelRequests: 0, keyReadOrResaved: false };
|
||||
save(mode + '.json', result); console.log(JSON.stringify({ root, ...result }, null, 2));
|
||||
@@ -18,13 +18,17 @@ async function until(predicate, timeout = 45000) {
|
||||
|
||||
// This verifier supplies a declared local response algorithm. The executing
|
||||
// Runtime/Store/permissions/native bridge all belong to the compiled host.
|
||||
export async function verifyControlledApi({ api, url, token, directory, appRoot, contained = false }) {
|
||||
export async function verifyControlledApi({ api, url, token, directory, appRoot, contained = false, openExecution = false }) {
|
||||
const origin = new URL(url);
|
||||
assert.equal(origin.hostname, '127.0.0.1'); assert.notEqual(origin.port, '4318');
|
||||
const expectedVersion = JSON.parse(fs.readFileSync(path.join(appRoot, fs.existsSync(path.join(appRoot, 'MANIFEST.json')) ? 'MANIFEST.json' : 'package.json'), 'utf8')).version;
|
||||
assert.ok(['1.14.0', '1.15.0', '1.16.0', '1.17.0', '1.18.0', '1.19.0', '1.20.0', '1.20.1', '1.20.2', '1.20.3', '1.21.0', '1.22.0', '1.22.1', '1.23.0', '1.24.0', '1.24.1', '1.24.2', '1.24.3', '1.24.4', '1.24.5', '1.24.6', '1.24.7', '1.24.8', '1.24.9', '1.25.0', '1.25.1', '1.25.2', '1.25.3', '1.25.4', '1.25.5'].includes(expectedVersion));
|
||||
const bootstrap = await api('/bootstrap'); assert.equal(bootstrap.version, expectedVersion);
|
||||
assert.equal(bootstrap.config.mode, 'demo'); assert.equal(bootstrap.config.hasKey, false);
|
||||
// This legacy acceptance deliberately exercises its original review contract.
|
||||
// Default unrestricted execution is covered separately by the permissions UI.
|
||||
await api('/model-center/runtime-budgets', openExecution ? { executionMode: 'unrestricted' } : { executionMode: 'restricted', capacityMode: 'manual', historyPolicy: 'preserve', contextLimit: 64000, maxOutputTokens: 2048, maxRunTokens: 200000, maxTaskTokens: 200000, maxSteps: 64, maxRunDurationMs: 600000 });
|
||||
if (openExecution) await api('/model-center/permissions', { approvalMode: 'full' });
|
||||
const root = path.join(directory, 'compiled-controlled-node'), hooks = path.join(directory, 'disabled-hooks');
|
||||
fs.mkdirSync(root); fs.mkdirSync(hooks);
|
||||
fs.cpSync(path.join(appRoot, 'benchmarks/workers-delivery-v1/node'), root, { recursive: true });
|
||||
@@ -50,6 +54,7 @@ export async function verifyControlledApi({ api, url, token, directory, appRoot,
|
||||
assert.equal(request.url, '/v1/chat/completions'); assert.equal(request.headers.authorization, 'Bearer owned-compiled-engine-fixture');
|
||||
const chunks = []; for await (const chunk of request) chunks.push(chunk);
|
||||
const input = JSON.parse(Buffer.concat(chunks)); assert.equal(input.model, 'owned-compiled-engineering'); assertToolPairs(input.messages);
|
||||
if (openExecution) for (const key of ['max_tokens', 'max_output_tokens', 'max_completion_tokens']) assert.equal(Object.hasOwn(input, key), false);
|
||||
const session = await api(childRoute), job = session.execution.checks.at(-1), plan = session.execution.plans.at(-1);
|
||||
let calls = [];
|
||||
if (session.changes.some(value => value.status === 'pending')) { /* Host review follows native completion. */ }
|
||||
@@ -69,6 +74,7 @@ export async function verifyControlledApi({ api, url, token, directory, appRoot,
|
||||
await new Promise(resolve => modelServer.listen(0, '127.0.0.1', resolve));
|
||||
try {
|
||||
await api('/config', { mode: 'compatible', model: 'owned-compiled-engineering', baseUrl: 'http://127.0.0.1:' + modelServer.address().port + '/v1', apiKey: 'owned-compiled-engine-fixture', contextLimit: 64000 });
|
||||
if (openExecution) await api('/model-center/runtime-budgets', { executionMode: 'unrestricted' });
|
||||
const project = await api('/projects', { root }), parent = await api('/sessions', { projectId: project.id }); parentRoute = '/sessions/' + parent.id;
|
||||
const installation = await api('/engines/deepseek/controlled-availability'); assert.equal(installation.controlledStatus, 'available', installation.message);
|
||||
assert.equal(installation.version, '0.2.1-rc.2');
|
||||
@@ -87,7 +93,8 @@ export async function verifyControlledApi({ api, url, token, directory, appRoot,
|
||||
const childProject = (await api('/bootstrap')).projects.find(value => value.id === child.projectId);
|
||||
assert.notEqual(childProject.root, root); verifyProtected(childProject.root); assert.deepEqual(owner(), originalOwner); assert.equal(requests.length, 0);
|
||||
mark('compiled host seals actual Harness/source identities and prepares one owned worktree while retaining parent bytes and staging');
|
||||
const apply = async (route, set) => { reviews.push({ action: 'apply reviewed change set', id: set.id, fingerprint: set.fingerprint, paths: set.files.map(value => value.path) });
|
||||
const apply = async (route, set) => { if (openExecution) { assert.equal(set.status, 'completed', set.summary); return; }
|
||||
reviews.push({ action: 'apply reviewed change set', id: set.id, fingerprint: set.fingerprint, paths: set.files.map(value => value.path) });
|
||||
await api(route + '/change-sets/' + set.id + '/apply', { fingerprint: set.fingerprint });
|
||||
let state; await until(async () => { state = await api(route + '/change-sets/' + set.id); return !['prepared', 'applying'].includes(state.status); }); assert.equal(state.status, 'completed', state.summary); };
|
||||
for (let turn = 0; turn < 4 && group.status !== 'ready_to_collect'; turn++) {
|
||||
@@ -108,6 +115,7 @@ export async function verifyControlledApi({ api, url, token, directory, appRoot,
|
||||
const response = await fetch(url + '/api' + childRoute + '/engine-runs/' + run.id + '/download', { headers: { 'X-Workbench-Token': token, Connection: 'close' } });
|
||||
assert.equal(response.status, 200); const bytes = Buffer.from(await response.arrayBuffer()); assert.equal(sha(bytes), run.reportSha256);
|
||||
const original = JSON.parse(bytes); assert.equal(original.native.stderr, ''); assert.equal(original.native.cleanup.treeConfirmed, true);
|
||||
if (openExecution) assert.equal(Object.hasOwn(original.native.responses.find(value => value.method === 'initialize').params, 'maxTokens'), false);
|
||||
assert.equal(original.native.activity.endEvents[0].data.reason.kind, 'completed');
|
||||
assert.equal(original.native.readiness.promptExperimentSha256, run.installation.strategy.sha256);
|
||||
const saved = path.join(directory, 'compiled-engine-original-' + run.id + '.json'); fs.writeFileSync(saved, bytes); originalRuns.push({ run, original, reportPath: saved, sha256: sha(bytes) });
|
||||
@@ -118,7 +126,8 @@ export async function verifyControlledApi({ api, url, token, directory, appRoot,
|
||||
assert.equal(current.execution.task.usage.requests, requests.length); assert.equal(current.execution.task.usage.totalTokens, requests.length * 168);
|
||||
for (const request of requests) assert.equal(request.input.messages.filter(value => value.role === 'system').map(value => value.content).join('').split(group.children[0].engine.strategy.section.text).length - 1, 1);
|
||||
verifyProtected(childProject.root); assert.deepEqual(owner(), originalOwner);
|
||||
mark('compiled native execution retains failing tests, requires original check approvals, seals literal prompt/model/receipts/results and accounts each owned HTTP request once');
|
||||
if (openExecution) { assert.equal(reviews.length, 0); assert.ok(current.approvals.length > 0); assert.ok(current.approvals.every(value => value.status === 'approved' && value.decisionSource === 'full-access-policy')); }
|
||||
mark(openExecution ? 'actual native SDK applies changes and runs checks in full access, preserving failures, complete requests and actual usage without manual review' : 'compiled native execution retains failing tests, requires original check approvals, seals literal prompt/model/receipts/results and accounts each owned HTTP request once');
|
||||
await operation('collect'); await until(async () => { group = await groupState(); return group.status !== 'collecting'; }); assert.equal(group.status, 'collected', group.summary);
|
||||
const collection = await api(parentRoute + '/collaborations/' + group.id + '/collection'); assert.deepEqual(collection.conflicts, []); assert.deepEqual(collection.paths, writable);
|
||||
await operation('merge'); await until(async () => { group = await groupState(); return ['merge_prepared', 'unknown', 'stale'].includes(group.status); }); assert.equal(group.status, 'merge_prepared', group.summary);
|
||||
@@ -137,7 +146,7 @@ export async function verifyControlledApi({ api, url, token, directory, appRoot,
|
||||
assert.deepEqual(owner(), originalOwner); verifyProtected(root); await operation('finalize'); group = await groupState(); assert.equal(group.status, 'completed', group.summary);
|
||||
for (const route of [parentRoute, childRoute]) { const value = await api(route); const file = path.join(directory, value.id + '-session.json'); fs.writeFileSync(file, JSON.stringify(value, null, 2)); exports.push({ id: value.id, file, sha256: sha(fs.readFileSync(file)) }); }
|
||||
mark('compiled Git delivery contains only reviewed modules, preserves staged/unstaged/untracked owner bytes and completes the parent with sealed original evidence');
|
||||
return { success: true, version: bootstrap.version, appRoot, contained, cases, root, group, requests, reviews, originalRuns, exports,
|
||||
return { success: true, version: bootstrap.version, appRoot, contained, openExecution, cases, root, group, requests, reviews, originalRuns, exports,
|
||||
protectedFiles: Object.fromEntries(Object.entries(protectedFiles).map(([name, bytes]) => [name, sha(bytes)])), owner: originalOwner, installation, purgeSource: source,
|
||||
checks: check, delivery, fixtureModelRequests: requests.length, realModelRequests: 0,
|
||||
scope: 'Actual compiled host, local native Harness, checks/reviews/Git and an explicitly owned HTTP response fixture. No configured model or upstream Purge plugin executes; real inference benefit remains unmeasured.' };
|
||||
@@ -152,7 +161,7 @@ export async function verifyControlledApi({ api, url, token, directory, appRoot,
|
||||
}
|
||||
}
|
||||
|
||||
export async function verifyControlledRelease(appRoot = process.cwd()) {
|
||||
export async function verifyControlledRelease(appRoot = process.cwd(), { openExecution = false } = {}) {
|
||||
appRoot = fs.realpathSync.native(appRoot);
|
||||
// Keep the synthetic Git project independent of the installation/extraction
|
||||
// depth. The production workspace path guard remains responsible for users'
|
||||
@@ -174,7 +183,7 @@ export async function verifyControlledRelease(appRoot = process.cwd()) {
|
||||
await until(() => url || child.exitCode !== null, 15000); assert.ok(url, errors);
|
||||
bootstrap = await (await fetch(url + '/api/bootstrap', { signal: AbortSignal.timeout(5000) })).json();
|
||||
const health = await api('/health'); assert.equal(health.pid, child.pid);
|
||||
result = await verifyControlledApi({ api, url, token: bootstrap.token, directory, appRoot, contained: node !== process.execPath });
|
||||
result = await verifyControlledApi({ api, url, token: bootstrap.token, directory, appRoot, contained: node !== process.execPath, openExecution });
|
||||
} catch (error) { result = { success: false, appRoot, directory, error: error.stack, realModelRequests: 0 }; throw error; }
|
||||
finally {
|
||||
try { if (url && bootstrap && child.exitCode === null) { await api('/shutdown', {}); await until(() => child.exitCode !== null || child.signalCode !== null, 15000); } }
|
||||
@@ -192,8 +201,9 @@ export async function verifyControlledRelease(appRoot = process.cwd()) {
|
||||
}
|
||||
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length === 1 && args[0] === '--help') { console.log('node scripts/verify-controlled-release.mjs [--app-root DIR] - run an actual compiled local host/native Harness/owned model/Node repair/check/review/Git/prompt acceptance in independent data. Requires explicit Harness and Purge source paths.'); process.exit(0); }
|
||||
assert.ok(!args.length || args.length === 2 && args[0] === '--app-root' && path.isAbsolute(args[1]), 'Unsupported argument; use --help.');
|
||||
const result = await verifyControlledRelease(args[1]); console.log(JSON.stringify({ success: result.success, version: result.version, directory: result.directory, cases: result.cases.length,
|
||||
if (args.length === 1 && args[0] === '--help') { console.log('node scripts/verify-controlled-release.mjs [--app-root DIR] [--open] - actual compiled host/native Harness/owned model/Node repair/check/Git acceptance in independent data; --open uses unlimited defaults and full access.'); process.exit(0); }
|
||||
const openExecution = args.includes('--open'), options = args.filter(value => value !== '--open');
|
||||
assert.ok(!options.length || options.length === 2 && options[0] === '--app-root' && path.isAbsolute(options[1]), 'Unsupported argument; use --help.');
|
||||
const result = await verifyControlledRelease(options[1], { openExecution }); console.log(JSON.stringify({ success: result.success, version: result.version, directory: result.directory, cases: result.cases.length,
|
||||
rootExited: result.rootExited, fixtureModelRequests: result.fixtureModelRequests, realModelRequests: 0 }));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { chromium, _electron } from 'playwright';
|
||||
import { expect } from 'playwright/test';
|
||||
import { HostController } from '../src/core/desktop/host-controller.mjs';
|
||||
import { desktopExecutableIdentity } from '../src/core/desktop/app-installation.mjs';
|
||||
import { projectEnvironment } from '../src/core/process-environment.mjs';
|
||||
import { openDefaults } from '../src/shared/contracts/execution-policy.mjs';
|
||||
|
||||
if (process.argv.includes('--help')) { console.log('node scripts/verify-open-formal-ui.mjs [--desktop] — read-only formal installed UI inspection; no model requests, permission edits or user project execution.'); process.exit(0); }
|
||||
assert.ok(process.argv.slice(2).every(arg => arg === '--desktop'));
|
||||
const desktop = process.argv.includes('--desktop'), url = 'http://127.0.0.1:4318';
|
||||
const root = path.resolve('.qa/unrestricted-1.25.5', (desktop ? 'formal-electron-' : 'formal-web-') + randomUUID()); fs.mkdirSync(root, { recursive: true });
|
||||
const boot = await (await fetch(url + '/api/bootstrap', { headers: { Connection: 'close' } })).json();
|
||||
assert.equal(boot.version, '1.25.5'); assert.equal(boot.config.approvalMode, 'full');
|
||||
for (const [key, value] of Object.entries(openDefaults)) assert.equal(boot.config[key], value, key);
|
||||
const host = await (await fetch(url + '/api/host/status', { headers: { 'X-Workbench-Token': boot.token, Connection: 'close' } })).json(); assert.equal(host.activity.active, false);
|
||||
let browser, app, page, window, result; const screenshots = [], errors = [];
|
||||
try {
|
||||
if (desktop) {
|
||||
const controller = new HostController({ appRoot: boot.runtimeRoot, dataRoot: host.identity.dataRoot, port: 4318, timeoutMs: 60000 });
|
||||
const connection = await controller.connect(); assert.equal(connection.identity.pid, host.identity.pid);
|
||||
const executablePath = desktopExecutableIdentity(boot.runtimeRoot).path;
|
||||
app = await _electron.launch({ executablePath, args: ['--app-root', boot.runtimeRoot, '--data-root', host.identity.dataRoot, '--port', '4318'], env: projectEnvironment({ AGENT_WORKBENCH_QA: '1' }) });
|
||||
page = await app.firstWindow(); window = await app.browserWindow(page);
|
||||
} else { browser = await chromium.launch({ channel: 'msedge', headless: true }); page = await browser.newPage(); await page.goto(url); }
|
||||
page.on('pageerror', error => errors.push(error.message)); await page.waitForLoadState('networkidle');
|
||||
for (const width of [1440, 390]) {
|
||||
if (window) { await window.evaluate((value, size) => value.setContentSize(size.width, size.height), { width, height: 1080 }); await expect.poll(() => page.evaluate(() => innerWidth)).toBe(width); }
|
||||
else await page.setViewportSize({ width, height: 1080 });
|
||||
await expect(page.getByLabel('操作权限', { exact: true })).toHaveValue('full');
|
||||
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1));
|
||||
const file = path.join(root, 'permission-' + width + '.png'); await page.screenshot({ path: file, fullPage: true }); screenshots.push(file);
|
||||
}
|
||||
await page.getByRole('button', { name: '打开模型中心', exact: true }).click();
|
||||
const dialog = page.getByRole('dialog', { name: '模型中心', exact: true }); await dialog.getByRole('button', { name: '运行预算', exact: true }).click();
|
||||
await expect(dialog.getByLabel('额度策略', { exact: true })).toHaveValue('unrestricted');
|
||||
await expect(dialog.getByLabel('输出上限', { exact: true })).toHaveCount(0);
|
||||
const file = path.join(root, 'open-budget-390.png'); await page.screenshot({ path: file, fullPage: true }); screenshots.push(file);
|
||||
await dialog.getByRole('button', { name: '关闭窗口', exact: true }).click();
|
||||
assert.deepEqual(errors, []); result = { success: true, version: boot.version, pid: host.identity.pid, runtimeRoot: boot.runtimeRoot, desktop, screenshots, errors, realModelRequests: 0, userProjectsExecuted: 0, writes: 0 };
|
||||
} catch (error) { if (page) await page.screenshot({ path: path.join(root, 'failure.png'), fullPage: true }).catch(() => {}); result = { success: false, error: error.stack, desktop, screenshots, errors }; }
|
||||
finally { await app?.close(); await browser?.close(); fs.writeFileSync(path.join(root, 'result.json'), JSON.stringify(result, null, 2)); }
|
||||
console.log(JSON.stringify({ root, ...result })); if (!result.success) process.exitCode = 1;
|
||||
@@ -102,10 +102,12 @@ try {
|
||||
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'; });
|
||||
await until(async () => { current = await api('/sessions/' + session.id); return current.status === 'completed'; });
|
||||
const command = current.events.find(event => event.tool === 'run_command');
|
||||
assert.equal(command.phase, 'completed'); assert.match(command.output, new RegExp(manifest.nodeVersion.replaceAll('.', '\\.')));
|
||||
for (const proposal of current.changes.filter(change => change.status === 'pending')) await api('/sessions/' + session.id + '/changes/' + proposal.id + '/reject', {});
|
||||
assert.equal(current.changes.filter(change => change.status === 'pending').length, 0);
|
||||
for (const proposal of current.changes.filter(change => change.status === 'applied')) await api('/sessions/' + session.id + '/changes/' + proposal.id + '/rollback', {});
|
||||
assert.equal(fs.existsSync(path.join(example.root, 'WORKBENCH-NOTES.md')), false);
|
||||
const planned = await api('/sessions/' + session.id + '/check-plans', { names: ['test'] });
|
||||
const plan = planned.execution.plans.at(-1); assert.ok(plan.checks.some(check => check.name === 'test'));
|
||||
const accepted = await api('/sessions/' + session.id + '/check-jobs', { planId: plan.id }); const jobId = accepted.execution.checks.at(-1).id;
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import net from 'node:net';
|
||||
import http from 'node:http';
|
||||
import assert from 'node:assert/strict';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { chromium, _electron } from 'playwright';
|
||||
import { expect } from 'playwright/test';
|
||||
import { PNG } from 'pngjs';
|
||||
import { fixture, compatibleFixture, completion, call, launchWorkbench, until } from '../tests/helpers.mjs';
|
||||
import { Provider } from '../src/server/provider.mjs';
|
||||
import { HostController } from '../src/core/desktop/host-controller.mjs';
|
||||
import { desktopExecutableIdentity } from '../src/core/desktop/app-installation.mjs';
|
||||
import { projectEnvironment } from '../src/core/process-environment.mjs';
|
||||
|
||||
if (process.argv.includes('--help')) { console.log('node scripts/verify-unrestricted-ui.mjs [--desktop] — isolated actual passthrough, permissions, automatic writes/rollback, upstream errors and cache UI. Optional AGENT_WORKBENCH_QA_APP_ROOT selects the immutable app. No real-model keys.'); process.exit(0); }
|
||||
assert.ok(process.argv.slice(2).every(value => value === '--desktop'));
|
||||
const desktop = process.argv.includes('--desktop'), appRoot = path.resolve(process.env.AGENT_WORKBENCH_QA_APP_ROOT || '.');
|
||||
const directory = path.resolve('.qa/unrestricted-1.25.5', (desktop ? 'open-electron-' : 'open-web-') + randomUUID());
|
||||
fs.mkdirSync(directory, { recursive: true }); console.log('EVIDENCE ' + directory);
|
||||
const disposers = [], t = { after: fn => disposers.push(fn) }, f = fixture(t, { modernDefaults: true }), checks = [], screenshots = [], errors = [];
|
||||
let host, controller, browser, application, page, window, result, ownedFailure = false, browserUrl, browserTurn = 0, ownedTabId;
|
||||
const dialog = () => page.getByRole('dialog', { name: '模型中心', exact: true });
|
||||
const mark = name => { checks.push(name); console.log('PASS ' + name); };
|
||||
async function open() { if (!await dialog().count()) await page.getByRole('button', { name: '打开模型中心', exact: true }).click(); }
|
||||
async function resize(width) {
|
||||
if (window) { await window.evaluate((win, size) => win.setContentSize(size.width, size.height), { width, height: 1080 }); await until(() => page.evaluate(w => innerWidth === w, width)); }
|
||||
else await page.setViewportSize({ width, height: 1080 });
|
||||
const compactControl = page.locator('.task-toolbar').getByRole('button', { name: '查看文件', exact: true });
|
||||
if (width <= 940) await expect(compactControl).toBeVisible(); else await expect(compactControl).toHaveCount(0);
|
||||
}
|
||||
async function shot(name) {
|
||||
const file = path.join(directory, name + '.png'); await page.screenshot({ path: file, fullPage: true }); screenshots.push(file);
|
||||
fs.writeFileSync(path.join(directory, name + '.txt'), await page.locator('body').innerText());
|
||||
}
|
||||
try {
|
||||
if (desktop) {
|
||||
const site = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
||||
res.end(req.url === '/next' ? '<title>Owned second origin</title><h1>CROSS-ORIGIN-COMPLETE</h1>' : '<title>Owned full-access site</title><label>账户口令<input type="password"></label><label>运行方式<select><option value="ask">请求批准</option><option value="full">完全访问</option></select></label><a href="http://localhost:' + site.address().port + '/next">打开第二来源</a>' + Array.from({length:130},(_,i)=>'<button>Owned control ' + i + '</button>').join('') + '<p>' + 'FULL-BROWSER-TEXT '.repeat(1500) + 'LONG-END</p>'); });
|
||||
await new Promise(resolve => site.listen(0, '127.0.0.1', resolve)); browserUrl = 'http://127.0.0.1:' + site.address().port + '/';
|
||||
disposers.push(() => new Promise(resolve => { site.closeAllConnections(); site.close(resolve); }));
|
||||
}
|
||||
const browserReply = body => {
|
||||
const turn = ++browserTurn, original = body.messages.findLast(row => row.role === 'tool');
|
||||
const observed = original ? JSON.parse(original.content) : null;
|
||||
if (turn === 1) return completion([call('browser-open', 'open_browser_tab', { url: browserUrl })]);
|
||||
if (turn === 2) { ownedTabId = observed.id; return completion([call('browser-observe', 'observe_browser_tab', { tab_id: ownedTabId })]); }
|
||||
if (turn <= 5) {
|
||||
const label = turn === 3 ? '账户口令' : turn === 4 ? '运行方式' : '打开第二来源';
|
||||
assert.ok(Array.isArray(observed?.controls), 'Original browser result at turn ' + turn + ': ' + JSON.stringify(observed));
|
||||
const control = observed.controls.find(value => value.label.startsWith(label)); assert.ok(control, label);
|
||||
if (turn === 3) { assert.ok(observed.text.length > 16000); assert.ok(observed.controls.length > 120); assert.ok(observed.text.includes('LONG-END')); }
|
||||
return completion([call('browser-act-' + turn, 'act_browser_tab', { tab_id: ownedTabId, observationId: observed.id, revision: observed.revision,
|
||||
action: turn === 5 ? 'click' : 'fill', ref: control.ref, ...(turn === 3 ? { value: 'OWNED-PASSWORD' } : turn === 4 ? { value: 'full' } : {}) })]);
|
||||
}
|
||||
return completion([], 'Owned full browser flow complete.');
|
||||
};
|
||||
const model = await compatibleFixture(t, (url, body) => ownedFailure ? { status: 429, body: { error: { code: 'owned_rate', type: 'owned_original', message: 'UI-UPSTREAM-ORIGINAL', detail: '原始上游正文'.repeat(6000) } }, headers: { 'x-request-id': 'owned-ui-error-id' } } : url.endsWith('/models') ? { data: [{ id: 'owned-capacity', context_length: 131072, max_output_tokens: 32768, capabilities: { text: true, tools: true } }] }
|
||||
: body.messages.some(row => row.role === 'user' && row.content.includes('FULL-BROWSER-FLOW')) ? browserReply(body)
|
||||
: body.messages.some(row => row.role === 'user' && row.content.includes('PERMISSION-FLOW')) ? completion(body.messages.some(row => row.role === 'tool') ? [] : [call('owned-permission', 'run_command', { command: process.platform === 'win32' ? 'Write-Output "OWNED-PERMISSION-MARKER"' : 'printf OWNED-PERMISSION-MARKER', reason: 'Verify permission switching in the actual UI.' })], 'Permission flow complete.')
|
||||
: body.messages.some(row => row.role === 'user' && row.content.includes('AUTO-WRITE-FLOW')) ? completion(body.messages.some(row => row.role === 'tool') ? [] : [call('owned-write', 'propose_file', { path: 'ui-auto.txt', content: 'OWNED-APPLIED\n', reason: 'Verify automatic writes and exact rollback.' })], 'File flow complete.')
|
||||
: { ...completion(body.messages.some(row => row.role === 'tool') ? [] : [call('owned-list', 'list_files', { path: '' })], 'Owned reference answer.'),
|
||||
usage: { prompt_tokens: 1000, completion_tokens: 20, prompt_tokens_details: { cached_tokens: 700 } } });
|
||||
const hub = new Provider().modelHub(f.store), source = hub.upsert({ name: 'Owned source', model: 'source', baseUrl: model.baseUrl, requiresKey: false });
|
||||
const preview = await hub.modelCatalog().fetch({ id: source.id, revision: source.revision });
|
||||
const applied = hub.modelCatalog().apply({ previewId: preview.id, models: ['owned-capacity'], routing: 'manual', defaultModel: 'owned-capacity' });
|
||||
const connection = hub.upsert({ ...hub.connection(applied.added[0]), contextLimit: 16000, maxOutputTokens: 2048 });
|
||||
assert.equal(connection.upstreamModel.maxOutputTokens, 32768); f.store.close();
|
||||
if (desktop) {
|
||||
const socket = net.createServer(); await new Promise(resolve => socket.listen(0, '127.0.0.1', resolve)); const port = socket.address().port; await new Promise(resolve => socket.close(resolve)); assert.notEqual(port, 4318);
|
||||
controller = new HostController({ appRoot, dataRoot: f.data, port, nodePath: process.execPath, timeoutMs: 60000 }); await controller.start();
|
||||
host = { api: (route, input) => controller.api(route, input ? { method: 'POST', input } : {}), bootstrap: await controller.api('/bootstrap') };
|
||||
const executable = desktopExecutableIdentity(appRoot).path;
|
||||
application = await _electron.launch({ executablePath: executable, args: [...(executable.toLowerCase().endsWith('agentworkbench.exe') ? [] : [path.join(appRoot, 'dist-desktop/main.cjs')]),
|
||||
'--app-root', appRoot, '--data-root', f.data, '--node', process.execPath, '--port', String(port)], env: projectEnvironment({ AGENT_WORKBENCH_QA: '1', AGENT_WORKBENCH_NODE: process.execPath }) });
|
||||
page = await application.firstWindow(); window = await application.browserWindow(page); await page.waitForLoadState();
|
||||
} else {
|
||||
host = await launchWorkbench(t, f.data, {}, { appRoot }); assert.notEqual(new URL(host.url).port, '4318');
|
||||
browser = await chromium.launch({ channel: 'msedge', headless: true }); page = await browser.newPage(); await page.goto(host.url);
|
||||
}
|
||||
|
||||
page.on('pageerror', error => errors.push(error.message)); await page.waitForLoadState('networkidle'); await resize(1440);
|
||||
const permission = () => page.getByLabel('操作权限', { exact: true });
|
||||
await expect(permission()).toHaveValue('ask');
|
||||
for (const mode of ['auto', 'full', 'ask']) {
|
||||
await permission().selectOption(mode); await until(async () => (await host.api('/bootstrap')).config.approvalMode === mode);
|
||||
await page.reload(); await expect(permission()).toHaveValue(mode);
|
||||
}
|
||||
mark('three permission choices save immediately, survive page reload and start at request approval');
|
||||
const permissionSession = await host.api('/sessions', { projectId: f.project.id });
|
||||
await host.api('/sessions/' + permissionSession.id + '/messages', { content: 'PERMISSION-FLOW: run the owned marker command once.' });
|
||||
await until(async () => (await host.api('/sessions/' + permissionSession.id)).status === 'awaiting_approval', 30000);
|
||||
await permission().selectOption('full');
|
||||
await until(async () => (await host.api('/sessions/' + permissionSession.id)).status === 'completed', 30000);
|
||||
const allowed = await host.api('/sessions/' + permissionSession.id);
|
||||
assert.equal(allowed.approvals.length, 1); assert.equal(allowed.approvals[0].decisionSource, 'full-access-policy');
|
||||
assert.equal(model.requests.filter(row => row.input).length, 2);
|
||||
for (const width of [1440, 390]) { await resize(width); await expect(permission()).toHaveValue('full'); await shot('permissions-full-' + width); }
|
||||
mark('selecting full access while a command waits releases that original command exactly once');
|
||||
await resize(1440); await open();
|
||||
await dialog().getByRole('button', { name: '运行预算', exact: true }).click();
|
||||
const budgets = () => dialog().getByRole('form', { name: '运行预算设置', exact: true });
|
||||
const originalSelection = (await host.api('/model-center')).selected;
|
||||
await budgets().getByLabel('额度策略', { exact: true }).selectOption('unrestricted');
|
||||
await expect(budgets().getByLabel('输出上限', { exact: true })).toHaveCount(0);
|
||||
await budgets().getByRole('button', { name: '保存运行预算', exact: true }).click();
|
||||
await expect(dialog().getByRole('status').filter({ hasText: '运行预算已保存' })).toBeVisible();
|
||||
const expected = { executionMode:'unrestricted', capacityMode:'passthrough', historyPolicy:'preserve', maxSteps:0, maxRunDurationMs:0, maxRunTokens:0, maxTaskTokens:0, modelResponseTimeoutMs:0, modelStreamIdleTimeoutMs:0 };
|
||||
for (const [key, value] of Object.entries(expected)) assert.equal((await host.api('/bootstrap')).config[key], value, key);
|
||||
assert.deepEqual((await host.api('/model-center')).selected, originalSelection);
|
||||
await page.reload(); await open(); await dialog().getByRole('button', { name: '运行预算', exact: true }).click();
|
||||
await expect(budgets().getByLabel('额度策略', { exact: true })).toHaveValue('unrestricted');
|
||||
for (const width of [1440,390]) { await resize(width); assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1)); await shot('open-settings-' + width); }
|
||||
mark('open defaults save as real zeros, survive reload, hide local quotas and retain model selection at 1440 and 390 pixels');
|
||||
await budgets().getByLabel('额度策略', { exact: true }).selectOption('restricted');
|
||||
await budgets().getByLabel('容量策略', { exact: true }).selectOption('manual');
|
||||
await budgets().getByLabel('输出上限', { exact: true }).fill('32768');
|
||||
await budgets().getByLabel('上下文预算', { exact: true }).fill('131072');
|
||||
await budgets().getByRole('button', { name: '保存运行预算', exact: true }).click();
|
||||
await expect(dialog().getByRole('status').filter({ hasText: '运行预算已保存' })).toBeVisible();
|
||||
assert.equal((await host.api('/bootstrap')).config.maxOutputTokens,32768);
|
||||
await budgets().getByLabel('额度策略', { exact: true }).selectOption('unrestricted');
|
||||
await budgets().getByRole('button', { name: '保存运行预算', exact: true }).click();
|
||||
await expect(dialog().getByRole('status').filter({ hasText: '运行预算已保存' })).toBeVisible();
|
||||
mark('explicit manual settings remain selectable and returning to open mode removes their enforcement');
|
||||
await dialog().getByRole('button', { name:'关闭窗口', exact:true }).click();
|
||||
await host.api('/sessions/'+f.session.id+'/messages',{content:'Inspect the directory once and answer only. Do not modify files or run checks.'});
|
||||
let state; await until(async()=>{state=await host.api('/sessions/'+f.session.id);return !['running','awaiting_approval','stopping'].includes(state.status);},30000);
|
||||
assert.equal(state.status,'completed',JSON.stringify(state.failure)); assert.equal(model.requests.filter(row=>row.input).length,4);
|
||||
for(const row of model.requests.filter(row=>row.input)) for(const key of ['max_tokens','max_output_tokens','max_completion_tokens']) assert.equal(Object.hasOwn(row.input,key),false);
|
||||
async function selectProject() { const project=page.getByLabel('当前项目',{exact:true});if(!await project.isVisible())await page.getByRole('button',{name:'展开项目栏',exact:true}).click();await project.selectOption(f.project.id); }
|
||||
await page.reload(); await selectProject(); await page.getByRole('button',{name:'查看任务记录',exact:true}).click();
|
||||
const context=page.getByLabel('请求上下文',{exact:true}); await expect(context).toContainText('700 tokens'); await expect(context).toContainText('不附加上限');
|
||||
for(const width of [1440,390]){await resize(width);if(!await context.isVisible())await page.getByRole('button',{name:'查看任务记录',exact:true}).click();await context.scrollIntoViewIfNeeded();assert.ok(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth+1));await shot('open-request-cache-'+width);}
|
||||
fs.writeFileSync(path.join(directory,'completed-session.json'),JSON.stringify(state,null,2));
|
||||
mark('actual requests omit output limits and request records separately show complete history, unlimited budgets and reported cache usage');
|
||||
ownedFailure=true; await host.api('/sessions/'+f.session.id+'/messages',{content:'Reply once and retain any upstream error.'});
|
||||
await until(async()=>{state=await host.api('/sessions/'+f.session.id);return !['running','awaiting_approval','stopping'].includes(state.status);},30000);
|
||||
assert.equal(state.status,'failed');assert.equal(state.failure.httpStatus,429);assert.equal(state.failure.upstream.code,'owned_rate');assert.equal(state.failure.retryDecision,'passthrough');
|
||||
assert.equal(model.requests.filter(row=>row.input).length,5); await page.reload();await selectProject();
|
||||
const details=page.locator('details.model-error-details').filter({hasText:'owned-ui-error-id'}).first();await details.locator('summary').click();await expect(details).toContainText('上游模型服务');await expect(details).toContainText('UI-UPSTREAM-ORIGINAL');
|
||||
await expect(details.getByRole('button',{name:'下载已保存的原文',exact:true})).toBeVisible();
|
||||
for(const width of [1440,390]){await resize(width);if(!await details.isVisible())await page.getByRole('button',{name:'查看对话',exact:true}).click();await details.scrollIntoViewIfNeeded();await shot('original-upstream-error-'+width);}
|
||||
fs.writeFileSync(path.join(directory,'failed-session.json'),JSON.stringify(state,null,2));assert.deepEqual(errors,[]);
|
||||
mark('original upstream status, code, request ID, preview and complete-body download are visible without retry or failover');
|
||||
ownedFailure = false;
|
||||
const writeSession = await host.api('/sessions', { projectId: f.project.id });
|
||||
await host.api('/sessions/' + writeSession.id + '/messages', { content: 'AUTO-WRITE-FLOW: create the owned UI file.' });
|
||||
await until(async () => (await host.api('/sessions/' + writeSession.id)).status === 'completed', 30000);
|
||||
const written = await host.api('/sessions/' + writeSession.id); assert.equal(written.changes[0].status, 'applied');
|
||||
assert.equal(fs.readFileSync(path.join(f.projectRoot, 'ui-auto.txt'), 'utf8'), 'OWNED-APPLIED\n');
|
||||
await resize(1440); await page.reload(); await selectProject();
|
||||
await page.getByRole('button', { name: /AUTO-WRITE-FLOW/ }).first().click();
|
||||
await page.locator('.inspector-tabs').getByRole('button', { name: '改动', exact: true }).click();
|
||||
await expect(page.getByRole('button', { name: '回滚这项改动', exact: true })).toBeVisible(); await shot('automatically-applied-file');
|
||||
await page.getByRole('button', { name: '回滚这项改动', exact: true }).click();
|
||||
await until(async () => (await host.api('/sessions/' + writeSession.id)).changes[0].status === 'rolled_back');
|
||||
assert.equal(fs.existsSync(path.join(f.projectRoot, 'ui-auto.txt')), false); await shot('rolled-back-file');
|
||||
assert.equal(await page.getByText('项改动等待审查', { exact: false }).count(), 0);
|
||||
mark('an automatic file write has no review pause and its UI rollback restores the original absence without deleting history');
|
||||
await page.getByRole('button', { name: '关闭检查器', exact: true }).click().catch(() => {});
|
||||
const image=new PNG({width:32,height:16}),imageBytes=PNG.sync.write(image);
|
||||
await page.getByLabel('选择工程截图', { exact: true }).setInputFiles(Array.from({length:9},(_,index)=>({name:'owned-'+index+'.png',mimeType:'image/png',buffer:imageBytes})));
|
||||
await expect(page.locator('.input-draft')).toHaveCount(9);
|
||||
await expect(page.locator('.input-draft input:checked')).toHaveCount(9);
|
||||
await page.locator('.input-remove').nth(1).click();
|
||||
await expect(page.locator('.input-draft')).toHaveCount(8);
|
||||
await expect(page.locator('.input-draft input:checked')).toHaveCount(8);
|
||||
await resize(390);await shot('multiple-input-images-390');await resize(1440);
|
||||
mark('nine images upload together and removing one retains all other selected images without a one-image quota');
|
||||
if (desktop) {
|
||||
const browserSession = await host.api('/sessions', { projectId: f.project.id });
|
||||
await host.api('/sessions/' + browserSession.id + '/messages', { content: 'FULL-BROWSER-FLOW: open and operate the owned local site.' });
|
||||
let browserState; await until(async () => { browserState = await host.api('/sessions/' + browserSession.id); return !['running', 'stopping', 'awaiting_approval'].includes(browserState.status); }, 45000);
|
||||
fs.writeFileSync(path.join(directory, 'full-browser-session.json'), JSON.stringify(browserState, null, 2));
|
||||
assert.equal(browserState.status, 'completed', JSON.stringify(browserState.failure)); assert.equal(browserTurn, 6);
|
||||
assert.equal(browserState.approvals.length, 4); assert.ok(browserState.approvals.every(value => value.status === 'approved' && value.decisionSource === 'full-access-policy'));
|
||||
await until(() => application.evaluate(({ webContents }) => webContents.getAllWebContents().some(value => value.getURL().includes('localhost:') && value.getURL().endsWith('/next'))), 15000);
|
||||
fs.writeFileSync(path.join(directory, 'full-browser-session.json'), JSON.stringify(browserState, null, 2));
|
||||
const png = await application.evaluate(async ({ webContents }) => (await webContents.getAllWebContents().find(value => value.getURL().includes('localhost:') && value.getURL().endsWith('/next')).capturePage()).toPNG().toString('base64'));
|
||||
const screenshot = path.join(directory, 'full-browser-second-origin.png'); fs.writeFileSync(screenshot, Buffer.from(png, 'base64')); screenshots.push(screenshot);
|
||||
await host.api('/sessions/' + browserSession.id + '/browsing/tabs/' + ownedTabId + '/close', { approved: true });
|
||||
mark('actual Electron full access opens localhost, retains large DOM and 133 controls, fills password/select and navigates across origins without a manual approval');
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
assert.equal(model.requests.filter(row => row.input).length, desktop ? 13 : 7);
|
||||
result={success:true,version:host.bootstrap.version,appRoot,actualElectron:desktop,checks,screenshots,errors,realModelRequests:0,ownedModelRequests:desktop ? 13 : 7,directoryGets:1,officialServiceTouched:false};
|
||||
} catch(error) {if(page)await shot('failure').catch(()=>{});result={success:false,appRoot,actualElectron:desktop,checks,screenshots,errors,error:error.stack,realModelRequests:0};}
|
||||
finally {if(application)await application.close();if(browser)await browser.close();if(controller&&await controller.health())await controller.stop();await host?.close?.();for(const dispose of disposers.reverse())await dispose();fs.writeFileSync(path.join(directory,'result.json'),JSON.stringify(result,null,2));}
|
||||
console.log(JSON.stringify({directory,...result}));if(!result.success)process.exitCode=1;
|
||||
Reference in New Issue
Block a user