Files
Agent-Workbench/docs/model-protocols-f-release-evidence/110-run-protocol-phase.mjs
T
2026-11-01 00:19:52 +08:00

53 lines
4.5 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
import { createHash } from 'node:crypto';
import { projectEnvironment } from '../src/core/process-environment.mjs';
const hash = bytes => createHash('sha256').update(bytes).digest('hex');
const phase = process.argv[2];
const python = 'D:/Ai-project/REA逆向/Agent-Workbench/.qa/dev-task-plans/.qa/python-3.10/Scripts/python.exe';
const release = JSON.parse(fs.readFileSync('releases/latest.json', 'utf8'));
const choices = {
archives: { executable: python, args: ['scripts/verify-archives.py', '--extract-source'], pointer: '.qa/archives-validation.json' },
source: { args: ['scripts/verify-source-package.mjs', '--native-engines'], pointer: '.qa/source-package-validation.json' },
'source-retry': { args: ['scripts/verify-source-package.mjs', '--native-engines'], pointer: '.qa/source-package-validation.json' },
portable: { args: ['scripts/verify-release.mjs', '--native-engines'], pointer: '.qa/release-validation.json' },
'portable-companion': { args: ['scripts/verify-companion-ui.mjs', '--app-root', release.portableRoot] },
'portable-protocols': { args: ['scripts/verify-model-protocols-ui.mjs', '--app-root', release.portableRoot] },
'prepare-install': { args: ['.qa/prepare-protocol-installer.mjs'] },
install: { args: ['.qa/verify-protocol-install.mjs'] },
'formal-stage': { args: ['.qa/deploy-protocol-formal.mjs', 'stage'] },
'formal-upgrade': { args: ['.qa/deploy-protocol-formal.mjs', 'upgrade'] },
'formal-activate': { args: ['.qa/deploy-protocol-formal.mjs', 'activate'] },
'formal-verify': { args: ['.qa/deploy-protocol-formal.mjs', 'verify'] },
'formal-ui': { args: ['.qa/verify-protocol-formal-ui.mjs'] },
'formal-artifacts': { args: ['.qa/verify-protocol-formal-artifacts.mjs', '.qa/protocol-f-formal-verify.json', '.qa/protocol-f-formal-artifacts.json'] },
seal: { args: ['.qa/seal-protocol-release.mjs'] },
'seal-retry': { args: ['.qa/seal-protocol-release.mjs'] },
};
const choice = choices[phase]; assert.ok(choice, 'Select a defined isolated acceptance phase.');
const prefix = '.qa/protocol-f-' + phase, logPath = prefix + '.log', receiptPath = prefix + '-result.json';
for (const file of [logPath, receiptPath]) assert.equal(fs.existsSync(file), false, 'Keep existing evidence: ' + file);
const baseline = JSON.parse(fs.readFileSync('docs/model-protocols-release-code-baseline.json', 'utf8'));
function unchanged() { for (const item of [...baseline.inputs, ...baseline.builds, ...baseline.benchmarks]) { const bytes = fs.readFileSync(item.path); assert.equal(bytes.length, item.bytes, item.path); assert.equal(hash(bytes), item.sha256, item.path); } }
unchanged();
const startedAt = new Date().toISOString(), log = fs.createWriteStream(logPath, { flags: 'wx' });
const env = projectEnvironment({ PATH: path.dirname(process.execPath) + path.delimiter + process.env.PATH, AGENT_WORKBENCH_TEST_PYTHON: python,
AGENT_WORKBENCH_ARCHIVE_QA_ROOT: 'D:/AWQA17',
AGENT_WORKBENCH_DEEPSEEK_ROOT: 'D:/Ai-project/DeepSeek-Harness-Desktop/deepseek-harness',
AGENT_WORKBENCH_PURGE_ROOT: 'D:/Ai-project/DeepSeek-Harness-Desktop/plugins/dsh-purge' });
const child = spawn(choice.executable || process.execPath, choice.args, { cwd: process.cwd(), env, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
child.stdout.on('data', bytes => log.write(bytes)); child.stderr.on('data', bytes => log.write(bytes));
const exitCode = await new Promise((resolve, reject) => { child.once('error', reject); child.once('close', resolve); });
await new Promise(resolve => log.end(resolve));
let pointer = null;
if (choice.pointer && fs.existsSync(choice.pointer)) { const bytes = fs.readFileSync(choice.pointer); pointer = { path: choice.pointer, sha256: hash(bytes) }; fs.writeFileSync(prefix + '-original-validation.json', bytes, { flag: 'wx' }); }
let unchangedInputs = true, error;
try { unchanged(); } catch (failure) { unchangedInputs = false; error = failure.stack; }
const receipt = { success: exitCode === 0 && unchangedInputs, phase, startedAt, finishedAt: new Date().toISOString(), exitCode, logPath,
logBytes: fs.statSync(logPath).size, logSha256: hash(fs.readFileSync(logPath)), pointer, unchangedInputs,
codeCommit: baseline.codeCommit, release: { portableRoot: release.portableRoot, sourceRoot: release.sourceRoot, setupSha256: release.installer.sha256 }, ...(error ? { error } : {}) };
fs.writeFileSync(receiptPath, JSON.stringify(receipt, null, 2) + '\n', { flag: 'wx' });
console.log(JSON.stringify(receipt)); if (!receipt.success) process.exitCode = 1;