feat: add task-bound real browser checks and verified page delivery

This commit is contained in:
Agent Workbench Dev
2026-10-30 08:46:53 +08:00
parent 29a65760c9
commit 5921b8efdc
78 changed files with 4563 additions and 76 deletions
+15
View File
@@ -11,6 +11,8 @@ import { DeliveryReporter, verifiedCheck } from './delivery-report.mjs';
import { pendingDeliveryReview, resolveDeliveryReview } from '../shared/contracts/delivery-review.mjs';
import { assertWorkspacesResolved } from '../shared/contracts/workspaces.mjs';
import { verifyWorkspaceProject } from './workspaces/git-workspaces.mjs';
import { currentBrowserVerification } from './browser/browser-manager.mjs';
import { assertBrowserResolved } from '../shared/contracts/browser.mjs';
const at = () => new Date().toISOString();
const sha = value => createHash('sha256').update(value).digest('hex');
@@ -215,6 +217,9 @@ export class GitDelivery {
check.sourceFingerprint = inspection.sourceFingerprint;
task.verification = { ...task.verification, sourceFingerprint: inspection.sourceFingerprint };
}
assertBrowserResolved(this.store, session.projectId);
const browser = await currentBrowserVerification(this.store, session, inspection);
if (browser.required && browser.status !== 'passed') throw conflict('本任务已配置页面验收,请先取得当前源码与构建的实际浏览器断言通过记录。');
const files = await this.selectedFiles(session, project, snapshot);
const name = options.authorName ?? snapshot.config['user.name'] ?? 'Agent Workbench';
const email = options.authorEmail ?? snapshot.config['user.email'] ?? 'local@agent-workbench.invalid';
@@ -228,6 +233,7 @@ export class GitDelivery {
const plan = { id: randomUUID(), sessionId: session.id, projectId: session.projectId, taskId: task.id, runId: run.id, status: 'planned', createdAt: at(),
message, author, files, paths: files.map(file => file.path), snapshot, preparedBy: source, fingerprint: inspection.fingerprint, sourceFingerprint: inspection.sourceFingerprint,
checkJobId: check.id, checkSummary: check.results.map(value => ({ name: value.name, command: value.command, exitCode: value.exitCode, tests: value.tests, logArtifactId: value.logArtifactId })),
...(browser.required ? { browserJobId: browser.jobId, browserPlanId: browser.planId, browserBuildSha256: browser.buildSha256 } : {}),
protectedIndexSha256: protectedIndex(snapshot.stage, snapshot.flags, files.map(file => file.path)), diffArtifactId: diffArtifact.id,
policy: { name: 'local-reviewed-snapshot', hooks: 'disabled', signing: 'unsigned', remote: 'none',
note: '工作台生成本地普通提交,保留其他暂存与工作区改动;本次不执行仓库hooks和GPG签名。' } };
@@ -278,6 +284,13 @@ export class GitDelivery {
await this.faultInjector?.(phase, job);
}
async verifyBrowserDelivery(session, plan, inspection) {
assertBrowserResolved(this.store, session.projectId);
const browser = await currentBrowserVerification(this.store, session, inspection);
if (browser.required && (browser.status !== 'passed' || browser.jobId !== plan.browserJobId || browser.buildSha256 !== plan.browserBuildSha256)
|| !browser.required && plan.browserJobId) throw conflict('页面验收在Git预览后变化或已失效,请重新验证并准备交付。');
}
async execute(session, plan, job, signal) {
const project = this.store.project(session.projectId);
let lockOwned = false, keepLock = false;
@@ -287,6 +300,7 @@ export class GitDelivery {
signal.throwIfAborted();
if (session.taskId !== plan.taskId || session.runId !== plan.runId || snapshot.digest !== plan.snapshot.digest || inspection.fingerprint !== plan.fingerprint) throw conflict('提交预览后工程、Git索引或Task/Run已变化,没有执行提交。');
if (!verifiedCheck(this.store, session, inspection)) throw conflict('提交前检查证据已失效,请重新运行工程检查。');
await this.verifyBrowserDelivery(session, plan, inspection);
const selected = await this.selectedFiles(session, project, snapshot);
if (JSON.stringify(selected) !== JSON.stringify(plan.files)) throw conflict('当前文件与已审核提交清单不一致。');
signal.throwIfAborted();
@@ -372,6 +386,7 @@ export class GitDelivery {
if (actualRef !== plan.snapshot.reference || digestFile(job.indexPath) !== job.indexBeforeSha256) throw conflict('Git锁定后当前分支或索引与提交计划不同,未发布提交。');
const inspection = await inspectProject(project);
if (inspection.sourceFingerprint !== plan.sourceFingerprint || !verifiedCheck(this.store, session, inspection)) throw conflict('Git锁定后源码或实际检查已经变化,未发布提交。');
await this.verifyBrowserDelivery(session, plan, inspection);
await this.checkpoint(session, job, 'ref_prepared');
signal.throwIfAborted();
job.status = 'publishing'; job.referenceAttempted = true;