🔒 Weigh a release by everything its environment does not run yet
A release's risk only counted what the target branch gained when the run integrated. Commits people pushed to the branch directly, and integrations that were never deployed, went out with the next release without being classified: an environment preauthorized for automatic release took a migration or a Dockerfile change pushed straight to the branch without approval. The POC chose what to rebuild from the same narrow diff, so worker and coordinator kept running old code; on the local POC, WishForge had in fact only ever rebuilt the api. The control plane now gives the verifier the commit of the release the environment runs, and the classification covers everything between it and the release, as well as what the integration brought. On the POC, each deployment records the commit and the image a release put there. The build plans from that snapshot, the one the release is checked against: worker and coordinator keep their images only while what they run differs from the source in web files alone. A component of unknown source (never deployed by a release, restored by a rollback, or set by hand, which leaves the annotations stale) is rebuilt, and the release is marked partial: it needs approval and does not roll back on its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8b2a8ca4fe
commit
6722319314
@ -1056,6 +1056,11 @@ export class ControlPlane {
|
||||
['awaiting_approval', 'ready', 'deploying', 'unknown'].includes(r.status),
|
||||
);
|
||||
const deliveryConfig = project.deliveryConfig as { environmentId?: string } | undefined;
|
||||
const environmentId = release?.environmentId ?? deliveryConfig?.environmentId;
|
||||
const environment = environmentId ? await tx.get<Environment>('environment', environmentId) : undefined;
|
||||
const live = environment?.currentReleaseId
|
||||
? await tx.get<Release>('release', environment.currentReleaseId)
|
||||
: undefined;
|
||||
// Test and build evidence count only under the protected policy they were recorded with, as
|
||||
// a release requires; after the policy changes, the run verifies again instead of stalling.
|
||||
const policy = verificationPolicyDigest(project);
|
||||
@ -1078,8 +1083,12 @@ export class ControlPlane {
|
||||
release,
|
||||
verificationEvidenceId: current('verification'),
|
||||
buildEvidenceId: current('build'),
|
||||
environmentId: release?.environmentId ?? deliveryConfig?.environmentId,
|
||||
environmentId,
|
||||
integrationBaseCommit: evidence.find(e => e.type === 'integration')?.targetCommit,
|
||||
// What the environment runs now: a release's risk covers everything since, including
|
||||
// commits people pushed to the target branch directly.
|
||||
deployedCommit:
|
||||
live?.status === 'healthy' && live.projectId === run.projectId ? live.sourceCommit : undefined,
|
||||
},
|
||||
};
|
||||
});
|
||||
@ -1112,6 +1121,7 @@ export class ControlPlane {
|
||||
changedPaths: string[];
|
||||
migration: boolean;
|
||||
permissionsExpanded: boolean;
|
||||
partial?: boolean;
|
||||
},
|
||||
) {
|
||||
if (actor.kind !== 'verifier') throw new DomainError('FORBIDDEN', 'Independent verifier required', 403);
|
||||
@ -1134,6 +1144,7 @@ export class ControlPlane {
|
||||
changedPaths: [...new Set([...previous.changedPaths, ...classification.changedPaths])],
|
||||
migration: previous.migration || classification.migration,
|
||||
permissionsExpanded: previous.permissionsExpanded || classification.permissionsExpanded,
|
||||
partial: !!(previous.partial || classification.partial),
|
||||
}
|
||||
: classification;
|
||||
await tx.put('checkpoint', touch(cp));
|
||||
|
||||
@ -34,12 +34,14 @@ export function releaseRisk(input: {
|
||||
changedPaths?: string[];
|
||||
migration?: boolean;
|
||||
permissionsExpanded?: boolean;
|
||||
partial?: boolean;
|
||||
evidenceComplete: boolean;
|
||||
preauthorized: boolean;
|
||||
}) {
|
||||
const reasons: string[] = [];
|
||||
if (!input.evidenceComplete) reasons.push('Missing trusted change classification');
|
||||
if (!input.preauthorized) reasons.push('Environment is not preauthorized for automatic release');
|
||||
if (input.partial) reasons.push('The environment runs code of unknown source; not every change could be classified');
|
||||
if (input.migration) reasons.push('Database migration');
|
||||
if (input.permissionsExpanded) reasons.push('Permission expansion');
|
||||
for (const path of input.changedPaths ?? []) {
|
||||
|
||||
@ -292,7 +292,13 @@ export class Releases {
|
||||
? await tx.get<CheckpointRecord>('checkpoint', run.checkpointId)
|
||||
: undefined;
|
||||
const classification = checkpoint?.trustedClassification as
|
||||
| { changedPaths: string[]; migration: boolean; permissionsExpanded: boolean; sourceCommit: string }
|
||||
| {
|
||||
changedPaths: string[];
|
||||
migration: boolean;
|
||||
permissionsExpanded: boolean;
|
||||
partial?: boolean;
|
||||
sourceCommit: string;
|
||||
}
|
||||
| undefined;
|
||||
const riskReasons = releaseRisk({
|
||||
...classification,
|
||||
|
||||
@ -121,6 +121,7 @@ const classificationBody = z
|
||||
changedPaths: z.array(z.string().min(1).max(4096)).max(10000),
|
||||
migration: z.boolean(),
|
||||
permissionsExpanded: z.boolean(),
|
||||
partial: z.boolean().optional(),
|
||||
})
|
||||
.strict();
|
||||
const meterBody = z
|
||||
|
||||
@ -56,6 +56,8 @@ export interface RunContext {
|
||||
environmentId?: string;
|
||||
/** The target branch commit the run integrated onto. */
|
||||
integrationBaseCommit?: string;
|
||||
/** The commit of the release the environment runs now, if any. */
|
||||
deployedCommit?: string;
|
||||
};
|
||||
}
|
||||
export interface ActivityOutcome {
|
||||
|
||||
@ -11,6 +11,8 @@ import {
|
||||
executeCommand,
|
||||
isolatedVerifierExecutor,
|
||||
MergeConflictError,
|
||||
pocComponentNames,
|
||||
pocComponentsToBuild,
|
||||
RuntimeError,
|
||||
safeIdentifier,
|
||||
validateVerificationProfile,
|
||||
@ -343,31 +345,74 @@ async function candidateFor(
|
||||
return { candidate, expected };
|
||||
}
|
||||
|
||||
/** What a release changes where it deploys. */
|
||||
interface ReleaseChanges {
|
||||
paths: string[];
|
||||
/** Part of what the environment runs is of unknown source, so `paths` may miss changes. */
|
||||
partial: boolean;
|
||||
/** The files that differ between a commit and the release; undefined when the repository lacks it. */
|
||||
since: (commit: string) => Promise<string[] | undefined>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Everything the release changes: what the target branch gained with this run, and whatever
|
||||
* differs from the commits the environment runs now, which takes in commits people pushed to the
|
||||
* branch directly and integrations that were never deployed.
|
||||
*/
|
||||
async function releaseChanges(
|
||||
session: Session,
|
||||
integrated: Verified,
|
||||
deployed: string[],
|
||||
unknown = false,
|
||||
): Promise<ReleaseChanges> {
|
||||
const { git } = session;
|
||||
const diffs = new Map<string, Promise<string[] | undefined>>();
|
||||
const since = (commit: string) => {
|
||||
if (!diffs.has(commit))
|
||||
diffs.set(
|
||||
commit,
|
||||
git
|
||||
.hasCommit(integrated.workspace, commit)
|
||||
.then(known => (known ? git.changedPaths(integrated.workspace, commit, integrated.commit) : undefined)),
|
||||
);
|
||||
return diffs.get(commit)!;
|
||||
};
|
||||
const paths = new Set(await git.changedPaths(integrated.workspace, integrated.baseCommit, integrated.commit));
|
||||
let partial = unknown;
|
||||
for (const commit of new Set(deployed)) {
|
||||
const changed = await since(commit);
|
||||
if (!changed) partial = true;
|
||||
for (const file of changed ?? []) paths.add(file);
|
||||
}
|
||||
return { paths: [...paths].sort(), partial, since };
|
||||
}
|
||||
|
||||
/** Records what the release changes; the control plane weighs the release's risk from it. */
|
||||
async function classify(session: Session, integrated: Verified, changes: ReleaseChanges) {
|
||||
await session.keeper.ensure();
|
||||
await session.api.request(`/internal/runs/${session.input.runId}/classification`, {
|
||||
leaseToken: session.leaseToken,
|
||||
sourceCommit: integrated.commit,
|
||||
changedPaths: changes.paths,
|
||||
migration: integrated.migrationRequired || changes.paths.some(file => /(^|\/)migrations?(\/|$)/i.test(file)),
|
||||
permissionsExpanded: changes.paths.some(file => /(^|\/)(security|auth|infra)(\/|$)/i.test(file)),
|
||||
partial: changes.partial,
|
||||
});
|
||||
await session.keeper.ensure();
|
||||
}
|
||||
|
||||
/** Builds the integrated commit when the project delivers; otherwise the integration completed the run. */
|
||||
async function deliver(session: Session, integrated: Verified): Promise<ActivityOutcome> {
|
||||
const delivery = session.context.project.deliveryConfig;
|
||||
if (!delivery) return { status: 'complete' };
|
||||
if (session.run.stage !== 'build')
|
||||
await session.transition('build', `Integrated ${short(integrated.commit)}; building an immutable image`);
|
||||
const changedPaths = await session.git.changedPaths(integrated.workspace, integrated.baseCommit, integrated.commit);
|
||||
await session.keeper.ensure();
|
||||
await session.api.request(`/internal/runs/${session.input.runId}/classification`, {
|
||||
leaseToken: session.leaseToken,
|
||||
sourceCommit: integrated.commit,
|
||||
changedPaths,
|
||||
migration: integrated.migrationRequired || changedPaths.some(file => /(^|\/)migrations?(\/|$)/i.test(file)),
|
||||
permissionsExpanded: changedPaths.some(file => /(^|\/)(security|auth|infra)(\/|$)/i.test(file)),
|
||||
});
|
||||
await session.keeper.ensure();
|
||||
const deployed = session.context.delivery?.deployedCommit;
|
||||
const localPoc = localPocForProject(readLocalPocBinding(session.config.localPocBindingFile), session.context.project);
|
||||
if (localPoc) {
|
||||
if (session.config.sandboxMode !== 'host' || delivery.environmentId !== localPoc.environmentId)
|
||||
throw new RuntimeError('LOCAL_POC_POLICY', 'POC delivery requires its bound local execution and environment');
|
||||
const profile = await loadPocProfile(localPoc.profileFile);
|
||||
// Shared server/internal changes rebuild the coherent set. Web-only changes retain the two existing consumers.
|
||||
const apiOnly = changedPaths.every(file =>
|
||||
/^(src\/|tests\/frontend\/|tools\/drosync\/Cargo\.(toml|lock)$)/.test(file),
|
||||
);
|
||||
const { release, evidence } = await buildPocRelease(
|
||||
{
|
||||
profile,
|
||||
@ -375,10 +420,28 @@ async function deliver(session: Session, integrated: Verified): Promise<Activity
|
||||
sourceCommit: integrated.commit,
|
||||
releaseId: `run-${session.input.runId}-${session.leaseToken}`,
|
||||
stateDirectory: localPoc.stateDirectory,
|
||||
components: apiOnly ? ['api'] : ['api', 'worker', 'coordinator'],
|
||||
rollbackCompatible:
|
||||
!integrated.migrationRequired &&
|
||||
!changedPaths.some(file => /(^|\/)(migrations?|store|auth|security)(\/|$)/i.test(file)),
|
||||
// The components can run different commits. The cluster says which, in the snapshot the
|
||||
// release is later checked against; the risk and what to build follow from them.
|
||||
plan: async running => {
|
||||
const commits = Object.values(running).filter((commit): commit is string => !!commit);
|
||||
const changes = await releaseChanges(
|
||||
session,
|
||||
integrated,
|
||||
deployed ? [deployed, ...commits] : commits,
|
||||
pocComponentNames.some(component => !running[component]),
|
||||
);
|
||||
await classify(session, integrated, changes);
|
||||
const { components, reasons } = await pocComponentsToBuild(running, changes.since);
|
||||
for (const [component, reason] of Object.entries(reasons))
|
||||
await session.transition('build', `Building ${component} too: ${reason}`);
|
||||
return {
|
||||
components,
|
||||
rollbackCompatible:
|
||||
!changes.partial &&
|
||||
!integrated.migrationRequired &&
|
||||
!changes.paths.some(file => /(^|\/)(migrations?|store|auth|security)(\/|$)/i.test(file)),
|
||||
};
|
||||
},
|
||||
signal: session.keeper.signal,
|
||||
onProgress: message => session.transition('build', message).then(() => undefined),
|
||||
// A flaky link to the cluster shows in the timeline instead of only as a slow build.
|
||||
@ -401,6 +464,7 @@ async function deliver(session: Session, integrated: Verified): Promise<Activity
|
||||
environmentId: delivery.environmentId,
|
||||
};
|
||||
}
|
||||
await classify(session, integrated, await releaseChanges(session, integrated, deployed ? [deployed] : []));
|
||||
const image = await buildDockerImage(
|
||||
{
|
||||
workspace: integrated.workspace,
|
||||
|
||||
@ -236,7 +236,7 @@ sequenceDiagram
|
||||
```
|
||||
|
||||
- 发布绑定 commit、镜像 digest、架构、环境、配置版本、密钥版本引用、验证策略摘要与证据 ID;任一项变化都会使审批失效。
|
||||
- 风险由后端根据验证器上报的可信变更事实计算:受保护路径、数据迁移、权限扩大、生产环境。
|
||||
- 风险由后端根据验证器上报的可信变更事实计算:受保护路径、数据迁移、权限扩大、生产环境。变更范围是「环境当前运行的提交」到这次发布之间的全部差异,加上目标分支在本次合入中得到的改动,因此有人直接推到目标分支、或合入后从未部署过的提交,也会计入。环境运行的代码来源不明(提交不在仓库中,或本机 POC 的组件不是由发布部署的)时,分类标记为不完整,发布必须人工审批。
|
||||
- 部署失败保留旧版本,环境锁随失败回执释放,运行回到等待,继续即可重新请求发布;结果未知时 Runner 先读回目标状态再回报(`reconcile`),仍无法确定时 owner/admin 在核对目标后解锁环境。回滚同样处理:Runner 回报回滚失败(当前版本继续服务)时释放环境;结果未知的回滚可以由 owner/admin 核对后解锁,回滚操作随之作废。
|
||||
- Runner 拉取任务时,跳过已经失效的就绪发布(运行取消、需求或代码变化、配置或审批失效),把它标记为失败并让对应运行回到等待,后面的发布照常部署;运行暂停中的就绪发布保留,继续运行后可能重新有效。
|
||||
- 审批 24 小时内有效;过期后发布失败,运行可以继续并重新请求发布。
|
||||
|
||||
@ -120,7 +120,10 @@ LaunchAgent 随当前用户登录运行,退出登录后停止;电脑关机
|
||||
|
||||
本机到 POC 集群 API 的连接不稳定时(例如经 Wi‑Fi 或企业网络客户端),构建与发布会自动重试没有得到应答的请求:读取最多试 6 次,间隔 2 至 30 秒;上传源码失败会重传,解压可安全重复;`rollout status` 断开后在发布时限内接着观察;发布后的公网检查(健康、就绪、首页、API 的构建提交和受保护业务检查)也各试 6 次,间隔 2 至 10 秒,因为滚动更新刚结束时公网入口可能还连到正在退出的旧 Pod。每次重试都有记录:构建时写进运行时间线,发布时写进 `runner.log`。连接中断超过这些重试时,运行仍停在「基础设施」等待,网络恢复后在网页上继续即可。可以用 `kubectl --kubeconfig <POC kubeconfig> --request-timeout=5s get --raw /readyz` 反复探测这条链路。
|
||||
|
||||
## 有人直接改 `poc` 分支时
|
||||
## 有人直接改 `poc` 分支或 POC 集群时
|
||||
|
||||
- 运行实现期间有人推了 `poc`:合入时 Claude 的提交合并到最新的 `poc` 上,合并结果重新跑一遍受保护检查后才推送;冲突按修复轮处理。
|
||||
- 运行合入之后有人推了 `poc`:构建照常进行,构建的是这个运行合入的提交,时间线会说明 `poc` 已经前进;更新的提交由之后的运行部署。只有 `poc` 被强推、不再包含这个提交时,运行才停在「仓库」等待(`POC_SOURCE_REWRITTEN`),这时取消运行,需要的话重新提交愿望。不要强推 `poc`:进行中的运行合入时会把删掉的提交重新带回来。
|
||||
- 发布的风险按「POC 当前运行的代码」到这次发布之间的全部变化计算,直接推到 `poc` 的改动同样会触发审批(迁移、鉴权、Dockerfile、依赖等)。
|
||||
- 每次发布在 Deployment 上记下组件镜像构建自哪个提交和镜像本身。构建前按这些记录逐个判断:worker、coordinator 运行的代码与本次源码之间只有网页文件不同时沿用原镜像,否则重新构建。没有记录、记录已被回滚覆盖、或镜像被人用 `kubectl set image` 改过的组件视为来源不明:会重新构建,并且这次发布必须人工审批、不自动回滚。
|
||||
- 因此升级到这个版本后的第一次 POC 发布会重建全部三个组件,并等待一次人工审批:此前 WishForge 只重建过 api,worker 和 coordinator 仍运行接入 POC 之前的镜像。
|
||||
|
||||
@ -38,6 +38,8 @@ export interface TrustedClassification {
|
||||
changedPaths: string[];
|
||||
migration: boolean;
|
||||
permissionsExpanded: boolean;
|
||||
/** Part of what the environment runs is of unknown source, so the changes since are not all known. */
|
||||
partial?: boolean;
|
||||
}
|
||||
|
||||
/** A portable checkpoint as stored for a run; `checkpoint` is the worker's PortableCheckpoint. */
|
||||
|
||||
@ -279,6 +279,11 @@ export class GitWorkspace {
|
||||
if (ref !== 'HEAD') requireTargetRef(ref);
|
||||
return requireCommit(await this.git(repository, ['rev-parse', '--verify', `${ref}^{commit}`]));
|
||||
}
|
||||
async hasCommit(repository: string, commit: string): Promise<boolean> {
|
||||
requireCommit(commit);
|
||||
const result = await this.execute(this.command(repository, ['cat-file', '-e', `${commit}^{commit}`]));
|
||||
return result.exitCode === 0;
|
||||
}
|
||||
async changedPaths(workspace: string, baseCommit: string, sourceCommit: string): Promise<string[]> {
|
||||
requireCommit(baseCommit);
|
||||
requireCommit(sourceCommit);
|
||||
|
||||
@ -14,7 +14,14 @@ import {
|
||||
type PocImages,
|
||||
type PocRelease,
|
||||
} from './poc-release.js';
|
||||
import { pocComponents, pocComponentNames, profileDigest, type PocProfile, type PocComponent } from './poc-profile.js';
|
||||
import {
|
||||
pocApiOnlyPath,
|
||||
pocComponents,
|
||||
pocComponentNames,
|
||||
profileDigest,
|
||||
type PocProfile,
|
||||
type PocComponent,
|
||||
} from './poc-profile.js';
|
||||
import { pocReleaseDigest } from './poc-runner.js';
|
||||
|
||||
export interface PocBuildEvidence {
|
||||
@ -30,6 +37,10 @@ export interface PocBuildEvidence {
|
||||
retainedImages: Partial<PocImages>;
|
||||
bundleDigest: string;
|
||||
}
|
||||
export interface PocBuildPlan {
|
||||
components: PocComponent[];
|
||||
rollbackCompatible: boolean;
|
||||
}
|
||||
export interface PocBuildInput {
|
||||
profile: PocProfile;
|
||||
workspace: string;
|
||||
@ -38,12 +49,57 @@ export interface PocBuildInput {
|
||||
stateDirectory: string;
|
||||
components?: PocComponent[];
|
||||
rollbackCompatible?: boolean;
|
||||
/**
|
||||
* Decides what to build from the commit each component runs now (absent when unknown), read in
|
||||
* the snapshot the release later checks the cluster against; replaces the two settings above.
|
||||
*/
|
||||
plan?: (running: Partial<Record<PocComponent, string>>) => Promise<PocBuildPlan>;
|
||||
signal?: AbortSignal;
|
||||
onProgress?: (message: string) => void | Promise<void>;
|
||||
/** How often to repeat requests the cluster API leaves unanswered, and whom to tell. */
|
||||
patience?: Patience;
|
||||
}
|
||||
|
||||
/**
|
||||
* The api is always built. Worker and coordinator keep their images while the commit those were
|
||||
* built from differs from the source in web files alone; one of unknown source, or built from a
|
||||
* commit the repository does not have, is built again. Says why each of them is built.
|
||||
*/
|
||||
export async function pocComponentsToBuild(
|
||||
running: Partial<Record<PocComponent, string>>,
|
||||
changedSince: (commit: string) => Promise<string[] | undefined>,
|
||||
): Promise<{ components: PocComponent[]; reasons: Partial<Record<PocComponent, string>> }> {
|
||||
const components: PocComponent[] = ['api'];
|
||||
const reasons: Partial<Record<PocComponent, string>> = {};
|
||||
for (const component of pocComponentNames) {
|
||||
if (component === 'api') continue;
|
||||
const commit = running[component];
|
||||
let reason: string | undefined;
|
||||
if (!commit) reason = 'what it runs is of unknown source';
|
||||
else {
|
||||
const changed = await changedSince(commit);
|
||||
const file = changed?.find(path => !pocApiOnlyPath(path));
|
||||
if (!changed) reason = `it runs ${commit.slice(0, 12)}, which the repository does not have`;
|
||||
else if (file) reason = `${file} changed since ${commit.slice(0, 12)}, which it runs`;
|
||||
}
|
||||
if (reason) {
|
||||
components.push(component);
|
||||
reasons[component] = reason;
|
||||
}
|
||||
}
|
||||
return { components, reasons };
|
||||
}
|
||||
|
||||
function requireComponents(components: PocComponent[]) {
|
||||
if (
|
||||
!components.length ||
|
||||
new Set(components).size !== components.length ||
|
||||
components.some(c => !pocComponentNames.includes(c))
|
||||
)
|
||||
throw Error('Invalid POC build components');
|
||||
return components;
|
||||
}
|
||||
|
||||
interface BuildPod {
|
||||
metadata: { uid: string; labels?: Record<string, string> };
|
||||
status?: {
|
||||
@ -161,13 +217,7 @@ export async function buildPocRelease(
|
||||
requireCommit(input.sourceCommit);
|
||||
safeIdentifier(input.releaseId);
|
||||
if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(input.releaseId)) throw Error('Invalid POC release ID');
|
||||
const components = input.components ?? [...pocComponentNames];
|
||||
if (
|
||||
!components.length ||
|
||||
new Set(components).size !== components.length ||
|
||||
components.some(c => !pocComponentNames.includes(c))
|
||||
)
|
||||
throw Error('Invalid POC build components');
|
||||
if (input.components) requireComponents(input.components);
|
||||
const adapter = new PocDeploymentAdapter(
|
||||
input.profile,
|
||||
path.join(input.stateDirectory, 'deployments'),
|
||||
@ -223,6 +273,18 @@ export async function buildPocRelease(
|
||||
`poc has moved on to ${tip.slice(0, 12)}; building ${input.sourceCommit.slice(0, 12)}, which this run integrated, while the newer commits deploy with a later run`,
|
||||
);
|
||||
}
|
||||
const running: Partial<Record<PocComponent, string>> = {};
|
||||
for (const component of pocComponentNames) {
|
||||
const commit = baseline.deployments[component].sourceCommit;
|
||||
if (commit) running[component] = commit;
|
||||
}
|
||||
const plan = input.plan
|
||||
? await input.plan(running)
|
||||
: {
|
||||
components: input.components ?? [...pocComponentNames],
|
||||
rollbackCompatible: input.rollbackCompatible ?? false,
|
||||
};
|
||||
const components = requireComponents(plan.components);
|
||||
const archive = path.join(buildDirectory, 'source.tar.gz');
|
||||
await command('git', ['archive', '--format=tar.gz', `--output=${archive}`, input.sourceCommit]);
|
||||
if ((await stat(archive)).size > 512 * 1024 * 1024) throw Error('POC source archive exceeds 512 MiB');
|
||||
@ -360,7 +422,7 @@ export async function buildPocRelease(
|
||||
images,
|
||||
expectedImages: baseline.images,
|
||||
expectedTemplateDigests: baseline.templateDigests,
|
||||
rollbackCompatible: input.rollbackCompatible ?? false,
|
||||
rollbackCompatible: plan.rollbackCompatible,
|
||||
});
|
||||
evidence.completedAt = new Date().toISOString();
|
||||
evidence.bundleDigest = pocReleaseDigest(release);
|
||||
|
||||
@ -24,6 +24,9 @@ export const pocComponents = {
|
||||
repository: 'drosync-coordinator',
|
||||
},
|
||||
} as const;
|
||||
/** Web files, which only the api image includes; a change anywhere else may reach every component. */
|
||||
export const pocApiOnlyPath = (file: string) =>
|
||||
/^(src\/|tests\/frontend\/|tools\/drosync\/Cargo\.(toml|lock)$)/.test(file);
|
||||
|
||||
const absolutePath = z
|
||||
.string()
|
||||
|
||||
@ -61,7 +61,17 @@ interface Deployment {
|
||||
export interface PocSnapshot {
|
||||
images: PocImages;
|
||||
templateDigests: z.infer<typeof templateDigestSet>;
|
||||
deployments: Record<PocComponent, { uid: string; resourceVersion: string; generation: number; ready: boolean }>;
|
||||
deployments: Record<
|
||||
PocComponent,
|
||||
{
|
||||
uid: string;
|
||||
resourceVersion: string;
|
||||
generation: number;
|
||||
ready: boolean;
|
||||
/** The commit its image was built from, while it runs the image a release put there. */
|
||||
sourceCommit?: string;
|
||||
}
|
||||
>;
|
||||
}
|
||||
export type PocJournalState =
|
||||
'prepared' | 'applying' | 'verifying' | 'succeeded' | 'rolling_back' | 'rolled_back' | 'needs_reconciliation';
|
||||
@ -238,11 +248,17 @@ export class PocDeploymentAdapter {
|
||||
const item = await this.deployment(component);
|
||||
images[component] = digestImage.parse(this.image(component, item));
|
||||
templateDigests[component] = pocTemplateDigest(component, item);
|
||||
const annotations = item.spec.template.metadata?.annotations ?? {};
|
||||
const sourceCommit = annotations[`${annotationPrefix}/source-commit`] ?? '';
|
||||
deployments[component] = {
|
||||
uid: item.metadata.uid,
|
||||
resourceVersion: item.metadata.resourceVersion,
|
||||
generation: item.metadata.generation,
|
||||
ready: this.ready(item),
|
||||
// A person's `kubectl set image` leaves the annotations as they were; the image tells.
|
||||
...(/^[0-9a-f]{40}$/.test(sourceCommit) && annotations[`${annotationPrefix}/image`] === images[component]
|
||||
? { sourceCommit }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
return { images, templateDigests, deployments };
|
||||
@ -309,6 +325,7 @@ export class PocDeploymentAdapter {
|
||||
for (const [name, value] of Object.entries({
|
||||
'release-id': release.id,
|
||||
'source-commit': rollback ? 'unknown-restored-baseline' : release.sourceCommit,
|
||||
image: nextImage,
|
||||
'attempted-source-commit': release.sourceCommit,
|
||||
'profile-digest': release.profileDigest,
|
||||
operation: rollback ? 'rollback' : 'deploy',
|
||||
|
||||
@ -3,7 +3,7 @@ import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import { KubectlError, PocDeploymentAdapter, unanswered, writePocJson, type PocRelease } from '../src/poc-release.js';
|
||||
import { buildPocRelease, createPocBuildPod, type PocBuildInput } from '../src/poc-build.js';
|
||||
import { buildPocRelease, createPocBuildPod, pocComponentsToBuild, type PocBuildInput } from '../src/poc-build.js';
|
||||
import { PocRunnerDeploymentAdapter, pocReleaseDigest } from '../src/poc-runner.js';
|
||||
import type { ReleaseManifest } from '../src/types.js';
|
||||
import {
|
||||
@ -608,7 +608,13 @@ describe('the POC build and release on a flaky link to the cluster', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('what a POC build builds after people pushed to the branch', () => {
|
||||
describe('what a POC build builds after people changed the branch or the cluster', () => {
|
||||
/** Leaves a component as a release does: running `image`, built from `commit`. */
|
||||
const annotate = (item: any, commit: string, image: string) =>
|
||||
Object.assign(item.spec.template.metadata.annotations, {
|
||||
'wishforge.d-robotics.cc/source-commit': commit,
|
||||
'wishforge.d-robotics.cc/image': image,
|
||||
});
|
||||
it('builds what the run integrated after people pushed onto it, and says so', async () => {
|
||||
const c = await cluster();
|
||||
c.branch.tip = 'e'.repeat(40);
|
||||
@ -626,4 +632,62 @@ describe('what a POC build builds after people pushed to the branch', () => {
|
||||
await expect(c.build()).rejects.toMatchObject({ code: 'POC_SOURCE_REWRITTEN' });
|
||||
expect(c.count('create')).toBe(0);
|
||||
});
|
||||
it('knows what each component was built from, until its image changes', async () => {
|
||||
const f = await fixture();
|
||||
expect((await f.adapter.snapshot()).deployments.api.sourceCommit).toBeUndefined();
|
||||
await f.adapter.deploy(release());
|
||||
for (const c of pocComponentNames)
|
||||
expect((await f.adapter.snapshot()).deployments[c].sourceCommit).toBe('a'.repeat(40));
|
||||
// A person sets an image by hand: the annotations stay as they were, but no longer vouch for it.
|
||||
f.state.worker.spec.template.spec.containers[0].image = images('c').worker;
|
||||
expect((await f.adapter.snapshot()).deployments.worker.sourceCommit).toBeUndefined();
|
||||
// Restored by a rollback, a component runs an image of unknown source again.
|
||||
const g = await fixture();
|
||||
g.failures.loseReceipt = true;
|
||||
expect((await g.adapter.deploy(release())).state).toBe('rolled_back');
|
||||
expect(g.state.coordinator.spec.template.metadata.annotations['wishforge.d-robotics.cc/image']).toBe(
|
||||
images('a').coordinator,
|
||||
);
|
||||
expect((await g.adapter.snapshot()).deployments.coordinator.sourceCommit).toBeUndefined();
|
||||
});
|
||||
it('plans the build from what each component runs, in the snapshot the release is checked against', async () => {
|
||||
const c = await cluster();
|
||||
// The worker runs what a release built from b…; a person set the coordinator's image by hand since.
|
||||
annotate(c.state.worker, 'b'.repeat(40), images('a').worker);
|
||||
annotate(c.state.coordinator, 'b'.repeat(40), images('f').coordinator);
|
||||
let running: Partial<Record<PocComponent, string>> | undefined;
|
||||
const { release, evidence } = await c.build({
|
||||
components: undefined,
|
||||
plan: async seen => {
|
||||
running = seen;
|
||||
return { components: ['api', 'coordinator'], rollbackCompatible: true };
|
||||
},
|
||||
});
|
||||
expect(running).toEqual({ worker: 'b'.repeat(40) });
|
||||
expect(Object.keys(evidence.components).sort()).toEqual(['api', 'coordinator']);
|
||||
expect(evidence.retainedImages).toEqual({ worker: images('a').worker });
|
||||
expect(release).toMatchObject({ rollbackCompatible: true, expectedImages: images('a') });
|
||||
});
|
||||
it('builds worker and coordinator again unless they differ from the source in web files alone', async () => {
|
||||
const changed: Record<string, string[]> = {
|
||||
['1'.repeat(40)]: ['src/app.tsx', 'tests/frontend/app.test.ts'],
|
||||
['2'.repeat(40)]: ['src/app.tsx', 'internal/worker/run.go'],
|
||||
};
|
||||
const since = async (commit: string) => changed[commit];
|
||||
expect(await pocComponentsToBuild({ worker: '1'.repeat(40), coordinator: '1'.repeat(40) }, since)).toEqual({
|
||||
components: ['api'],
|
||||
reasons: {},
|
||||
});
|
||||
expect(await pocComponentsToBuild({ worker: '2'.repeat(40), coordinator: '3'.repeat(40) }, since)).toEqual({
|
||||
components: ['api', 'worker', 'coordinator'],
|
||||
reasons: {
|
||||
worker: `internal/worker/run.go changed since ${'2'.repeat(12)}, which it runs`,
|
||||
coordinator: `it runs ${'3'.repeat(12)}, which the repository does not have`,
|
||||
},
|
||||
});
|
||||
expect(await pocComponentsToBuild({}, since)).toEqual({
|
||||
components: ['api', 'worker', 'coordinator'],
|
||||
reasons: { worker: 'what it runs is of unknown source', coordinator: 'what it runs is of unknown source' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -5,7 +5,7 @@ import { ControlPlane } from '../apps/api/src/domain/control-plane.js';
|
||||
import { Connections } from '../apps/api/src/domain/connections.js';
|
||||
import { Releases } from '../apps/api/src/domain/releases.js';
|
||||
import { AgentBundles } from '../apps/api/src/domain/agent-bundles.js';
|
||||
import { digest } from '../apps/api/src/domain/policy.js';
|
||||
import { digest, releaseRisk } from '../apps/api/src/domain/policy.js';
|
||||
import { deliverable } from './helpers/delivery.js';
|
||||
|
||||
const owner: Actor = { tenantId: 'alpha', userId: 'owner', role: 'owner', kind: 'human' };
|
||||
@ -139,13 +139,14 @@ describe('tenant-scoped durable task invariants', () => {
|
||||
await tx.put('checkpoint', checkpoint);
|
||||
await tx.put('run', { ...run, checkpointId: checkpoint.id, verifiedCommit: commit });
|
||||
});
|
||||
const classify = (sourceCommit: string, changedPaths: string[], migration: boolean) =>
|
||||
const classify = (sourceCommit: string, changedPaths: string[], migration: boolean, partial = false) =>
|
||||
control.classify(verifier, runId, {
|
||||
leaseToken: leased.lease!.token,
|
||||
sourceCommit,
|
||||
changedPaths,
|
||||
migration,
|
||||
permissionsExpanded: false,
|
||||
partial,
|
||||
});
|
||||
const stored = async () =>
|
||||
(await db.transaction('alpha', tx => tx.get<CheckpointRecord>('checkpoint', 'checkpoint-1')))!
|
||||
@ -154,6 +155,15 @@ describe('tenant-scoped durable task invariants', () => {
|
||||
// A resumed build that diffed from a later base sees less of what the target branch gained.
|
||||
await classify(commit, ['src/app.ts'], false);
|
||||
expect(await stored()).toMatchObject({ migration: true, changedPaths: ['migrations/001.sql', 'src/app.ts'] });
|
||||
// Once part of what the environment ran was of unknown source, the commit's changes stay incomplete.
|
||||
await classify(commit, ['src/app.ts'], false, true);
|
||||
await classify(commit, ['src/app.ts'], false);
|
||||
expect(await stored()).toMatchObject({ migration: true, partial: true });
|
||||
expect(releaseRisk({ ...(await stored()), evidenceComplete: true, preauthorized: true })).toEqual([
|
||||
'The environment runs code of unknown source; not every change could be classified',
|
||||
'Database migration',
|
||||
'Protected change: migrations/001.sql',
|
||||
]);
|
||||
// Another commit is classified on its own.
|
||||
await db.transaction('alpha', async tx => {
|
||||
const run = (await tx.get<Run>('run', runId))!;
|
||||
|
||||
@ -12,7 +12,16 @@ import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/promis
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { promisify } from 'node:util';
|
||||
import type { Actor, CheckpointRecord, Evidence, Lesson, Project, Run } from '@wishforge/contracts';
|
||||
import type {
|
||||
Actor,
|
||||
CheckpointRecord,
|
||||
Environment,
|
||||
Evidence,
|
||||
Lesson,
|
||||
Project,
|
||||
Release,
|
||||
Run,
|
||||
} from '@wishforge/contracts';
|
||||
import { executeCommand, type CommandExecutor, type HostCheckSandbox, type ProviderStart } from '@wishforge/runtime';
|
||||
import { ManagedProvider } from '../packages/runtime/src/providers/base.js';
|
||||
import { ControlPlane } from '../apps/api/src/domain/control-plane.js';
|
||||
@ -640,6 +649,68 @@ describe('local main loop', () => {
|
||||
expect(reclassified?.trustedClassification).toMatchObject({ migration: true });
|
||||
expect(reclassified?.trustedClassification?.changedPaths).toContain('migrations/002-tags.sql');
|
||||
});
|
||||
it('weighs the release risk of everything the environment has not run yet, including direct pushes', async () => {
|
||||
const project = await createProject();
|
||||
const deployed = await git(remote, 'rev-parse', 'main');
|
||||
await store.transaction(TENANT, async tx => {
|
||||
const current = (await tx.get<Project>('project', project.id))!;
|
||||
await tx.put('project', {
|
||||
...current,
|
||||
deliveryConfig: {
|
||||
imageRepository: 'registry.local/greeting',
|
||||
architecture: 'linux/amd64',
|
||||
environmentId: 'environment-1',
|
||||
dockerfile: 'Dockerfile',
|
||||
containerPort: 3000,
|
||||
healthPath: '/health',
|
||||
smokeChecks: [],
|
||||
},
|
||||
});
|
||||
// The environment runs the project as it was before the person's push below.
|
||||
const stamp = new Date().toISOString();
|
||||
const entity = { tenantId: TENANT, version: 1, createdAt: stamp, updatedAt: stamp, projectId: project.id };
|
||||
await tx.put('release', {
|
||||
...entity,
|
||||
id: 'release-live',
|
||||
environmentId: 'environment-1',
|
||||
status: 'healthy',
|
||||
sourceCommit: deployed,
|
||||
} as Release);
|
||||
await tx.put('environment', { ...entity, id: 'environment-1', currentReleaseId: 'release-live' } as Environment);
|
||||
});
|
||||
// A person pushes a migration straight to the target branch; the agent then only touches the greeting.
|
||||
const person = path.join(root, 'person');
|
||||
await git(root, 'clone', remote, person);
|
||||
await mkdir(path.join(person, 'migrations'));
|
||||
await writeFile(path.join(person, 'migrations', '001-notes.sql'), 'create table notes (body text);\n');
|
||||
await writeFile(path.join(person, 'Dockerfile'), 'FROM scratch\n');
|
||||
await git(person, 'add', '.');
|
||||
await git(person, 'commit', '-m', 'Add a notes table');
|
||||
await git(person, 'push', 'origin', 'main');
|
||||
const classification = (runId: string) =>
|
||||
store.transaction(TENANT, async tx => {
|
||||
const run = (await tx.get<Run>('run', runId))!;
|
||||
return (await tx.get<CheckpointRecord>('checkpoint', run.checkpointId!))?.trustedClassification;
|
||||
});
|
||||
const runId = await submit(project.id, 'Make the greeting say hello world', 'wish-direct-0001');
|
||||
const session = await provision(runId, writeGreeting('hello world', 'Updated the greeting.'));
|
||||
expect(await drive(session)).toMatchObject({ status: 'release' });
|
||||
expect(await classification(runId)).toMatchObject({
|
||||
migration: true,
|
||||
partial: false,
|
||||
changedPaths: ['Dockerfile', 'greeting.txt', 'migrations/001-notes.sql'],
|
||||
});
|
||||
|
||||
// The environment runs a commit the repository does not have, as after a rewrite of the branch.
|
||||
await store.transaction(TENANT, async tx => {
|
||||
const live = (await tx.get<Release>('release', 'release-live'))!;
|
||||
await tx.put('release', { ...live, sourceCommit: 'f'.repeat(40) });
|
||||
});
|
||||
const second = await submit(project.id, 'Make the greeting say hello world again', 'wish-direct-0002');
|
||||
const next = await provision(second, writeGreeting('hello world again', 'Updated the greeting.'));
|
||||
expect(await drive(next)).toMatchObject({ status: 'release' });
|
||||
expect(await classification(second)).toMatchObject({ partial: true, changedPaths: ['greeting.txt'] });
|
||||
});
|
||||
it('repeats the checks when a build continues after the protected policy changed', async () => {
|
||||
const project = await createProject();
|
||||
await store.transaction(TENANT, async tx => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user