Verification ran git inside the tree under test, kept no command output and treated every infrastructure fault as a test failure; repairs went through an executor lease the coordinator should not hold; and a project without delivery could never succeed. This reworks the worker execution path and the control-plane contracts it depends on. - Verification exports the exact commit to a directory without .git, installs dependencies (network allowed) and runs the protected commands under bubblewrap in kata mode or directly in host mode; evidence records exit code, duration, digest, a redacted output tail and the isolation used. Production rejects host evidence. A failed installation waits as infrastructure. - Waiting reasons are an enum with a redacted detail; dispatcher, GitHub and model-proxy states map onto it, and the console explains each one with a way out. - Repairs are requested by the coordinator through /internal/runs/:id/repair; the control plane derives the failure summary from the verifier's evidence and enforces the repair budget. Continuing after the budget is spent grants one more round; a new requirement revision starts a fresh budget. - Execution identities may only move a run within their own stages and only to running or waiting; success comes from integration evidence (no delivery configured) or deployment acceptance. The unused preview stage is gone. - Integration fast-forwards when the target has not moved, merges and re-verifies otherwise, retries when a push finds the target moved, and turns merge conflicts into a repair round that merges the current target for the agent to resolve. - Successful runs that needed a repair leave a project lesson; active lessons are injected into later prompts, and admins can list, add, disable and delete them. - Executor progress (messages, commands, file changes, plan updates) is stored as normalized events; previously agent messages were recorded as the literal word "output". Provider failures keep the work as a checkpoint and wait as provider_error instead of failing the run. - Workers declare WF_SANDBOX_MODE=host|kata (host refused in production), heartbeat with retries until the lease could have expired, and retry safe control-plane reads with backoff. - tests/local-loop.test.ts runs the loop end to end with real Git, the in-process control plane behind its internal routes and a scripted agent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
80 lines
2.9 KiB
TypeScript
80 lines
2.9 KiB
TypeScript
import type { Actor, Evidence } from '@wishforge/contracts';
|
|
import type { ControlPlane } from '../../apps/api/src/domain/control-plane.js';
|
|
import { digest } from '../../apps/api/src/domain/policy.js';
|
|
|
|
/**
|
|
* Takes a run the way the workers do (implementation, independent verification,
|
|
* integration under the project lease, then the image build) and returns the evidence a
|
|
* release needs. The project must have a delivery configuration.
|
|
*/
|
|
export async function deliverable(
|
|
control: ControlPlane,
|
|
tenantId: string,
|
|
runId: string,
|
|
options: {
|
|
commit?: string;
|
|
image?: string;
|
|
commands?: string[][];
|
|
verificationProfileDigest?: string;
|
|
targetBranch?: string;
|
|
} = {},
|
|
): Promise<{ verification: Evidence; build: Evidence }> {
|
|
const worker: Actor = { tenantId, userId: 'worker', role: 'admin', kind: 'worker' };
|
|
const verifier: Actor = { tenantId, userId: 'verifier', role: 'admin', kind: 'verifier' };
|
|
const sourceCommit = options.commit ?? 'a'.repeat(40);
|
|
let run = await control.lease(worker, runId, 'executor');
|
|
let leaseToken = run.lease!.token;
|
|
const order = ['clarify', 'plan', 'implement', 'verify'] as const;
|
|
for (const stage of order.slice(order.indexOf(run.stage as (typeof order)[number]) + 1))
|
|
run = await control.transition(worker, runId, {
|
|
leaseToken,
|
|
stage,
|
|
status: 'running',
|
|
message: `Fixture ${stage}`,
|
|
});
|
|
await control.releaseLease(worker, runId, leaseToken);
|
|
run = await control.lease(verifier, runId, 'verifier');
|
|
leaseToken = run.lease!.token;
|
|
const evidence = (body: Record<string, unknown>) =>
|
|
control.evidence(verifier, {
|
|
runId,
|
|
revision: run.revision,
|
|
leaseToken,
|
|
sourceCommit,
|
|
...(options.verificationProfileDigest ? { verificationProfileDigest: options.verificationProfileDigest } : {}),
|
|
...body,
|
|
});
|
|
const verification = await evidence({
|
|
type: 'verification',
|
|
passed: true,
|
|
isolation: 'sandbox',
|
|
commands: (options.commands ?? [['node', '--test']]).map(argv => ({
|
|
argv,
|
|
exitCode: 0,
|
|
outputDigest: digest('passed'),
|
|
})),
|
|
});
|
|
const lease = await control.integration.acquire(verifier, runId, leaseToken);
|
|
await control.transition(verifier, runId, {
|
|
leaseToken,
|
|
stage: 'integrate',
|
|
status: 'running',
|
|
message: 'Fixture integrate',
|
|
});
|
|
await evidence({ type: 'integration', passed: true, targetRef: `refs/heads/${options.targetBranch ?? 'main'}` });
|
|
await control.transition(verifier, runId, {
|
|
leaseToken,
|
|
stage: 'build',
|
|
status: 'running',
|
|
message: 'Fixture build',
|
|
});
|
|
const build = await evidence({
|
|
type: 'build',
|
|
passed: true,
|
|
imageDigest: options.image ?? `registry.example/catalog@sha256:${sourceCommit.slice(0, 1).repeat(64)}`,
|
|
});
|
|
await control.integration.release(verifier, runId, leaseToken, lease.fence);
|
|
await control.releaseLease(verifier, runId, leaseToken);
|
|
return { verification, build };
|
|
}
|