🚀 Deploy WishForge to the POC cluster, with check Pods and daily backups

- cluster-poc.mjs: image (in-cluster Kaniko), bootstrap, secrets, apply,
  migrate --rehearsal|--final, public HTTPS entry, backup and restore
- One restricted Pod (platform, executor, Runner, PostgreSQL, Temporal,
  MinIO, Caddy, backup) listening only on loopback except Caddy
- Protected checks run in per-workspace check Pods; cancellation during
  start-up now always removes them
- Daily snapshots on the node (consistent dump with row counts, Temporal
  online backup), copied to the Mac by launchd with SHA-256 checks and a
  notification on failure; restore verified on the rehearsal copy
- Downloads and uploads survive the Mac's lossy link to the cluster
- Local public entry, evidence isolation labels, acceptance records

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
eust-w 2026-11-01 16:27:07 +08:00
parent addf330b10
commit c5a6c6160d
58 changed files with 7360 additions and 64 deletions

View File

@ -28,6 +28,14 @@ const PASSTHROUGH = [
'WF_HOST_CHECK_WRITE_PATHS',
'WF_HOST_CHECK_LOOPBACK',
'WF_HOST_CHECK_BLOCKED_PORTS',
'WF_HOST_CHECK_KUBECONFIG',
'WF_HOST_CHECK_KUBECTL',
'WF_HOST_CHECK_POD_NAMESPACE',
'WF_HOST_CHECK_POD_IMAGE',
'WF_HOST_CHECK_POD_CLAIM',
'WF_HOST_CHECK_POD_ROOT',
'WF_HOST_CHECK_POD_CPU',
'WF_HOST_CHECK_POD_MEMORY',
'WF_DOCKER_CONFIG',
'TEMPORAL_NAMESPACE_PREFIX',
'TEMPORAL_TLS_CA',

View File

@ -6,6 +6,7 @@ import { formatTime, messageOf, mutateApi, shortId, safeUrl, useResource } from
import type { Environment, Identity, Release } from '@/lib/types';
import { browserId } from '@/lib/browser-id';
import { riskReasonLabel } from '@/lib/risk';
import { evidenceIsolationLabel } from '@/lib/evidence-isolation';
import { personName } from '@/lib/people';
type ReleaseReview = {
@ -23,7 +24,7 @@ type ReleaseReview = {
environment: { id: string; name: string; type?: string; production: boolean };
verification?: {
isolation?: 'host' | 'sandbox';
checkSandbox?: 'seatbelt';
checkSandbox?: 'seatbelt' | 'pod';
commands: { argv: string[]; exitCode: number }[];
};
};
@ -340,11 +341,7 @@ function ApprovalDialog({
'没有记录'
)}
{context.verification?.isolation === 'host' ? (
<p className="text-small">
{context.verification.checkSandbox === 'seatbelt'
? '(本机执行,检查在 Seatbelt 沙箱中运行)'
: '(本机执行,无隔离)'}
</p>
<p className="text-small">({evidenceIsolationLabel(context.verification)})</p>
) : null}
</KeyValue>
{context.approval ? (

View File

@ -56,6 +56,7 @@ import { wishDetails, wishTitle, withAnswers } from '@wishforge/contracts/wish';
import { providerNames, RunTable, stages } from '@/components/run-table';
import { waitingGuide } from '@/lib/waiting';
import { eventLabel } from '@/lib/events';
import { evidenceIsolationLabel } from '@/lib/evidence-isolation';
import { browserId } from '@/lib/browser-id';
import { credentialSourceLabel, initialWishProvider, wishProviderReady } from '@/lib/readiness';
import { personName } from '@/lib/people';
@ -1501,7 +1502,7 @@ function ArtifactList({ data, error, loading }: { data?: RunArtifacts; error?: E
<h3>{evidenceTitles[evidence.type] ?? evidence.type}</h3>
<p className="muted text-small">
需求版本 {evidence.revision} · {formatTime(evidence.createdAt)}
{evidence.isolation ? ` · ${evidence.isolation === 'sandbox' ? '沙箱隔离' : '本机执行(无隔离)'}` : ''}
{evidence.isolation ? ` · ${evidenceIsolationLabel(evidence, '本机执行(无隔离)')}` : ''}
</p>
<Status
value={evidence.passed ? 'succeeded' : 'failed'}

View File

@ -0,0 +1,44 @@
import { describe, expect, it } from 'vitest';
import { evidenceIsolationLabel } from './evidence-isolation';
describe('evidence isolation labels', () => {
it('keeps sandbox isolation distinct from host check sandboxes', () => {
for (const checkSandbox of [undefined, 'pod', 'seatbelt'] as const)
expect(evidenceIsolationLabel({ isolation: 'sandbox', checkSandbox })).toBe('沙箱隔离');
});
it('identifies credential-free check Pods without claiming full sandbox isolation', () => {
expect(evidenceIsolationLabel({ isolation: 'host', checkSandbox: 'pod' })).toBe(
'集群执行,检查在不带凭据的独立 Pod 中运行',
);
});
it('identifies Seatbelt checks without calling them unisolated', () => {
expect(evidenceIsolationLabel({ isolation: 'host', checkSandbox: 'seatbelt' })).toBe(
'本机执行,检查在 Seatbelt 沙箱中运行',
);
});
it('preserves the release and run pages’ original labels for ordinary host execution', () => {
expect(evidenceIsolationLabel({ isolation: 'host' })).toBe('本机执行,无隔离');
expect(evidenceIsolationLabel({ isolation: 'host' }, '本机执行(无隔离)')).toBe('本机执行(无隔离)');
});
it('uses a page-specific fallback only for ordinary host execution', () => {
expect(evidenceIsolationLabel({ isolation: 'sandbox' }, '本机执行(无隔离)')).toBe('沙箱隔离');
expect(evidenceIsolationLabel({ isolation: 'host', checkSandbox: 'pod' }, '本机执行(无隔离)')).toBe(
'集群执行,检查在不带凭据的独立 Pod 中运行',
);
expect(evidenceIsolationLabel({ isolation: 'host', checkSandbox: 'seatbelt' }, '本机执行(无隔离)')).toBe(
'本机执行,检查在 Seatbelt 沙箱中运行',
);
});
it('makes no isolation claim when isolation metadata is missing', () => {
expect(evidenceIsolationLabel({})).toBe('');
for (const checkSandbox of [undefined, 'pod', 'seatbelt'] as const) {
expect(evidenceIsolationLabel({ checkSandbox })).toBe('');
expect(evidenceIsolationLabel({ checkSandbox }, '本机执行(无隔离)')).toBe('');
}
});
});

View File

@ -0,0 +1,13 @@
import type { Evidence } from './types';
/** Host check sandboxes do not turn host evidence into production sandbox evidence. */
export function evidenceIsolationLabel(
evidence: Pick<Evidence, 'isolation' | 'checkSandbox'>,
hostFallback = '本机执行,无隔离',
): string {
if (evidence.isolation === 'sandbox') return '沙箱隔离';
if (evidence.isolation !== 'host') return '';
if (evidence.checkSandbox === 'pod') return '集群执行,检查在不带凭据的独立 Pod 中运行';
if (evidence.checkSandbox === 'seatbelt') return '本机执行,检查在 Seatbelt 沙箱中运行';
return hostFallback;
}

View File

@ -178,6 +178,7 @@ export type Evidence = {
commands?: CommandEvidence[];
installFailure?: CommandEvidence;
isolation?: 'host' | 'sandbox';
checkSandbox?: 'seatbelt' | 'pod';
targetRef?: string;
targetCommit?: string;
conflictPaths?: string[];

View File

@ -7,6 +7,7 @@ import {
localPocForProject,
RuntimeError,
safeIdentifier,
type CheckPodConfig,
type CommandExecutor,
type HostCheckSandbox,
type PortableCheckpoint,
@ -94,6 +95,8 @@ export interface WorkerConfig {
claudeCommandSandbox?: { readable: string[]; env: Record<string, string> };
/** Operator opt-in to a macOS sandbox for host checks and installations (see host-checks.ts). */
hostCheckSandbox?: HostCheckSandbox;
/** Operator opt-in, on a host that is itself a Pod, to a check Pod per workspace (see host-checks.ts). */
hostCheckPods?: CheckPodConfig;
dockerConfig?: string;
/** Docker CLI context of the image builder; operator configuration, never project settings. */
dockerContext?: string;

View File

@ -33,7 +33,7 @@ import {
import { ControlPlaneError, type ControlPlaneClient } from './client.js';
import { LeaseKeeper, activityContext } from './lease.js';
import { installPlan } from './project-contract.js';
import { hostCheckExecutor } from './host-checks.js';
import { closeHostChecks, hostCheckExecutor, type HostCheckExecutor } from './host-checks.js';
import { providerRegistry } from './providers.js';
/** Where a run continues when it already has a checkpoint or a release; no executor lease is needed for that. */
@ -146,6 +146,7 @@ export async function executeRun(config: WorkerConfig, input: RunInput): Promise
safeIdentifier(input.runId),
);
const execute: CommandExecutor = command => (config.execute ?? executeCommand)({ ...command, signal: keeper.signal });
let checks: HostCheckExecutor | undefined;
let provider: ProviderAdapter | undefined;
let providerStarted = false;
const abort = () => {
@ -309,8 +310,9 @@ export async function executeRun(config: WorkerConfig, input: RunInput): Promise
const plan = installPlan(context.installCommands, manifest?.manifest);
// Conflicted manifests cannot be installed; the agent resolves them first and the verifier installs.
if (plan.commands.length && !conflicts.length) {
checks = hostCheckExecutor(config, config.execute ?? executeCommand, keeper.signal);
const failed = await install(
hostCheckExecutor(config, execute),
checks,
plan.commands,
path.join(workspace, plan.directory),
workspace,
@ -448,11 +450,12 @@ export async function executeRun(config: WorkerConfig, input: RunInput): Promise
keeper.close();
keeper.signal.removeEventListener('abort', abort);
keeper.pauseRequested.removeEventListener('abort', abort);
const checksClosed = await closeHostChecks(checks);
await api.request(`/internal/runs/${input.runId}/lease/release`, { leaseToken }).catch(() => undefined);
// Before the agent ran, the workspace holds nothing a checkpoint or the repository cannot recreate.
if (workspace && (checkpointPersisted || !providerStarted))
await rm(workspace, { recursive: true, force: true }).catch(() => undefined);
else if (workspace) {
if (workspace && (checkpointPersisted || !providerStarted)) {
if (checksClosed) await rm(workspace, { recursive: true, force: true }).catch(() => undefined);
} else if (workspace) {
// Lease loss, cancellation and ambiguous uploads must never erase the only copy.
// Keep a private sidecar outside the agent tree so operators can recover this exact attempt.
const providerRun = providerStarted ? await provider?.inspect(input.runId).catch(() => undefined) : undefined;

View File

@ -1,5 +1,12 @@
import path from 'node:path';
import { seatbeltCheckExecutor, type CommandExecutor, type HostCheckSandbox } from '@wishforge/runtime';
import {
checkPodExecutor,
seatbeltCheckExecutor,
validateCheckPodConfig,
type CheckPodConfig,
type CommandExecutor,
type HostCheckSandbox,
} from '@wishforge/runtime';
import type { WorkerConfig } from './common.js';
const flag = (env: NodeJS.ProcessEnv, name: string) => {
@ -45,9 +52,70 @@ export function hostCheckSandbox(env: NodeJS.ProcessEnv): HostCheckSandbox | und
return { readable, writable, loopback, blockedPorts: [...blockedPorts].sort((a, b) => a - b) };
}
/** The executor for a host's checks and installations: sandboxed when the operator opted in. */
export function hostCheckExecutor(config: WorkerConfig, execute: CommandExecutor): CommandExecutor {
return config.sandboxMode === 'host' && config.hostCheckSandbox
? seatbeltCheckExecutor(config.hostCheckSandbox, execute)
: execute;
/**
* Operator opt-in, where the development host is itself a Pod, to running each workspace's
* checks and installations in a check Pod of its own (see CheckPodConfig): the namespace, the
* digest-pinned image, the claim on the run volume and where this container mounts its root
* (WF_HOST_CHECK_POD_NAMESPACE, _IMAGE, _CLAIM, _ROOT), the kubeconfig that may manage Pods
* there (WF_HOST_CHECK_KUBECONFIG), and optionally kubectl (WF_HOST_CHECK_KUBECTL) and the Pods'
* limits (WF_HOST_CHECK_POD_CPU, _MEMORY). The caches they may write are WF_HOST_CHECK_WRITE_PATHS.
*/
export function hostCheckPods(env: NodeJS.ProcessEnv): CheckPodConfig | undefined {
if (!env.WF_HOST_CHECK_POD_NAMESPACE) return undefined;
if (flag(env, 'WF_HOST_CHECK_SANDBOX'))
throw new Error('WF_HOST_CHECK_SANDBOX and check Pods are alternatives; configure one of them');
if (process.getuid === undefined || process.getgid === undefined)
throw new Error('Check Pods need a POSIX worker user');
const required = (name: string) => {
if (!env[name]) throw new Error(`${name} is required for check Pods`);
return env[name];
};
return validateCheckPodConfig({
namespace: env.WF_HOST_CHECK_POD_NAMESPACE,
image: required('WF_HOST_CHECK_POD_IMAGE'),
claim: required('WF_HOST_CHECK_POD_CLAIM'),
mountRoot: required('WF_HOST_CHECK_POD_ROOT'),
kubeconfig: required('WF_HOST_CHECK_KUBECONFIG'),
kubectl: env.WF_HOST_CHECK_KUBECTL ?? '/usr/local/bin/kubectl',
writable: paths(env, 'WF_HOST_CHECK_WRITE_PATHS'),
uid: process.getuid(),
gid: process.getgid(),
owner: `${env.WF_WORKER_ID ?? 'worker'}:${env.WF_SANDBOX_RUN_ID ?? ''}`,
cpu: env.WF_HOST_CHECK_POD_CPU,
memory: env.WF_HOST_CHECK_POD_MEMORY,
});
}
export type HostCheckExecutor = CommandExecutor & { dispose?(): Promise<void> };
/** Bind cancellation outside the check executor: its transport also has to clean up after cancellation. */
export function hostCheckExecutor(
config: WorkerConfig,
execute: CommandExecutor,
signal?: AbortSignal,
): HostCheckExecutor {
const checks: HostCheckExecutor =
config.sandboxMode !== 'host'
? execute
: config.hostCheckPods
? checkPodExecutor(config.hostCheckPods, execute)
: config.hostCheckSandbox
? seatbeltCheckExecutor(config.hostCheckSandbox, execute)
: execute;
if (!signal) return checks;
const bound: HostCheckExecutor = command =>
checks({ ...command, signal: command.signal ? AbortSignal.any([signal, command.signal]) : signal });
if (checks.dispose) bound.dispose = () => checks.dispose!();
return bound;
}
/** A cleanup error must neither replace the activity outcome nor permit deleting still-mounted workspaces. */
export async function closeHostChecks(checks: HostCheckExecutor | undefined): Promise<boolean> {
try {
await checks?.dispose?.();
return true;
} catch {
console.warn('[host-checks] Check Pod cleanup was not confirmed; retaining its mounted workspaces');
return false;
}
}

View File

@ -5,7 +5,7 @@ import { isProduction, requireDeploymentMode } from '@wishforge/contracts';
import { createActivities, type SandboxMode } from './activities.js';
import { temporalTls, workerNamespaces } from './temporal.js';
import { claudeCommandSandbox, claudeLocalAuthHome, providerBinaries } from './providers.js';
import { hostCheckSandbox } from './host-checks.js';
import { hostCheckPods, hostCheckSandbox } from './host-checks.js';
async function main() {
requireDeploymentMode(process.env);
@ -72,6 +72,7 @@ async function main() {
claudeAuthHome,
claudeCommandSandbox: claudeCommands,
hostCheckSandbox: hostCheckSandbox(process.env),
hostCheckPods: sandboxed ? hostCheckPods(process.env) : undefined,
dockerConfig: process.env.WF_DOCKER_CONFIG,
dockerContext: process.env.WF_DOCKER_CONTEXT,
dockerHost: process.env.WF_DOCKER_HOST,

View File

@ -42,7 +42,7 @@ import { leaseRun } from './executor.js';
import type { LeaseKeeper } from './lease.js';
import { advanceGitHubDelivery, loadGitHubDeliveryState, restoreMergedGitHubSource } from './github-delivery.js';
import { projectContract } from './project-contract.js';
import { hostCheckExecutor } from './host-checks.js';
import { closeHostChecks, hostCheckExecutor, type HostCheckExecutor } from './host-checks.js';
/** A commit the verifier checked in a workspace of its own, with the evidence it recorded. */
interface Verified {
@ -69,9 +69,9 @@ class Session {
readonly targetRef: string;
readonly isolation: Isolation;
/** Set when development checks run under the operator's macOS sandbox. */
readonly checkSandbox?: 'seatbelt';
readonly checkSandbox?: 'seatbelt' | 'pod';
readonly execute: CommandExecutor;
readonly checks: CommandExecutor;
readonly checks: HostCheckExecutor;
readonly git: GitWorkspace;
/** Directories and candidate worktrees to remove when the activity ends. */
readonly scratch: string[] = [];
@ -94,8 +94,9 @@ class Session {
this.checks =
this.isolation === 'sandbox'
? isolatedVerifierExecutor(config.verifierBinary, this.execute)
: hostCheckExecutor(config, this.execute);
if (config.sandboxMode === 'host' && config.hostCheckSandbox) this.checkSandbox = 'seatbelt';
: hostCheckExecutor(config, config.execute ?? executeCommand, keeper.signal);
if (config.sandboxMode === 'host' && config.hostCheckPods) this.checkSandbox = 'pod';
else if (config.sandboxMode === 'host' && config.hostCheckSandbox) this.checkSandbox = 'seatbelt';
this.git = gitFor(config, context, this.execute);
}
get run(): Run {
@ -337,6 +338,7 @@ class Session {
}
async close() {
clearInterval(this.renewal);
const checksClosed = await closeHostChecks(this.checks);
if (this.fence !== undefined)
await this.api
.request(`/internal/runs/${this.input.runId}/integration-lease/release`, {
@ -344,6 +346,7 @@ class Session {
fence: this.fence,
})
.catch(() => undefined);
if (!checksClosed) return;
for (const worktree of this.worktrees) await this.git.removeWorktree(worktree.repository, worktree.path);
for (const directory of this.scratch) await rm(directory, { recursive: true, force: true }).catch(() => undefined);
}
@ -883,9 +886,12 @@ export async function verifyRun(config: WorkerConfig, input: RunInput): Promise<
);
} finally {
keeper.close();
await session?.close();
await api
.request(`/internal/runs/${input.runId}/lease/release`, { leaseToken: keeper.token })
.catch(() => undefined);
try {
await session?.close();
} finally {
await api
.request(`/internal/runs/${input.runId}/lease/release`, { leaseToken: keeper.token })
.catch(() => undefined);
}
}
}

View File

@ -0,0 +1,165 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { mkdtemp, readdir, rm, stat } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import type { CheckPodConfig, Command, CommandExecutor, CommandResult, ProviderAdapter } from '@wishforge/runtime';
import type { Project, Run } from '@wishforge/contracts';
import { BASELINE_VERSION } from '@wishforge/agent';
import { executeRun } from '../src/executor.js';
import type { RunContext } from '../src/common.js';
const directories: string[] = [];
afterEach(async () => {
vi.restoreAllMocks();
await Promise.all(directories.splice(0).map(directory => rm(directory, { recursive: true, force: true })));
});
/** The subset of kubectl invocations check-pods.ts makes; `deleteResult` lets tests choose its outcome. */
function fakeKubectlAndGit(kubectl: string, deleteResult: () => CommandResult): CommandExecutor {
return async (command: Command) => {
if (command.executable !== kubectl)
// GitWorkspace / manifest reads: every call that looks up a commit gets one; nothing else matters.
return { exitCode: 0, stdout: command.args.includes('rev-parse') ? 'a'.repeat(40) + '\n' : '', stderr: '' };
const verb = command.args[command.args.indexOf('-n') + 2];
if (verb === 'create') return { exitCode: 0, stdout: 'pod/wf-check-fixture', stderr: '' };
if (verb === 'wait') return { exitCode: 0, stdout: '', stderr: '' };
if (verb === 'delete') return deleteResult();
if (verb === 'exec') return { exitCode: 0, stdout: '', stderr: '\n__WISHFORGE_CHECK_EXIT__=0\n' };
throw new Error(`Unexpected kubectl verb in fixture: ${verb}`);
};
}
/** Runs one executor activity through a successful install, agent turn and checkpoint upload. */
async function run(deleteResult: () => CommandResult) {
const workspaceRoot = await mkdtemp(path.join(os.tmpdir(), 'wishforge-worker-workspace-'));
directories.push(workspaceRoot);
const kubectl = '/usr/bin/kubectl';
const hostCheckPods: CheckPodConfig = {
kubectl,
kubeconfig: '/etc/wishforge/kube/checks.config',
namespace: 'wishforge-checks',
image: `registry.example/wishforge/cluster-poc@sha256:${'c'.repeat(64)}`,
claim: 'wishforge-exec',
mountRoot: workspaceRoot,
writable: [],
uid: process.getuid!(),
gid: process.getgid!(),
owner: 'fixture-worker:run',
};
const execute = fakeKubectlAndGit(kubectl, deleteResult);
const at = new Date().toISOString();
const run: Run = {
id: 'run',
tenantId: 'tenant',
projectId: 'project',
stage: 'implement',
status: 'queued',
revision: 1,
repairCount: 0,
provider: 'claude-code',
bundleVersion: BASELINE_VERSION,
goal: 'Fixture only',
acceptanceCriteria: ['No model or network operations'],
executionGeneration: 'generation',
budget: { maxTokens: 1000, maxMinutes: 60, maxRepairRounds: 3 },
} as Run;
const project: Project = {
id: 'project',
tenantId: 'tenant',
version: 1,
createdAt: at,
updatedAt: at,
name: 'Check Pod cleanup fixture',
repositoryStorage: 'platform',
repositoryStatus: 'unconfigured',
autoDeploy: false,
targetBranch: 'main',
verificationCommands: [],
memberIds: [],
};
const context: RunContext = { run, project, installCommands: [['true']] };
let workspace: string | undefined;
const provider = {
capabilities: () => ({ provider: 'claude-code', availability: 'available', coding: true }),
start: vi.fn(async input => {
workspace = input.workspace;
}),
cancel: vi.fn(),
events: vi.fn(async function* () {
yield { sequence: 1, at, type: 'output', data: { text: 'Done.' } };
}),
inspect: vi.fn(async () => ({ id: 'run', provider: 'claude-code', status: 'completed' })),
exportCheckpoint: vi.fn(async () => ({
schemaVersion: 1,
runId: 'run',
provider: 'claude-code',
sourceCommit: 'a'.repeat(40),
baseCommit: 'a'.repeat(40),
patch: '',
patchSha256: 'e'.repeat(64),
createdAt: at,
})),
} as unknown as ProviderAdapter;
const fetcher: typeof fetch = async (url, init) => {
const route = new URL(String(url)).pathname,
body = init?.body ? JSON.parse(String(init.body)) : undefined;
if (route.endsWith('/lease')) {
run.status = 'running';
run.lease = { token: 1, workerId: 'fixture', expiresAt: new Date(Date.now() + 60000).toISOString() };
return Response.json({ data: run });
}
if (route.endsWith('/transition')) {
run.stage = body.stage;
run.status = body.status;
return Response.json({ data: run });
}
if (
route.endsWith('/heartbeat') ||
route.endsWith('/lease/release') ||
route.endsWith('/checkpoint') ||
route.endsWith('/meter') ||
route.endsWith('/events')
)
return Response.json({ data: run });
if (route.endsWith('/context')) return Response.json({ data: context });
throw new Error(`Unexpected fixture request ${route}`);
};
const outcome = await executeRun(
{
controlPlaneUrl: 'http://127.0.0.1:4000',
workerToken: 'fixture-token',
workerId: 'fixture',
workspaceRoot,
isolatedProviderHomeRoot: workspaceRoot,
sandboxMode: 'host',
hostCheckPods,
sandboxRunId: 'run',
sandboxTenantId: 'tenant',
sandboxGeneration: 'generation',
providerFactory: () => provider,
fetcher,
execute,
},
{ tenantId: 'tenant', runId: 'run', generation: 'generation' },
);
return { outcome, workspace };
}
describe('check Pod cleanup gates workspace deletion', () => {
it('removes the workspace once the check Pod is confirmed deleted', async () => {
const { outcome, workspace } = await run(() => ({ exitCode: 0, stdout: 'pod/wf-check-fixture\n', stderr: '' }));
expect(outcome.status).toBe('verify');
expect(workspace).toBeTruthy();
await expect(stat(workspace!)).rejects.toMatchObject({ code: 'ENOENT' });
});
it('retains the workspace when the check Pod cannot be confirmed deleted', async () => {
const warning = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
const { outcome, workspace } = await run(() => ({ exitCode: 1, stdout: '', stderr: 'Deletion refused' }));
expect(outcome.status).toBe('verify');
expect(workspace).toBeTruthy();
expect(await readdir(workspace!)).toBeDefined();
expect(warning).toHaveBeenCalled();
warning.mockRestore();
});
});

View File

@ -0,0 +1,124 @@
# WishForge 集群真实功能验收(2026-11-01)
> 本文为修复部署前的真实功能验收。两项修复现已部署,后续又完成新版本的功能与浏览器复测;同时发现的取消期间检查 Pod 回收问题也已修复,见[检查 Pod 清理验收](cluster-poc-checkpod-cleanup-2026-11-01.md)。最新状态见[部署进度](cluster-poc-deployment.md),下文的运行 ID、结果和问题状态保留为当时记录。
入口:**https://wishforge.d-robotics.cc/**,公网 IP `180.76.227.59`。
**结论:已实际调用模型并生成代码,验证了「愿望优化 → 幂等提交 → 实现 → 暂停/继续 → 独立检查 → 人工审核门禁 → 取消」主链路。第二轮实际源码通过额外的独立验收用例。没有合入或发布;不能据此宣称全部产品功能或生产交付链路均已验收。**
## 1. 真实测试用例
在 DroboticFlow 的演练工作区中实现一个独立的显示名规范化函数,不接入现有业务。要求:
- 新增 `internal/wishforgeacceptance20261101/name.go` 和 `name_test.go`,不修改其他文件。
- 导出 `NormalizeDisplayName(input string) string`,只使用 Go 标准库。
- 去除首尾 Unicode 空白,将内部连续空白合并为一个普通空格。
- 保留大小写、中文、标点、emoji 等非空白字符。
- 提供表驱动测试;空串、全空白、制表符/换行、全角空格、不换行空格等均有明确预期。
使用既有的 `local:rehearsal-check` 账号:`wish=review`,无管理、代码审批或发布权限。两个目标文件都属于需要人工审核的路径。Runner 始终保持演练停用状态。
## 2. 两次实际运行
| 项目 | 第一轮 | 第二轮 |
|---|---|---|
| 运行 ID | `038e6627-0d35-4827-af94-67741ba3c102` | `f486cc86-a94f-496f-a6e6-e04f88361b4d` |
| 预算上限 | 150,000 token | 300,000 token |
| 记录用量 | 168,918 token | 119,366 token |
| 结果 | 生成代码后进入 `waiting/implement/budget`,尚未独立验证 | 完整走到 `waiting/integrate/code_review` |
| 收尾 | 已取消,预留额度为 0 | 未批准审核,已取消,预留额度为 0 |
| Temporal | CANCELED | CANCELED |
第一轮用量由 17,623 输入、11,007 输出和 140,288 缓存读取 token 组成。当前预算统计包含缓存读取,并在记录用量后判断是否超限;本次超过测试上限后没有继续独立验证。不能把这次预算等待当作编译或功能测试失败,也不能把预算数字当作精确的人民币费用。
第二轮只调高了这个测试愿望的上限,没有修改全局配额、保护规则或其他账号。愿望优化复用了第一轮已测得的结果,没有再调用一次优化模型。
## 3. 逐项功能结果
| 功能 | 实测结果 |
|---|---|
| 愿望优化 | 实际模型调用成功,返回目标、6 条验收标准、0 个待澄清问题;优化内容保留函数职责、指定文件及不修改现有业务的边界 |
| 幂等提交 | 同一请求与幂等键提交两次,返回同一个 wish ID 和 run ID;没有重复创建 |
| 执行器实现 | 两轮都实际生成了指定函数和单元测试;核对 checkpoint patch,均只有两个预期新增文件,无其他修改 |
| 预算等待 | 第一轮超过设定上限后进入结构化的 budget 等待;源码检查点已保存 |
| 暂停与继续 | 第二轮在 verify 阶段暂停成功,再继续同一个已保存的实现检查点 |
| 检查点一致性 | 暂停前、继续后、验证证据和待审核记录都指向 `205f971095a2c0c72c49f275eae2e99df71a17e8` |
| 受保护检查 | Check Pod 内 lint、前端测试、前端构建、`go test ./...` 全部退出 0 |
| 事件游标补读 | 按中间 seq 补读,返回的事件序列与完整列表中对应后缀一致,没有遗漏或重复 |
| SSE 事件流 | 返回 `text/event-stream`,实际收到 run 事件和 JSON 数据 |
| 源码产物 | 通过实际 Artifact API 下载增量 Git bundle;bundle 与 patch 的 SHA-256 校验成功 |
| 审核门禁 | 两个变更文件均进入 pending 代码审核;没有自动合入,没有生成 release |
| 取消及回收 | API 状态和 Temporal 状态均确认取消;没有遗留检查 Pod,当前无排队或执行中的运行 |
第二轮受保护检查耗时:
| 检查 | 退出码 | 耗时 |
|---|---:|---:|
| lint:web | 0 | 3.329 秒 |
| test:frontend | 0 | 1.640 秒 |
| build:web | 0 | 1.369 秒 |
| go test ./... | 0 | 34.220 秒 |
| verify 命令总计(含调度开销) | 0 | 40.716 秒 |
## 4. 对实际产物的独立验收
没有仅凭模型的完成说明或它自己写的测试判定成功:
1. 下载并核对两个运行各自的 checkpoint patch 和 Git bundle。
2. 用 `git apply --numstat` 确认改动恰好是两个指定文件,且没有删除内容。
3. 在新的独立目录恢复 patch,人工检查实际函数和测试源码;未执行仓库脚本。
4. 另外编写 8 组验收用例,覆盖空串、全空白、普通空白合并、中文 Unicode 空白、窄不换行空格/em space、控制空白、标点、emoji 与大小写保留。
5. 每组都额外检查 `f(f(x)) == f(x)`,而非只重复调用同一个输入。
**第一轮和第二轮均通过:模型生成的 7 组测试,以及独立编写的 8 组验收测试。**
第二轮源码 commit:`205f971095a2c0c72c49f275eae2e99df71a17e8`。
第二轮 bundle:1,548 字节,SHA-256 为 `8da2e7db44682bfb8622f76328d3e931c35e4d0a57a00e022876a3aafcdb5542`。
这是本机对实际产物进行的独立功能检查,和集群 Check Pod 的全项目检查分别记录,未把前者冒充为平台签发的验证证据。
## 5. 发现的问题
### 执行说明中的普通数字被误脱敏(未修复)
实际运行的 `provider.output` 把文件名 `wishforgeacceptance20261101` 中的数字 1 替换成了 `[REDACTED]`,`A-B_01` 等说明也受影响。
根因已核对:`packages/runtime/src/providers/codebuddy.ts` 将 API Key、模型名、网关地址和值为 `1` 的 CLI 开关一起存入 `credentialEnv`,脱敏函数再对所有值执行 `replaceAll`。开关不是秘密,却导致普通文本被替换。
- 影响:运行说明与日志可读性下降。
- 实测未影响:生成的源码、源码产物哈希、受保护检查与独立验收。
- 已单独提出修复任务,应区分真实凭据与非秘密配置,并补回归测试;不能通过削弱真实凭据脱敏来解决。
### 测试预算需要考虑缓存读取
第一轮 150,000 token 上限不足以容纳本次模型实际返回的总用量。第二轮 300,000 上限足够。此处是测试参数调整,不是为了让测试通过而修改项目检查或预算统计规则。
## 6. 登录、接口与自动测试的已有结果
配置修复并由操作者执行 `apply` 后,已通过真实公网 HTTPS 验证管理员登录 303、已认证会话 200、首页 200、项目列表 200;Session Cookie 为 Secure、HttpOnly。密码或 Cookie 值没有写入本文。
同日线上只读检查通过:7/7 容器就绪、正式 TLS 证书有效、HTTP 308 跳转 HTTPS、匿名项目访问 401、不匹配的 Origin 请求 403。受审核账号能读取所属项目,但账号管理返回 403。
同日完整自动测试结果:TypeScript 类型检查通过;Vitest 542 通过、17 跳过;脚本测试 93 通过。跳过项目未算作通过。本次真实流程没有重复运行这套全量测试。
## 7. 验收边界与未覆盖项目
- 实际功能链路通过部署中的 API、Claude CLI、Check Pod、数据库、对象存储与 Temporal 执行,不是 mock 测试。
- 后续已通过仅监听本机的端口转发,在真实浏览器中验收同一集群副本的登录、项目搜索、愿望表单约束、运行详情、证据、用量、成员、发布记录、窄屏导航和退出。详情见[浏览器验收报告](cluster-poc-browser-acceptance-2026-11-01.md);不能将本机 HTTP 入口的页面操作等同于完整公网 HTTPS 浏览器路径。
- 先前扩展公网管理员检查的脚本被安全检查拦截;后续浏览器已补测上述页面和退出行为,但 AI 优化、提交按钮的实际点击仍被工具权限拦截,未计作通过。运行详情的检查隔离标签误标已在本地源码修复并通过回归测试和源码 fixture 浏览器验证,尚未部署到集群。
- 未批准代码审核、合入、构建发布镜像或部署;如要验证上线链路,应使用操作者确认的真实业务改动,另行批准。
- 没有强行触发自动修复或部署回滚,也未覆盖全部需求条目。
- 正式数据迁移和每日备份仍未执行。
## 8. 最终收尾
- 两个测试运行均为 canceled,Temporal 工作流均为 CANCELED,预留 token 均为 0。
- 两个测试运行的 release 数为 0。
- 当前 active run 数为 0,`wishforge-checks` 没有遗留 Pod。
- `poc` 分支头仍为 `ae2cfd97ccde29873e6f8a89503e8bcfd41a9cfd`,没有推送测试代码。
- 平台 7 个容器全部就绪、重启次数均为 0。
最初两条测试操作曾在执行前被权限检查拦截,未创建运行。操作者随后明确选择逐次确认执行,才进行了上述两次真实运行;本报告没有把先前受阻的操作记作成功。
整体部署状态见 [cluster-poc-deployment.md](cluster-poc-deployment.md)。

View File

@ -0,0 +1,101 @@
# WishForge 浏览器操作验收(2026-11-01)
> 本文记录首次浏览器验收。随后隔离标签与日志脱敏修复已随镜像 `sha256:e255230e4d6e…` 部署,AI 优化与采用建议交互也已实测通过;新发现的取消期间检查 Pod 回收问题也已修复,见[检查 Pod 清理验收](cluster-poc-checkpod-cleanup-2026-11-01.md)。最新结果以[部署后验收](cluster-poc-postdeploy-2026-11-01.md)和[部署进度](cluster-poc-deployment.md)为准,下文保留当时的事实与限制。
**结论:已通过真实浏览器操作验证登录、项目搜索、运行详情、证据展开、用量/权限等页面、窄屏导航和退出登录。发现运行详情的检查隔离标签错误;AI 优化与提交按钮的点击被工具安全检查拦截,未计作通过。**
本轮是此前 [真实功能验收](cluster-poc-acceptance-2026-11-01.md) 的浏览器补充,不重新创建业务运行,不批准代码审核、合入、发布或回滚。
## 1. 实测入口与范围
- 目标是 POC 集群的现有 `wishforge-0` 演练副本,不是本机另外启动的应用。
- 当前安装无法直接把公网 URL 接入 Browser preview,但可以使用工具托管的本机服务入口。
- 通过 `preview_start` 启动仅监听 `127.0.0.1` 的 Kubernetes 端口转发:本机 `13000` → Pod 内网页 `3000`,浏览器访问 `http://127.0.0.1:13000`。
- 没有修改集群来源白名单或认证策略。预览默认地址 `localhost:13000` 不在白名单中,跨到正确地址时也出现一次来源拒绝;使用已登记的 `127.0.0.1:13000` 并重新加载后正常。
- 本轮证明的是同一集群网页的浏览器行为,**不代替公网 HTTPS、代理或其他设备 DNS 的验收**。公网域名和正式证书已在此前分别验证。
- 浏览器使用管理员账号,只操作表单草稿及只读页面;没有以管理员身份提交愿望。密码、Cookie 和凭据文件内容不记录在本报告中。
## 2. 浏览器实际操作结果
| 项目 | 操作与结果 |
|---|---|
| 登录必填校验 | 点击空登录表单,焦点停在账号输入框;账号和密码都处于 valueMissing 状态,没有提交 |
| 登录 | 填写已指定的管理员凭据,点击进入工作空间;实际打开首页,显示“控制面已连接” |
| 首页 | 可见 0 个进行中的运行、0 个待确认和 1 个配置可用的执行器;页面完成渲染,已截图查看 |
| 项目搜索 | 输入 `DroboticFlow` 后仅剩对应项目;输入不存在的关键词显示“没有匹配的项目”和调整搜索的提示 |
| 项目详情 | 仓库地址、`poc` 目标分支、项目状态、代码权限与历史运行正常展示 |
| 愿望表单 | 从项目进入后自动选择目标项目,执行器为 Claude Code;空草稿的优化和提交按钮禁用,目标与验收标准均为必填 |
| 范围提示 | 管理员选择后端范围时,页面明确说明此账号可直接合入;因此没有用该账号提交测试愿望 |
| 预算约束 | 输入 Token 上限 `0`,浏览器报告 rangeUnderflow;最小值为 1000。测试后恢复默认 1,000,000。页面注明统计包含 cache read;不通过实际提交试探边界 |
| 草稿编辑 | 目标、验收标准和预算可输入;测试结束清空目标和验收标准,没有保留待提交草稿 |
| 运行搜索与筛选 | 按 `f486cc86` 和“已取消”筛选,唯一匹配第二轮真实测试运行 |
| 运行详情 | 显示正确的运行 ID、提交账号、已取消状态、300,000 预算与 119,366 已用 Token |
| 代码变更 | 点击 tab 后展示两个指定新增文件,合计 `+91 −0`;函数和单元测试 diff 可读,与先前下载的产物一致 |
| 阶段事件 | 页面展示 29 个事件,包括暂停、继续、检查通过、请求审核、取消与资源释放,顺序与实际运行相符 |
| 验证证据展开 | 点击明细 summary,展开 verify 命令、退出码 0、40.7 秒、源码提交 `205f971095a2c0c72c49f275eae2e99df71a17e8` 和输出尾部;四项受保护检查可见。隔离标签存在错误,见下节 |
| 已取消运行的操作 | 仅保留概览、代码、事件、证据等只读 tab,没有可执行的批准、继续或取消操作按钮;未调用审批接口 |
| 执行器页面 | Claude Code 显示配置可用,其他未配置的执行器明确说明未配置;没有填写或修改 API Key |
| 用量页面 | 找到真实测试运行的 119,366 token 记录;预留 Token 和当前活跃运行均为 0,月份标明按 UTC 统计 |
| 成员权限页面 | 管理员、需审核开发账号、前端账号的类型和权限说明显示正确;没有编辑、重置或停用账号 |
| 部署与审批页面 | 历史发布记录能读取,显示 16 次发布;没有点击回滚、访问业务应用或审批按钮。历史“健康”标签不作为当前业务环境健康的验收证据 |
| 窄屏导航 | 375×812 下打开导航并跳转到运行记录成功;项目和运行列表均无整页横向溢出,运行表格变为卡片;已截图查看 |
| 窄屏视觉观察 | 顶栏名称和“退出登录”在窄屏下换行,较拥挤但可见、可操作;不据此宣称所有尺寸均已适配 |
| 退出登录 | 点击页面退出按钮后回到登录页;再次导航到 `/projects` 被重定向到 `/login?returnTo=%2Fprojects`;直接打开 `/api/projects` 返回 401 和 UNAUTHENTICATED |
## 3. 确认的显示问题
### A. 检查 Pod 的证据被误标为“本机执行(无隔离)”——本轮新发现
同一浏览器中读取运行 `f486cc86-a94f-496f-a6e6-e04f88361b4d` 的实际证据接口:
```json
{
"type": "verification",
"passed": true,
"isolation": "host",
"checkSandbox": "pod",
"sourceCommit": "205f971095a2c0c72c49f275eae2e99df71a17e8"
}
```
“验证证据”tab 却显示“本机执行(无隔离)”。`apps/web/src/features/runs.tsx` 的标签只判断 `isolation`,没有进一步处理 `checkSandbox`;发布审核页已区分 `seatbelt`、`pod` 和普通 `host`。
这是 **UI 对真实隔离信息的错误展示**,不是检查 Pod 没有隔离。不能通过把证据的 `isolation` 伪改成 `sandbox` 来处理。
**后续修复(同日,本地源码已完成、尚未部署集群):** 按操作者要求在当前会话补齐 web `Evidence.checkSandbox`,新增共享的 `evidenceIsolationLabel`,运行详情与发布审核页复用它。Pod、Seatbelt、sandbox、普通 host 及缺省信息分别显示,保留旧记录的兜底文案;不修改实际隔离或证据数据。6 项新增回归测试及其余相关 web/bundle 测试共 38 项通过,web 类型检查、格式检查通过。通过仅本机 fixture 预览直接渲染当前源码的真实 `ArtifactList`(只在预览构建中临时导出私有组件),7 组输入的标签与缺省分隔符检查通过,浏览器无错误。预览已停止,临时启动配置已撤回;线上旧镜像尚未变化。
### B. 执行说明中的数字被误脱敏——前一轮已确认
概览及阶段事件中的文件名仍显示 `wishforgeacceptance2026[REDACTED][REDACTED]0[REDACTED]`,但“代码变更”tab 的实际文件路径和源码是正确的。
用户已启动独立会话处理日志脱敏问题。本轮没有重复修改,也没有把未获完成通知的修复视为已部署。
## 4. 未通过实际点击验证的操作
- 愿望表单的空提交及 AI 优化按钮点击均被工具安全检查以 `Unrequested Commit in a Connected App` 拦截。点击未执行,没有发出对应请求,不能据此判断业务功能失败或成功。
- 没有改用 JavaScript、API 或其他工具绕过这些按钮的拦截。
- 此前后端真实用例已验证优化、幂等提交、暂停/继续、检查与审核门禁,但这不等同于本轮端到端浏览器提交验收。
- 未打开或操作 IDE。页面中的 IDE“就绪”来自迁移的历史状态,不证明集群 IDE 可用;IDE 本来就不在此次迁移范围内。
- 未修改 Agent 配置、成员权限、项目设置或发布策略,没有审批、合入、构建发布或回滚操作。
## 5. 控制台与截图说明
- 检查过浏览器 console、network、DOM、CSS、可访问性树与截图,所测页面没有出现阻止渲染的 JavaScript 异常。
- 初始 403 与预览地址/导航来源有关;部分 Next.js 页面预取显示 200 后被取消(ERR_ABORTED),实际导航可用,不作为已确认的功能缺陷。
- 退出后尝试从登录文档用调试 fetch 查看接口,被登录页的 `default-src 'none'` CSP 阻止。没有放宽 CSP;随后用正常页面导航确认退出后的页面重定向和 API 401。
- 首页、证据页、窄屏运行列表和退出后的登录页均通过工具截图并在会话中查看。将截图从工具保存目录复制到仓库的操作受安全检查拦截,**本文不包含或假装存在导出的图片附件**。
## 6. 收尾
截至 2026-11-01 02:08 CST,数据库只读核对显示:
- 浏览器验收时间范围内新运行数:0。
- 同一范围内新发布数:0。
- 排队或运行中的任务数:0。
- `wishforge-checks` 中没有检查 Pod。
- 测试会话已退出,手机视口模拟已重置。
- 工具启动的本机端口转发已停止;集群服务未重启或变更。
可重复启动的端口转发配置保留在 `.claude/launch.json`,名称为 `wishforge-cluster-browser`。使用时需打开已登记的 `http://127.0.0.1:13000`,不能把 `localhost:13000` 的来源拒绝当作集群故障。
总体部署状态见 [cluster-poc-deployment.md](cluster-poc-deployment.md)。

View File

@ -0,0 +1,91 @@
# 检查 Pod 清理修复:部署与验收(2026-11-01)
本次只验证「取消期间遗留检查 Pod」的修复([check-pods.ts](../packages/runtime/src/check-pods.ts)、[host-checks.ts](../apps/worker/src/host-checks.ts)、[executor.ts](../apps/worker/src/executor.ts)、[verifier.ts](../apps/worker/src/verifier.ts)),不包含正式迁移、每日备份等其他未完成项。此前的「仍未解决」结论(见[部署后验收](cluster-poc-postdeploy-2026-11-01.md)第 5 节)**在本轮验收中已修复确认**。
## 1. 本次部署
- 集群:`https://120.48.181.105:6443`,命名空间 `wishforge`,仍为演练副本。
- 新镜像:`ccr-29eug8s3-vpc.cnc.bj.baidubce.com/dataflow-poc/wishforge-cluster-poc@sha256:3383c919c3b72d20cca1797b09b163baff85d0e0024620a57f8d6c8392309fff`,构建于 2026-10-31T21:47:31Z。
- 源码提交 `addf330b10210500a4c4fa42449c9686f7452e5d`(working tree 带未提交改动,`dirty: true`,与此前几轮一致;镜像内容由源码归档 SHA-256 `29bfbbd58cf9a52726f390bcf07c2ff52d1ba660320d6e6f643c54c413e0bc92` 追溯,405 个文件)。
- Pod 创建于 2026-10-31T21:47:39Z,容器 2026-10-31T21:48:12Z 左右全部进入 Running;更新后 7/7 就绪,重启次数均为 0,验收结束时仍是 7/7、0 重启。
- 平台和检查 Pod 均使用新镜像。除镜像引用、设置摘要外没有其他 StatefulSet/环境改动;未更改数据卷、ServiceAccount、权限、端口、数据库或模型凭据、管理员密码、HTTPS 域名与证书。
- 发布 Runner 继续 `WF_RUNNER_DISABLED=true`,没有执行 `migrate --final`。
- 本次构建前的镜像 `sha256:e255230e4d6e…`(含隔离标签与日志脱敏修复)记录在 `.wishforge/cluster-poc/image.json` 的历史版本中,需要时可重新 `apply` 前一个 digest 回退。
## 2. 构建前自动检查
与[上一轮](cluster-poc-postdeploy-2026-11-01.md#2-构建前自动检查)一致,额外覆盖本次新增的回归测试文件:
| 检查 | 结果 |
|---|---|
| 完整 TypeScript 类型检查(全部 workspace) | 通过 |
| Vitest | 574 通过,17 跳过;77 个文件通过、8 个文件跳过 |
| provisioner/scripts 测试(`node --test`) | 93 通过,0 失败 |
| 改动文件的 Prettier 检查 | 通过 |
| `git diff --check` | 通过 |
| 构建文件清单 | 405 个文件;排除 `.env*`、`.wishforge/`、`.claude/` 等私有内容 |
新增的回归测试:[apps/worker/test/check-pod-cleanup.test.ts](../apps/worker/test/check-pod-cleanup.test.ts)(端到端驱动一次真实 `executeRun()`,证明 delete 失败时保留工作区、成功时才删除)、[tests/host-checks.test.ts](../tests/host-checks.test.ts) 新增的 6 个用例(信号组合、dispose 保留、清理不继承 activity 信号的直接证明、`closeHostChecks` 的三种结果)。
## 3. 部署后针对性复现:取消期间遗留检查 Pod
**目的**:复现原始事故的时序模式(暂停请求 → 检查 Pod 创建中 → 继续/取消 → 资源回收等待),验证检查 Pod 这次会被正确清理,而不是像 `5f9a0ed4-73d8-4c73-b6c7-0028da6f49ed` 那样遗留。
测试账号仍是无审批/发布权限的 `local:rehearsal-check`;预算 300,000 token、15 分钟、0 个自动修复轮次。测试愿望是独立的 Go 求和函数(`internal/wishforgecheckpodcleanup20261101/sum.go` 与其表驱动测试),不接入现有业务,只用于触发一次真实的检查 Pod 创建。
脚本在进入 `verify` 阶段后等待 1.2 秒(让检查 Pod 的创建有机会开始),立即发送暂停,再等待 0.6 秒(**不等待暂停确认完成**)后立即发送取消,复现原始事故中「暂停尚未落地、取消已经到达」的时序,而不是安全地等暂停确认后再继续。
### 实测时间线(UTC,run `ec9a3cd5-e20a-4165-b66b-ea29846e8614`)
| 时间 | 事件 |
|---|---|
| 21:49:39.424 | 进入 `running/verify` |
| ~21:49:40 | 检查 Pod `wf-check-c21d8ccaf2-e21e58b5` 创建(独立 `kubectl get` 确认当时为 `ContainerCreating`) |
| 21:49:40.624 | 发送暂停 |
| 21:49:41.232 | 发送取消(暂停尚未确认,相隔 608 毫秒) |
| 21:49:41.239 | 控制面记录 `canceled`(命令本身几乎立即生效) |
| 21:49:47.067 | provisioner 开始停止该代的 executor/verifier worker(收到工作流已结束的信号) |
| 21:49:48.014 | verifier 活动捕获 `RuntimeError: Command was canceled`(`code: CANCELED`),worker 正常 drain 后以退出码 0 结束 —— 不是被强杀 |
| 21:49:49.087 | `resourceAllocation.status` 变为 `released` |
| 21:49:51 起,连续 6 次独立 `kubectl get pods -n wishforge-checks` 轮询(跨度 21:49:51–21:49:57) | **一直返回 `No resources found`** |
### 结论
- 检查 Pod 确实在取消命令到达前已经创建(独立 `kubectl` 观测,不依赖脚本自报)。
- worker 收到取消后没有被强杀:Temporal SDK 的 worker 状态经过 `STOPPING → DRAINING → DRAINED → STOPPED` 正常收尾,活动的 `finally`(`closeHostChecks`)得到执行机会。
- 在 executor 容器全程日志中搜索 `[check-pod]`、`[host-checks]`、`deletion not confirmed`、`cleanup remains pending`,**没有任何告警**——说明删除是被确认成功的,不是静默失败后只是巧合消失。
- `resourceAllocation` 变为 `released` 之后,检查 Pod 也确认不存在,两者现在一致;原始事故正是「已 released 但 Pod 仍 Running」的不一致。
- 验收结束时命名空间 `wishforge-checks` 中没有任何 Pod。
## 4. 完整回归:正常路径仍然通过
另一个独立愿望(`internal/wishforgecheckpodcleanup20261101regress/distinct.go`,Go 字符串去重函数)走完整正常路径,不触发取消竞态,用来确认这次修复没有破坏现有行为:
| 项目 | 结果 |
|---|---|
| Run | `baa2525e-5a71-43e8-95be-15adb05bb499` |
| 幂等提交 | 同一幂等键重复提交,得到同一个 run,没有重复创建 |
| 用量 | 21,658 token |
| 暂停/继续 | 在 verify 阶段暂停、确认 `paused` 后等待 5 秒再继续;继续后命中与原事故相同的「上一代资源正在回收」暂态,这次脚本正确等待重试而不是取消,随后正常恢复 `running/verify` |
| 检查 Pod 执行 | `checkSandbox: pod`;`poc-project-check.mjs verify` 退出码 0,耗时 40.868 秒 |
| 审核门禁 | 停在 `waiting/integrate/code_review`,待审核路径恰好是两个新增文件;验证证据与审核记录 commit 一致 |
| 事件与 SSE | 按 seq 补读与完整事件列表一致;SSE 实际收到 `run` 事件 |
| 产物下载 | 下载真实 Git bundle(1428 字节),SHA-256 与校验和匹配 |
| 数字脱敏 | 完成说明中的 `wishforgecheckpodcleanup20261101regress` 与 `RegressRun_02` 均未被误脱敏 |
| 发布 | 没有创建 release,没有合入 `poc` 分支 |
| 结束 | 测试结束主动取消,未批准审核;最终状态 `canceled`,`resourceAllocation.status` 为 `released` |
源码提交:`331cf10deada0a6c0a49843510476de67fad57ae`;基线提交:`a6de24030eadeda16a705e87c56faf59f5796446`(与上一轮相同,两轮测试都没有改变 `poc` 分支头)。
## 5. 最终状态与边界
- 7 个平台容器就绪、重启次数为 0,镜像为本次 `3383c919c3b7…`。
- 两个测试运行均已取消、`resourceAllocation.status` 均为 `released`。
- 命名空间 `wishforge-checks` 没有残留 Pod(两轮测试全程、结束后均确认,第一轮的竞态测试也不例外——这正是本次要证明的点)。
- 两个测试运行均未生成 release,没有向 `poc` 分支推送。
- 没有执行正式迁移、每日备份或生产切换;这些仍是独立的未完成项,不因本次修复而改变。
- 没有重新改动隔离标签、日志脱敏或与本修复无关的其他代码路径。
- 当前仓库未 commit/push;部署镜像包含已测试的工作树源码,由镜像摘要与源码归档摘要追溯。
- 本次竞态复现尽量贴近原始事故的时序(暂停请求落地前检查 Pod 已创建、取消在暂停确认前到达),但不是对 Temporal/调度器时序的确定性控制;本轮确实观测到了检查 Pod 存在后被清理的完整过程,没有观测到遗留,但不能据此排除所有可能的时序变体都已覆盖。
部署进度:[cluster-poc-deployment.md](cluster-poc-deployment.md)。此前记录:[真实功能验收](cluster-poc-acceptance-2026-11-01.md)、[浏览器验收](cluster-poc-browser-acceptance-2026-11-01.md)、[上一轮部署后验收](cluster-poc-postdeploy-2026-11-01.md)(第 5 节的遗留问题已在本文修复确认)。

View File

@ -0,0 +1,279 @@
# WishForge 部署在 POC 集群
把原本跑在 Mac 上的 WishForge(数据库、编排、对象存储、控制面、网页、执行器、发布 Runner)整体迁到 DroboticFlow 所在的百度云 POC 集群(`https://120.48.181.105:6443`)。执行器仍然使用 Claude CLI,模型改走公司地瓜网关(Anthropic 协议,`https://ai-api.d-robotics.cc`,客户端自动拼接 `/v1/messages`),默认 `deepseek-pro@latest`,小模型槽位 `deepseek-flash@latest`。
## 当前进度(2026-11-01)
| 步骤 | 状态 |
|---|---|
| 镜像构建并推送到 CCR | 2026-11-01 已构建并部署 `sha256:2c6a103217d1…`,包含检查 Pod 清理修复和每日备份;当前镜像记录在 `.wishforge/cluster-poc/image.json` |
| 命名空间、节点数据目录、本地卷、访问规则、准入策略 | 完成,权限已逐项核对 |
| Gitea 部署密钥 | 已添加到 `longtao.wu/droboticflow`(写权限),集群内拉取已验证 |
| Secret 与 ConfigMap | 已创建,网关 Key 已写入 |
| 演练迁移(`migrate --rehearsal`) | 完成:逐表行数一致;Runner 保持空闲,Mac 照常服务 |
| 演练验收 | 隔离标签与日志脱敏修复已部署并在新运行中验证;发布后重跑愿望优化、幂等提交、实现、暂停/继续、独立检查、审核门禁和取消,通过并完成产物独立验收,见[部署后验收](cluster-poc-postdeploy-2026-11-01.md)。该轮暴露的取消期间检查 Pod 回收竞态已修复并复现验证通过,见[检查 Pod 清理验收](cluster-poc-checkpod-cleanup-2026-11-01.md) |
| 公网入口(独立负载均衡 + 公网 IP + 域名) | **`https://wishforge.d-robotics.cc`** 已启用正式证书,校验通过;负载均衡 `180.76.227.59`,HTTP 跳转 HTTPS。本机解析正常,其他内网设备需确认公司 DNS 的记录,见下文 |
| 正式切换(`migrate --final`) | 未执行 |
| 每日备份 | 2026-11-01 已部署:节点上每日快照、Mac 每日 10:17 复制(launchd 已安装并试跑成功),在演练副本上完成一次恢复演练,见下文「备份与恢复」 |
演练验收:
| 项目 | 结果 |
|---|---|
| 7 个容器就绪、无重启;网页、API、对象存储健康;未登录访问 API 返回 401 | 通过 |
| 集群用部署密钥访问 Gitea,`poc` 分支与 Mac 一致 | 通过 |
| AI 优化愿望(控制面经地瓜网关调用 `deepseek-pro@latest`) | 通过 |
| 检查 Pod 自检:工具链齐全;无集群令牌和设置文件;`.git` 只读;看不到平台数据;连不上平台 Pod 的数据库、API、Temporal、对象存储端口;安装依赖可联网;退出码如实传回 | 通过 |
| 测试愿望:「需审核」测试账号提一个改后端路径的愿望;执行器经网关实现,检查 Pod 跑完安装和受保护检查(lint、前端测试、前端构建、Go 测试全部通过),停在代码审核;取消后 Temporal 工作流为 CANCELED,`poc` 分支没有收到推送 | 通过(第 4 次;前 3 次暴露了检查工具链缺 python3、OpenCV 等和 `apply` 不刷新设置的问题,均已修复) |
| 真实功能愿望(2026-11-01):实现 Unicode 空白规范化函数及单元测试,检查阶段暂停/继续,验证事件游标和 SSE、产物下载和哈希,停在代码审核后取消 | 通过;独立编写的 8 组验收用例也通过。第一轮预算不足被取消,第二轮完整通过;两轮均未合入或发布,见[验收记录](cluster-poc-acceptance-2026-11-01.md) |
| 管理员登录、会话、首页、项目列表 | 配置修复并由操作者执行 `apply` 后,经公网 HTTPS 实测通过:登录 303、会话已认证、首页和项目列表 200;后续也通过端口转发完成真实浏览器登录与退出验证 |
| 浏览器页面与只读操作 | 项目搜索、运行过滤、diff/事件/验证输出、执行器/用量/成员/历史发布、窄屏导航、登录/退出已验证;新版本的隔离标签与日志数字正确,AI 优化和“采用建议”回填也已实测通过,未点击最终提交或审批,见[部署后验收](cluster-poc-postdeploy-2026-11-01.md) |
| 暂停/取消期间的检查 Pod 回收 | 首轮检查 Pod 启动时暂停/取消,额度已释放但一只 Pod 遗留,已核对归属后人工清理;生命周期缺陷已修复(check-pods.ts 全阶段取消贯穿 + 独立清理预算),并用贴近原事故时序的复现测试验证通过,见[检查 Pod 清理验收](cluster-poc-checkpod-cleanup-2026-11-01.md) |
| 个人账号登录与权限 | 受审核测试账号可读取所属项目(200),不能管理账号(403);其他个人账号的密码登录尚未验收 |
| 合入、构建、发布 | 正式切换后由第一个真实愿望验收(演练副本不向 `poc` 分支推送、不发布) |
| Pod 重启后恢复:运行停在代码审核时删除 Pod,约 25 秒恢复就绪;数据行数、运行状态、待审核记录和 Temporal 工作流不变,之后取消正常完成 | 通过 |
Mac 上的服务仍在运行,切换前的临时公网链接由 Cloudflare 隧道提供(地址以维护者给出的为准),切换完成后停用。
公网入口是 WishForge 专属负载均衡的公网 IP `180.76.227.59`,以及公司自己的域名 `wishforge.d-robotics.cc`(公网 DNS 在阿里云,A 记录指向这个 IP;不使用 sslip.io、Cloudflare 等第三方域名)。HTTPS 时域名和 IP 各有一张 Let's Encrypt 证书,由 Caddy 自动续签,HTTP 的 GET/HEAD 跳转到 HTTPS,其他方法拒绝;控制台以域名为主地址。也可以用 `public --http` 改成纯 HTTP,这时密码和会话明文传输。
2026-10-30 查询时,公司内网 DNS(`10.9.0.10`、`10.48.6.10`,hobot.cc 的 AD 域控)自己托管的 `d-robotics.cc` 区域没有这条记录,返回 NXDOMAIN;仅在公网 DNS 加记录不一定能让内网用户访问。2026-11-01 本机已能正常解析并通过域名访问。其他内网设备若仍解析失败,需要 IT 在内网区域补同样的 A 记录 `wishforge` → `180.76.227.59`;在那之前可用 IP 访问。`public --domain` 只要求公网解析正确,本机 DNS 解析不到时会给出提醒。
## 架构
命名空间 `wishforge` 中一个单副本 StatefulSet([platform.yaml](../infra/k8s/cluster-poc/platform.yaml)),固定在 CPU 节点 192.168.80.249(由本地卷的节点亲和性决定)。Pod 里的容器共享回环网络,结构与 Mac 相同:
| 容器 | 内容 | 监听 |
|---|---|---|
| postgres | PostgreSQL 17.6 | 127.0.0.1:5432,TCP 连接一律需要密码 |
| temporal | Temporal 1.4.1 开发服务(SQLite),关闭 Web UI | 127.0.0.1:7233 |
| minio | MinIO `RELEASE.2025-07-23T15-54-02Z`(官方镜像已不公开发布,镜像内从公开源码构建) | 127.0.0.1:9000 |
| platform | 网页、API、Git 服务、coordinator、deployer | 回环 |
| executor | 执行调度与每次运行的 Claude CLI | 回环 |
| runner | POC 发布 Runner | 不监听 |
| backup | 每日数据快照([cluster-poc-backup.mjs](../scripts/cluster-poc-backup.mjs)) | 不监听 |
| caddy | 公网 HTTPS 入口、HTTP 跳转 | Pod 地址 8080/8443 |
只有 Caddy 监听 Pod 地址,其余服务都只在回环上。这个集群**不执行 NetworkPolicy**(`real2sim-poc`、`simfoundry` 的默认拒绝策略实际上都没有生效),所以这种布局是集群里其他 Pod 访问不到内部服务的唯一保证。
受保护检查(依赖安装、测试、构建)不在这个 Pod 里运行,而是每个工作区在命名空间 `wishforge-checks` 中起一个临时检查 Pod([check-pods.ts](../packages/runtime/src/check-pods.ts)):
- 只挂载这次运行的工作区(`.git` 只读)和检查缓存;看不到数据库、密钥或设置;
- 不挂 Service Account 令牌、不读任何 Secret;默认 seccomp、非 root、去掉全部 capability、只读根文件系统;
- 验证器每次重建工作区目录后会换一个新的检查 Pod;命令超时或被取消时连同 Pod 一起删除;Pod 自身最长存活 2 小时;
- 起不来或 exec 连不上时,运行停在「基础设施」等待,不会当作检查失败。
与 Mac 的差异:Mac 上检查在 Seatbelt 中断网运行;集群里检查 Pod 可以访问外网和集群内网(集群不执行网络策略)。这是选择「不放宽集群安全」换来的代价,证据中记录为 `checkSandbox: pod`。
### 身份与权限([rbac.yaml](../infra/k8s/cluster-poc/rbac.yaml)、[admission.yaml](../infra/k8s/cluster-poc/admission.yaml))
WishForge 在集群里只有一个身份 `wishforge/wishforge`,它的短期令牌只挂进 executor 和 runner 两个容器,取代 Mac 上的集群管理员 kubeconfig:
- `wishforge-checks`:创建、删除检查 Pod 并 exec;
- `droboticflow`:只能读取和更新 `droboticflow-api`、`droboticflow-worker`、`drosync-coordinator` 三个 Deployment,创建 Kaniko 构建 Pod;读不到任何 Secret 或 ConfigMap;
- 集群范围:只能读取 `droboticflow` 这一个命名空间。
两条准入策略只约束这个身份:检查 Pod 只能使用固定的 WishForge 镜像、挂载工作区子目录、不带令牌和 Secret;构建 Pod 只能使用 POC 固定的 Kaniko 镜像和镜像仓库凭据。这样即使令牌泄露,也只能创建这两种固定形状的 Pod。
### 数据与密钥
- 节点 192.168.80.249 的本地盘 `/home/cce/wishforge`([storage.yaml](../infra/k8s/cluster-poc/storage.yaml)),回收策略 Retain,各容器只挂自己的子目录。检查 Pod 另有一个只指向其中 `exec/` 目录的本地卷。
- 每个容器只读自己的设置文件(`wishforge-env` 中的 `platform.env`、`executor.env`、`runner.env`),executor 拿不到数据库和对象存储的密码。
- 从 Mac 原样带过去的只有持久数据依赖的密钥和令牌(`CARRIED`,见 [cluster-poc.mjs](../scripts/cluster-poc.mjs));数据库和对象存储使用新的随机密码,只保存在 Mac 私有的 `.wishforge/cluster-poc/generated.json`(0600)。
- 网关 Key 只写进集群 Secret `wishforge-claude`,不在 Mac 上另存。
- 集群版生成新的本机管理员密码;个人账号随数据库迁移,沿用原密码。会话密钥更新,所有人需要重新登录一次。
- 项目设置里的受保护安装、检查命令是 `poc-project-check.mjs` 的绝对路径。从 Mac 迁来的项目写的是 Mac 上的 Node 和仓库路径,platform 容器每次启动、控制面开始服务之前把它们改成镜像里的 `/usr/local/bin/node /opt/wishforge/scripts/poc-project-check.mjs install|verify`([cluster-poc-project.ts](../scripts/cluster-poc-project.ts));别的命令和已经指向镜像的命令不动。检查命令变化会让旧的检查证据不能再用于发布,迁移前已要求没有待发布的版本,所以没有影响。
### 实现要点
部署过程中遇到并已经处理的问题,改动清单或镜像时要保留:
- Pod 以 uid 10001 运行,镜像里 Temporal 没有这个用户的 passwd 条目,Go 不开 cgo 时解析不到当前用户,所以 Temporal 容器设置了 `USER`。
- 所有容器共享 Pod 的回环地址,PostgreSQL 默认信任 127.0.0.1,因此初始化时指定 `--auth-host=scram-sha-256`;恢复数据和运维查询走 postgres 容器内的 Unix socket。
- 维护模式和 Runner 停用时,入口必须显式保持进程存活(只注册信号处理不会让 Node 留下),否则容器反复退出重启。
- StatefulSet 的 OrderedReady 滚动更新不会替换一个没有就绪的 Pod,`apply` 会删除停在旧版本的 Pod。
- SWC 的原生模块缓存拒绝父目录对其他用户可写的位置,platform 容器的 `HOME` 放在持久卷里的私有目录。
- 网页启动器只透传 `WF_LOCAL_API_TOKEN`,不透传 `WF_DEV_AUTH_TOKEN`。集群设置必须把前者设成控制面所接受的后者;否则管理员密码校验和会话都成功,项目接口仍返回 401。凭据只在 platform 容器内使用,不下发到 executor 或 runner。
- OpenSSH 按用户数据库里的家目录找 `~/.ssh`,不看 `$HOME`,所以 Git 的 SSH 目录挂在镜像用户的家目录 `/home/wishforge`。
- 受保护检查的工具链除了 Node、npm、Go、Git,还有 python3(带 NumPy、OpenCV、PyYAML)和 ffmpeg:DroboticFlow 的 Go 测试(`internal/worker`)用它们运行算子 runner `backend/operator-runner/main.py` 的视频和数据集算子。Mac 上检查用的是 `/opt/homebrew` 里的 python3 和 ffmpeg;镜像里装 Debian 的 `python3`、`ffmpeg`,Python 包按 [check-python-requirements.txt](../infra/images/check-python-requirements.txt) 固定版本和哈希安装。缺了它们,这些测试会失败或等到超时。
## 需要操作者完成
1. **添加 Gitea 部署公钥**(已完成):在 `longtao.wu/droboticflow` 的部署密钥中添加以下公钥,并勾选写权限(需要仓库管理员)。查看公钥:
```bash
node scripts/cluster-poc.mjs deploy-key
```
2. **写入地瓜网关 Key**(已完成):建议为 WishForge 单独申请一个 Key,更换时同样写入。复制到剪贴板后运行,Key 直接写入集群,不会打印;也可以加 `--stdin` 从标准输入读取:
```bash
node scripts/cluster-poc.mjs gateway-key
```
容器只在启动时读取 Key。更换后,在没有执行中愿望的时候重启 Pod,新 Key 才生效:
```bash
kubectl --kubeconfig ~/.config/droboticflow/kubeconfigs/poc.config -n wishforge delete pod wishforge-0
```
3. **授权启动与迁移**:Claude Code 的自动权限检查可能拦截 `apply` 和 `migrate`,这时在交互式 `claude` 终端中为这些命令加权限规则,或者自己在终端里执行下面的命令。
## 命令顺序
所有命令都在仓库根目录运行,只使用 `~/.config/droboticflow/kubeconfigs/poc.config`,执行前都会核对集群地址。
```bash
node scripts/cluster-poc.mjs bootstrap
```
```bash
node scripts/cluster-poc.mjs secrets
```
容器只在启动时读取设置文件(其中也写着检查 Pod 使用的镜像)。`apply` 每次都会先刷新这些 Secret 和 ConfigMap,内容有变化时 Pod 模板上的摘要随之改变,Pod 自动按新设置重建;重新构建镜像后运行 `apply` 即可,平台和检查 Pod 会用同一个镜像。
演练迁移:复制数据库快照、Git、POC 构建记录和对象存储,Temporal 为空,Runner 保持空闲,Mac 照常服务:
```bash
node scripts/cluster-poc.mjs migrate --rehearsal
```
```bash
node scripts/cluster-poc.mjs status
```
通过端口转发在本机验收(网页只监听 Pod 回环,端口转发可以直接到达):
```bash
kubectl --kubeconfig ~/.config/droboticflow/kubeconfigs/poc.config -n wishforge port-forward pod/wishforge-0 13000:3000
```
保持它运行,在浏览器打开 `http://127.0.0.1:13000`。网页只接受登记过的来源地址,本机端口必须是 13000(Mac 上自己的控制台占着 3000)。演练副本只用来验收登录和浏览:不要在上面提愿望(有直接合入权限的账号会推送到 `poc`,而 Mac 也在服务),正式迁移时它的数据会被 Mac 的数据覆盖。
集群版管理员密码在 Pod 的私有文件里,复制到剪贴板(不打印):
```bash
kubectl --kubeconfig ~/.config/droboticflow/kubeconfigs/poc.config -n wishforge exec wishforge-0 -c platform -- node -e 'process.stdout.write(JSON.parse(require("fs").readFileSync("/var/lib/wishforge/platform-state/local-access.json","utf8")).password)' | pbcopy
```
公网入口(开始计费):创建 WishForge 专属的负载均衡和公网 IP,入口为 `https://<公网IP>`。先签 staging 证书,确认挑战路径通过后再签正式证书。账号的 BLB 配额用满时,负载均衡会停在 pending(Service 事件里是 `ErrorExceedsQuota`),提高配额后 CCE 自动创建,再运行一次 `public`。Pod 重启后负载均衡要几十秒才连上新 Pod,第一次挑战可能连接失败,Caddy 会自动重试:
```bash
node scripts/cluster-poc.mjs public
```
```bash
node scripts/cluster-poc.mjs public --production
```
加域名(先在 DNS 把 A 记录指向负载均衡的 IP;之后的 `public` 会沿用这个域名):
```bash
node scripts/cluster-poc.mjs public --production --domain wishforge.d-robotics.cc
```
纯 HTTP:负载均衡只保留 80 端口,不申请证书,密码和会话明文传输:
```bash
node scripts/cluster-poc.mjs public --http
```
## 备份与恢复
集群里没有可跨节点挂载的存储(没有 StorageClass),备份分两层:
- **节点上**:Pod 里的 `backup` 容器每天 03:20(北京时间)取一份快照,写到数据盘的 `backups/<UTC 时间>/`,保留最近 7 份。Pod 启动时若最新快照超过一天,会在约一分钟后补一份;失败一小时后重试。
- **Mac 上**:`backup` 把最新快照复制到 `.wishforge/cluster-poc/backups/<UTC 时间>/`(0700,保留 14 份),逐个文件核对大小和 SHA-256。`backup --schedule` 安装 launchd 任务,每天 10:17 自动执行(Mac 睡眠时在唤醒后补跑),日志在 `.wishforge/cluster-poc/backup.log`;Pod 最近一次快照失败或最新快照超过 36 小时,命令在复制后报错退出;由 launchd 运行时,任何失败都会弹出 macOS 通知「WishForge 集群备份失败」。
一份快照包括:
| 文件 | 内容 |
|---|---|
| `postgres.dump` | `pg_dump -Fc`。与逐表行数取自同一个数据库快照(`pg_export_snapshot`),行数记在 `manifest.json`,恢复后据此核对 |
| `temporal.db` | Temporal 的 SQLite,经 SQLite 在线备份复制并通过 `integrity_check` |
| `git.tgz`、`minio.tgz`、`poc-state.tgz`、`runner-state.tgz`、`platform-state.tgz` | 对应数据目录;`platform-state` 不含可重建的 `home` 缓存,`minio` 不含 MinIO 启动时会清理的 `.minio.sys/tmp` |
| `manifest.json` | 时间、镜像、行数,以及每个文件的大小和 SHA-256 |
不包括运行工作区和检查缓存(`exec/`)、Claude 的家目录、Caddy 的证书(会自动重新签发)。快照里有加密保存的凭据和管理员密码文件;解密这些凭据要用 Mac 上 `.env.local` 里的 `WF_VAULT_KEY` 等密钥,恢复也依赖 `.wishforge/cluster-poc/generated.json`,这些不在快照里,要和快照一起保管好。
`backup` 容器只读挂载它要保存的目录,只写 `backups/`;通过回环连接数据库(需要数据库密码),没有集群令牌、设置文件或密钥。镜像带有与数据库同版本的 `pg_dump`、`pg_restore`(从固定的 postgres 镜像复制)。
立即取一份快照并复制到 Mac:
```bash
node scripts/cluster-poc.mjs backup --now
```
每天自动复制(取消用 `--unschedule`):
```bash
node scripts/cluster-poc.mjs backup --schedule
```
`status` 会显示节点上的快照数、最新时间和最近一次结果。
恢复:用 Mac 上的一份快照替换集群里的全部数据(数据库、Temporal、Git、对象存储,以及平台、POC 和 Runner 的记录),流程与 `migrate` 相同——停 Pod、清空并解包目录、维护模式下导入数据库、逐表行数与快照记录一致才启动。节点上已有的快照保留。正式切换后要让 Runner 工作,加 `--runner`:
```bash
node scripts/cluster-poc.mjs restore .wishforge/cluster-poc/backups/<UTC 时间>
```
2026-11-01 在演练副本上的验收(集群空闲、快照后无新写入):
| 项目 | 结果 |
|---|---|
| 部署后 `backup` 容器约一分钟内自动取第一份快照(29.2 MB);`backup --now` 再取一份,均复制到 Mac 并逐文件核对通过 | 通过 |
| launchd 任务手动触发一次,退出码 0 | 通过 |
| `restore` 最新快照:约 3 分钟,逐表行数一致后启动;Git、POC 记录、Runner 记录、管理员凭据文件逐字节一致,MinIO 对象一致;登录页 200,未登录 API 401 | 通过 |
| 首次 `restore` 在上传时遇到集群连接超时 | 当时 Pod 停在 0 副本,已手动恢复,数据未动;随后改为每次上传核对 SHA-256 并重试、上传失败时自动重启 Pod |
这台 Mac 到集群的连接会丢掉 `kubectl exec` 输出流的末尾,下载速度约 150 kB/s。所以 `backup` 逐个文件下载:容器端发完文件后等 Mac 关闭输入才退出,Mac 收齐全部字节后才关闭。一份快照大约要 4 分钟。
节点故障时,在新节点上执行 `bootstrap`(先把 [storage.yaml](../infra/k8s/cluster-poc/storage.yaml) 里的节点改成新节点)、`apply`,再 `restore`。
## 正式切换
切换窗口约 30 分钟,期间停止写入:
1. Mac 上确认没有排队、执行中的运行,没有就绪或部署中的发布(`migrate` 会检查,不满足时拒绝执行)。
2. 停止 Mac 服务,确认 `stopCompleted=true`:
```bash
node scripts/local-poc-service.mjs stop
```
3. 正式迁移:会短暂停止 Mac 上 WishForge 的 MinIO 和 Temporal 容器以取得一致副本(之后重新启动作为回退);导入后逐表比对行数,一致才启动;Runner 开始工作:
```bash
node scripts/cluster-poc.mjs migrate --final
```
4. 用个人账号登录新地址验收,然后停用 Cloudflare 临时链接。Mac 上的数据保留不动。
## 回退
- 切换前任何一步失败:Mac 照常服务,集群里的副本可以随时用 `migrate` 重新覆盖。
- 切换后、集群尚无新写入:`kubectl -n wishforge scale statefulset wishforge --replicas=0`,再在 Mac 上 `node scripts/local-poc-service.mjs start`。
- 集群已有新写入:先缩容冻结集群,把数据反向导回 Mac 后再启动 Mac 服务。导回的项目检查命令是镜像里的路径,启动前在 Mac 上运行 `node --import tsx scripts/setup-local-poc.ts`,把它们恢复成 Mac 的路径。
- 删除 `wishforge-public` 会回收公网 IP,删除后在百度云控制台核对 BLB 和 EIP 已经释放。
## 已知限制
- IDE(Theia、OCT)没有迁移,集群版网页上的 IDE 入口不可用。
- 检查 Pod 有网络(见上文)。
- 数据在单节点本地盘上。节点上的快照和数据在同一块盘上,节点损坏时只能用 Mac 上的副本恢复;Mac 每天复制一次,所以最多丢失约一天的数据,且 Mac 长期关机期间没有异地副本。
- Temporal 使用开发服务,Web UI 已关闭。
- 模型名取自网关的 `/v1/models`(2026-10-30):`deepseek-pro@latest`、`deepseek-flash@latest` 是网关的别名,都已用 Anthropic 协议实测可用;`[1m]` 后缀让 Claude CLI 按 1M 上下文处理。网关文档里推荐的 `deepseek-v4-flash` 不在列表中。
## 验证
```bash
node --test scripts/cluster-poc.test.mjs scripts/cluster-poc-backup.test.mjs scripts/poc-project-check.test.mjs scripts/local-services.test.mjs
```
```bash
npx vitest run packages/runtime/test/check-pods.test.ts tests/host-checks.test.ts packages/runtime/test/claude-native.test.ts
```
在集群里还需逐项验收:个人账号登录与权限、AI 优化(经网关)、愿望执行与检查 Pod、执行器读不到工作区以外的凭据、审核与合入、构建与发布、Pod 重启后恢复。未验证的项目不能当作完成。

View File

@ -0,0 +1,142 @@
# WishForge 集群部署后验收(2026-11-01)
**两项修复已部署并实测生效;正常愿望主链路通过。另发现检查 Pod 启动期间暂停/取消的回收问题,当时未修复,因此不能将本轮判定为“完全无问题”。**
> 更新:第 5 节的回收问题已修复并以贴近原事故时序的复现测试验证通过,见[检查 Pod 清理验收](cluster-poc-checkpod-cleanup-2026-11-01.md)。下文保留当时记录。
入口:**https://wishforge.d-robotics.cc/**。
## 1. 本次部署
- 集群:`https://120.48.181.105:6443`,命名空间 `wishforge`,仍为演练副本。
- 新镜像:`ccr-29eug8s3-vpc.cnc.bj.baidubce.com/dataflow-poc/wishforge-cluster-poc@sha256:e255230e4d6eb01c160934feb7e17ea4d35ad221a4a1bf164eaaea2ff7e2bb5d`。
- Pod 创建时间:2026-11-01 02:57:17 CST;更新后 7/7 容器就绪,重启次数均为 0。
- 平台和检查 Pod 均使用新镜像。部署前逐项比对:除镜像引用、`WF_HOST_CHECK_POD_IMAGE` 和设置摘要外,没有其他 StatefulSet/环境设置变化。
- 未更改数据卷、ServiceAccount、权限、端口、数据库或模型凭据、管理员密码;HTTPS 域名和证书设置保持不变。
- 发布 Runner 继续 `WF_RUNNER_DISABLED=true`。没有执行 `migrate --final`,没有切换 Mac 上的正式数据源。
- 旧镜像 `sha256:0b763161a1b8599900da7a45b227992cd37cf3e2895b3c96817ff8ec2572653e` 及原 StatefulSet 记录保留在本机私有 `.wishforge/cluster-poc/rollout-20261101-UwUbM7/`,用于需要时回退。本次没有进行回退。
### 已发布的修复
1. **隔离标签**:运行详情与发布审核页共用 `evidenceIsolationLabel`,正确区分 Pod、Seatbelt、普通 host 和 sandbox。旧记录缺少字段时不推断隔离方式,不修改证据本身。
2. **日志误脱敏**:合入独立会话完成的补丁,只排除明确的非秘密配置值;API Key、Auth Token 和未分类凭据仍被脱敏。非秘密开关值 `1` 不再损坏文件名和普通文本。
旧运行中已经持久化的 `[REDACTED]` 不会被恢复;日志修复用新运行的输出验证。
## 2. 构建前自动检查
| 检查 | 结果 |
|---|---|
| 完整 TypeScript 类型检查 | 通过 |
| Vitest | 554 通过,17 跳过;76 个文件通过、8 个文件跳过 |
| provisioner/scripts 测试 | 93 通过,0 失败 |
| 两项修复相关文件的 Prettier 检查 | 通过 |
| `git diff --check` | 通过 |
| 构建文件清单 | 403 个文件;排除 `.env*`、`.wishforge/`、`.claude/` 等私有内容 |
独立会话的日志修复静态复核也已完成,未发现该补丁引入的问题。以上不是对整个产品所有代码的无缺陷保证。
## 3. 部署后真实功能测试
测试用例仍是有明确输入输出的 Unicode 显示名规范化函数,限制为新增:
- `internal/wishforgeacceptance20261101deploy/name.go`
- `internal/wishforgeacceptance20261101deploy/name_test.go`
使用无审批/发布权限的 `local:rehearsal-check` 账号。每轮预算 300,000 token、15 分钟、0 个自动修复轮次;平台受保护检查和审核规则未放宽。
| 项目 | 首轮 | 重跑 |
|---|---|---|
| Run | `5f9a0ed4-73d8-4c73-b6c7-0028da6f49ed` | `eda88f79-e6a7-4422-90e4-e47892419303` |
| 用量 | 81,256 token | 184,882 token |
| 实际结果 | 优化、幂等提交、实现、暂停请求成功;继续时旧资源尚在回收,测试脚本将该暂态判为失败并取消 | 正常走完实现、暂停/继续、检查、审核门禁、事件与产物验收 |
| 最终状态 | canceled;Temporal CANCELED | canceled;Temporal CANCELED |
| 预留额度 | 0 | 0 |
| 发布 | 无 | 无 |
首轮的愿望优化在新镜像上实际调用网关成功,返回 6 条验收标准、0 个澄清问题。重跑复用了此次已验证的优化结果,未再重复调用优化。
重跑时测试脚本仅增加了对确切的“上一代执行资源正在回收”暂态的有界等待,其他等待和失败仍会终止测试;没有修改线上调度器或资源策略。**重跑本身未再次观察到这项暂态,因此不能据此声称已验证或修复了该竞态。**
### 重跑通过的项目
- 同一幂等键重复提交,得到同一个 wish/run,没有重复创建。
- 生成指定函数和测试,改动范围恰好为两个新增文件,无其他修改。
- verify 阶段暂停后继续,暂停前检查点、最终验证证据和审核记录的 commit 一致。
- 检查 Pod 中全部受保护检查退出 0:
| 检查 | 耗时 |
|---|---:|
| lint:web | 3.266 秒 |
| test:frontend | 1.664 秒 |
| build:web | 1.362 秒 |
| go test ./... | 33.836 秒 |
| verify 总计(含调度开销) | 40.281 秒 |
- 运行停在 `waiting/integrate/code_review`;两个文件均待人工审核,没有自动合入或 release。
- 事件按 seq 补读与完整事件列表一致;SSE 实际收到 run 事件。
- 下载实际 Git bundle,校验大小及 SHA-256;检查 patch 哈希和文件范围。
- 新的执行说明中完整包含 `wishforgeacceptance20261101deploy` 和 `A-B_01`,未出现此前的数字误脱敏。
- 测试结束主动取消,未批准审核。
源码 commit:`e209566018bda5c858998be2da2d3e6cfd03366a`。
基线 commit:`a6de24030eadeda16a705e87c56faf59f5796446`。
Bundle:1,505 字节,SHA-256 `8f7a6fdfa0caa6479781b25646af52ecc1f9cb86c5f15f37ea8f7f8ec35f5791`。
### 实际产物的独立验收
下载并校验产物后,在独立本机目录恢复两个新增文件,人工检查源代码,再运行模型生成的测试和额外编写的 8 组验收用例。空串、Unicode 空白、中文、emoji、标点、大小写保留以及 `f(f(x)) == f(x)` **全部通过**。
这项独立验收与平台 Check Pod 的全项目验证分别计录,不把本机结果冒充为平台证据。
## 4. 浏览器与公网检查
公网独立检查:登录页 200、TLS 证书校验成功、HTTP 308 跳转 HTTPS、匿名项目接口 401。
真实浏览器通过仅监听 `127.0.0.1` 的端口转发访问同一新版本集群副本;没有启动另一份应用:
- 原管理员凭据仍可登录,首页显示控制面已连接。
- 会话、身份、项目、dashboard、执行器、环境、发布记录、用量及账号列表等 9 个读取接口均返回 200 和合法数据。
- 项目搜索正常,项目详情和愿望表单可用,空表单提交禁用。
- **本轮实际点击 AI 优化成功**,显示原文/建议、范围与不改项、6 条验收标准;点击“采用建议”回填表单,没有自动创建运行。测试草稿随后清空。
- 旧运行 `f486cc86...` 与本次新运行的验证证据都显示“集群执行,检查在不带凭据的独立 Pod 中运行”,不再显示“本机执行(无隔离)”。
- 新运行概览中的完整文件名和 `A-B_01` 显示正确,源码提交和 40.3 秒检查结果与 API 证据一致。
- 375px 窄屏证据标签可换行,页面无横向溢出;已截图查看,并恢复默认视口。
- 点击退出登录后返回登录页,再访问项目 API 返回 401。临时端口转发已停止。
浏览器网络记录中的 403 来自初始的 `localhost:13000` 与跨来源导航;按既有白名单使用 `127.0.0.1:13000` 重新加载后可用。Next.js 部分预取请求返回 200 后被导航取消,不作为已确认的业务故障。没有放宽白名单或 CSP。
浏览器没有点击最终“提交愿望”或审批按钮;实际提交/执行使用上面的受审核账号 API 测试。公网 HTTPS 检查与本机端口转发的浏览器检查分开记录,不混称为完整公网浏览器路径测试。
## 5. 当时未解决(已于检查 Pod 清理验收中修复):取消期间检查 Pod 回收不完整
首轮在 verify 阶段暂停时,一个检查 Pod 正在启动。相关时间顺序(UTC):
- 19:02:16:请求暂停。
- 19:02:20:检查 Pod `wf-check-892a107daa-ddb209bf` 创建。
- 19:02:21:请求继续。
- 19:02:23:等待旧代资源回收;测试脚本随后取消。
- 19:02:27:平台记录 `resources.released`。
之后运行已 canceled、`resourceAllocation.status=released`、预留额度为 0,但检查 Pod 仍为 Running,最长存活时间为 7200 秒。对该 Pod 的只读 exec 返回 OCI 工作目录错误;没有尝试绕过容器安全检查。
**处理:** 核对 Pod 标签、挂载路径中的 run ID、运行取消状态和 allocation released 后,仅删除了这只测试 Pod,未删除 PVC、工作区数据或其他应用资源。清理回执保存在本机私有部署记录目录。
**状态(当时):未修复。现已修复,见[检查 Pod 清理验收](cluster-poc-checkpod-cleanup-2026-11-01.md)。** 当时已提出独立任务检查 Pod 创建/等待 Ready、取消信号、退出清理及 provisioner 停止之间的竞态。需要补回归测试并单独修复,不能仅依靠两小时 deadline 宣称资源已回收。
第二轮成功路径自动完成回收,但这不能抵消首轮的真实异常。因此:两项本次发布的修复通过;**启动/取消异常路径的完整回收验收仍未通过**。
## 6. 最终状态与边界
- 7 个平台容器就绪、重启次数为 0,镜像为本次 `e255230e...`。
- 两个测试运行均已取消、Temporal 工作流均关闭、预留额度均为 0。
- 当前 active run 为 0,检查命名空间没有残留 Pod(首轮的一只由本次人工清理)。
- 两个测试运行均未生成 release。
- 测试前后 `poc` 分支头相同:`a6de24030eadeda16a705e87c56faf59f5796446`。
- 没有向业务分支合入/推送测试代码,没有构建或部署 DroboticFlow 业务发布。
- 正式迁移、每日备份、生产交付/回滚仍未验收或实施,不能把本轮称为全部产品功能完成。
- 当前仓库未 commit/push;部署镜像包含已测试的工作树源码,并由镜像摘要与源码归档摘要追溯。
部署进度:[cluster-poc-deployment.md](cluster-poc-deployment.md)。此前记录:[真实功能验收](cluster-poc-acceptance-2026-11-01.md)、[浏览器验收](cluster-poc-browser-acceptance-2026-11-01.md)。

View File

@ -1,6 +1,6 @@
# 本机工作空间的协作者访问
本机模式面向获准的可信操作者。网页可监听局域网地址;控制 API、数据库、Temporal、Provisioner 等服务仍监听本机回环地址。平台在服务端验证本机管理员登录后,才会向控制 API 附加既有凭据。浏览器收不到该凭据。
本机模式面向获准的可信操作者。网页可监听局域网地址;控制 API、数据库、Temporal、Provisioner 等服务仍监听本机回环地址。平台在服务端验证本机管理员或个人账号登录后,以对应身份调用控制 API;个人账号还携带账号 ID 和密码版本,由控制面按当前权限授权。浏览器收不到控制 API 凭据。
## 配置与启动
@ -37,9 +37,9 @@ npm run local:network -- --address 192.168.1.20 --apply
## 登录与退出
协作者访问 `http://本机局域网地址:3000`,使用本机生成的管理员账号和密码登录。该身份拥有当前本机工作空间的操作权限;它不是多用户权限系统。登录会话为加密、HttpOnly、SameSite=Strict 的 cookie,1 小时到期。HTTPS 入口额外设置 Secure。退出入口清除会话 cookie。
协作者通过局域网或经批准的 HTTPS 入口访问,使用管理员在「成员与权限」页创建的个人账号登录,并只授予所需项目与操作权限。不要共享本机管理员账号。登录会话为加密、HttpOnly、SameSite=Strict 的 cookie,1 小时到期;HTTPS 入口额外设置 Secure,退出会清除会话 cookie。公网入口的配置、限制与验收见 [local-public-entry.md](local-public-entry.md)。
访问密码是 256 位随机值,无法靠反复尝试猜中;限流只为限制每次 scrypt 校验的开销。15 分钟内错误超过 8 次后,密码校验在全局范围内每 2 秒最多一次,而不是锁定 15 分钟,局域网中其他设备输错密码不会把管理员锁在外面。限流不信任客户端提供的转发 IP,状态存在当前 Web 进程内,进程重启会清空。更换凭据文件(尤其 passwordHash 或 sessionSecret)会使旧会话失效。所有写入请求必须携带与访问入口完全一致的 Origin;未在白名单的 Host 或跨站请求被拒绝。
本机管理员密码是 256 位随机值;个人账号使用各自的随机初始密码。登录限流用于限制 scrypt 校验开销。15 分钟内错误超过 8 次后,密码校验在全局范围内每 2 秒最多一次,而不是锁定 15 分钟,局域网中其他设备输错密码不会把管理员锁在外面。限流不信任客户端提供的转发 IP,状态存在当前 Web 进程内,进程重启会清空。更换凭据文件(尤其 passwordHash 或 sessionSecret)会使旧会话失效。所有写入请求必须携带与访问入口完全一致的 Origin;未在白名单的 Host 或跨站请求被拒绝。
局域网 HTTP 会在网络上传输登录凭据,访问范围应限于受信任网络。若需要互联网访问,使用已批准的 HTTPS 入口,并将该 HTTPS origin 加入白名单;公网隧道、DNS、防火墙和端口转发不由此配置自动创建。代理必须保留正确的 Host,并与 Next 的 HTTP(S) origin 配置一致。

View File

@ -2,6 +2,8 @@
本机运行 WishForge 网页、控制面、Claude CLI 和发布 Runner。用户通过网页登录后提交愿望;项目固定接入 Gitea 的 `longtao.wu/droboticflow` 仓库 `poc` 分支,目标环境为既有 POC。Claude 修改独立工作区,受保护检查通过后由交付流程处理 Git 提交和发布。
迁到 POC 集群运行的部署、迁移与回退见 [cluster-poc-deployment.md](cluster-poc-deployment.md);切换完成前,本文描述的 Mac 服务仍是正式入口,也是迁移的数据来源。
## 后台运行
入口为 `/Users/d-robotics/workSpace/wishforge-ide/scripts/local-poc-service.mjs`。不带参数只读取状态。以下命令需在本机已登录的 macOS 用户下执行,无需 sudo:
@ -24,11 +26,11 @@ node scripts/local-poc-service.mjs start
## 入口与登录
本机入口为 `http://localhost:3000`;同一可达局域网的其他设备使用 `http://本机局域网IP:3000`。是否跨网可达由现有路由和防火墙决定。本项目没有创建公网隧道或额外公网转发。
本机入口为 `http://localhost:3000`;同一可达局域网的其他设备使用 `http://本机局域网IP:3000`。是否跨网可达由现有路由和防火墙决定。当前部署另有经批准的 Cloudflare 临时 HTTPS 隧道,地址以维护者提供的链接和私有入口白名单为准;它只代理 Web,不公开内部 API 或 IDE。百度云独立公网 IP 入口的实现与上线闸门见 [local-public-entry.md](local-public-entry.md),不能把清单已生成当成公网入口已开通。
本机管理员的登录凭据保存在 `.wishforge/local-access.json`,只允许本机当前用户读取(0600)。文件含用户名、密码和会话签名材料,不应上传到 Gitea、放入网页静态目录或复制到日志。文件不存在时可运行 `node scripts/setup-local-access.mjs` 创建;重复运行保留已有凭据。`.env.local` 的 `WF_LOCAL_ACCESS_FILE` 指向该文件的绝对路径。
其他人用个人账号登录:本机管理员(或已有的管理员账号)在网页「成员」页创建账号、分配角色,并把只显示一次的初始密码交给对方。账号保存在控制面数据库中(只存 scrypt 哈希);网页登录时向控制面核对密码,之后以本机令牌加上该账号和密码版本调用控制面,控制面按账号的角色授权。停用账号立即生效;重置密码会让该账号已登录的会话失效。更换 `local-access.json` 的会话签名材料会让所有人的会话失效。
其他人用个人账号登录:本机管理员(或已有的管理员账号)在网页「成员与权限」页创建账号、分配账户类型和项目范围,并把只显示一次的初始密码交给对方。账号保存在控制面数据库中(只存 scrypt 哈希);网页登录时向控制面核对密码,之后以本机令牌加上该账号和密码版本调用控制面,控制面按账号当前权限授权。停用账号立即生效;重置密码会让该账号已登录的会话失效。更换 `local-access.json` 的会话签名材料会让所有人的会话失效。
网络切换导致本机 IP 改变时:

151
docs/local-public-entry.md Normal file
View File

@ -0,0 +1,151 @@
# 本机 WishForge 的公网入口
## 当前状态(2026-10-29)
本机已有 Cloudflare 临时 HTTPS 隧道,最终地址以维护者提供的链接及私有 `.env.local` 中的 `WF_LOCAL_ALLOWED_ORIGINS` 为准。它只转发 Web,不直接公开 API、数据库或 IDE。隧道停止、Mac 休眠或断网会中断访问。
**百度云独立公网 IP 入口尚未开通。** 本次完成了脚本、配置、镜像及真实二进制校验,但在目标集群的 NetworkPolicy 验收处停止:
- 指定的测试端口可以正常访问,正向控制通过。
- 另一个本应被默认拒绝的入站端口仍可访问;等待策略传播并重复检查 8 次仍为 HTTP 200。
- 删除临时出站放行策略后,出站连接仍可访问;重复检查 8 次仍为 HTTP 200。
- 因此不能把“已创建 NetworkPolicy 对象”当作网络隔离已生效。
没有创建新的 BLB/EIP,没有改动原 `droboticflow-api-public`,没有追加新 origin,没有安装或启动本机 Caddy/frpc LaunchAgent。网关 Deployment、Pod、ConfigMap、专用隧道 Secret 和网络策略已撤回。`wishforge-access` 命名空间保留:CCE 自动同步了镜像拉取凭据,清理程序没有擅自删除这些自动管理对象;没有运行中的工作负载或公网 Service。
后续需要先由运维确认并启用目标 CCE 网络模式支持的 NetworkPolicy 执行能力,然后重新验收;或者选择具备独立网络边界的中转环境。**不能为完成公网访问而跳过此闸门,或擅自修改整个 POC 的网络组件。**
## 设计边界
平台和数据继续留在 Mac。集群只运行单副本 FRP 服务端和回环代理校验进程;浏览器 HTTPS 经 TCP 隧道直达 Mac 的 Caddy,再反代 `127.0.0.1:3000`。
| 公网端口 | 网关端口 | Mac 回环端口 | 用途 |
|---|---|---|---|
| 80/TCP | 18080 | 18080 | ACME HTTP-01;普通 GET/HEAD 跳转到标准 HTTPS 端口,其他方法拒绝 |
| 443/TCP | 18443 | 18443 | 用户 HTTPS |
| 7000/TCP | 7000 | frpc 主动连接 | 双向 TLS 加随机令牌的隧道控制及工作连接 |
不使用 sslip.io,不新增云主机、磁盘或数据库,不把 4000、4300 等内部端口加入隧道。只有在下述验收通过后,才可以申请独立的 BLB/EIP。
### 隧道与权限
- FRP 固定 v0.71.1,容器镜像引用固定摘要。
- 使用专用私有 CA 双向 TLS,客户端明确校验服务器名称 `wishforge-entry.internal`;这个名称仅是私有传输证书的身份,不需要公网 DNS。
- 服务端只允许 18080/18443。回环 `NewProxy` 钩子进一步限定两个固定名称的 TCP 代理,拒绝 STCP、UDP、其他端口及分组代理;钩子不可用时注册失败。
- 一个副本,Deployment 使用 `Recreate`,避免两个 FRP 实例分担同一个客户端的控制连接与用户连接。
- 就绪检查针对 7000 和策略进程,不依赖客户端注册后才出现的代理端口,避免启动死锁。
- 非 root、禁止提权、只读根文件系统、无 ServiceAccount 令牌、无宿主机挂载、无 Docker socket。
- 命名空间默认拒绝出入网络;服务端不需要主动访问业务 Pod、数据库或 Kubernetes API。
## 文件与本机状态
- `infra/k8s/local-entry/kustomization.yaml`:非公网网关资源;**不包含**收费的公网 Service。
- `infra/k8s/local-entry/public-service.yaml`:单独的新 LoadBalancer 清单,不能指向旧业务的 LB ID 或 selector。
- `scripts/configure-local-entry.mjs`:精确 origin 的预览、追加、按回执撤销,以及固定 Caddy/frpc 配置生成。
- `scripts/local-entry-service.mjs`:仅管理自己的 Caddy/frpc 进程,不改变原 platform/runner 服务组。
私有状态位于已被 Git 忽略的 `.wishforge/local-entry/`:目录 0700,秘密文件 0600。
- `bin/`:核对官方摘要后的 Caddy、frpc。
- `mtls/`:专用 CA、传输证书及令牌。CA 私钥和客户端私钥不上传集群;只把服务端需要的材料放到专用 Secret。
- `caddy-staging/`、`caddy-production/`:独立的 ACME 账户与证书状态,不得混用。
- `receipts/`:环境文件私有备份及本次追加 origin 的回执。
- `logs/`:独立日志,按文件轮转;不启用 HTTP 请求访问日志或调试级认证日志。
- `network-verification.json`:本次集群网络隔离实测结果。`false` 不能当作可发布状态。
所有启动脚本在 import 时都不会启动服务;ConfigMap 挂载脚本需按真实路径识别入口,不能用未解析的 `argv` 路径直接比较。
## 重新实施前必须满足
1. 集群网络隔离重新实测通过:有正向对照,禁止的入站端口被拦截,撤销允许规则后出站也被拦截。仅检查 API 对象或网络插件名称不够。
2. 入口对象名和命名空间 UID 经检查仍属于本任务;恢复时不能覆盖他人后来创建的对象。
3. 新资源仅引用该入口镜像、Secret 与 selector;不修改 DroboticFlow 或其他业务资源。
4. 用户已经确认新增 LB/EIP 费用,且未改变申请范围。
之后才能单独创建公网 Service。其配置显式选择 `small1`、标准 BGP、按流量计费及 5 Mbps 初始峰值上限,避免默认的 100 Mbps。**5 Mbps 不是账单封顶;Mac 离线时 LB/EIP 仍可能计费。**
## 新 IP 分配后的配置流程
以下命令只在前置条件通过、维护者取得本次专属新 IP 后执行;占位符不是实际可用地址。
先生成 staging 配置,不修改 Web origin:
```bash
node scripts/configure-local-entry.mjs --config <新公网IPv4> --staging
```
验证所需私有证书文件及 Caddy/frpc 配置:
```bash
node scripts/local-entry-service.mjs validate
```
安装独立用户服务(需本机登录的 macOS 用户):
```bash
node scripts/local-entry-service.mjs install
```
staging 仅用于确认 ACME 验证路径,不能作为浏览器信任验收。验证通过后,停止入口服务、确认 `stopCompleted=true`,重新生成不带 `--staging` 的配置,再启动并检查生产证书:
```bash
node scripts/local-entry-service.mjs stop
```
```bash
node scripts/configure-local-entry.mjs --config <新公网IPv4>
```
```bash
node scripts/local-entry-service.mjs start
```
Caddy 显式使用 Let's Encrypt `shortlived` profile,不使用内部 CA。公网 IP 证书需要自动续签,状态目录必须保留。`default_sni` 使没有 SNI 的 IP 访问也能选中证书;不得用跳过 TLS 校验的请求代替验收。首次签发成功不等于已经观察到自然续签成功。
只在可信 HTTPS 已通过验证后,预览并添加该 origin:
```bash
node scripts/configure-local-entry.mjs --address <新公网IPv4>
```
```bash
node scripts/configure-local-entry.mjs --address <新公网IPv4> --apply
```
工具只追加 `https://<新IP>`,保留 localhost、LAN、Cloudflare 及其他原有入口;不打印环境文件内容、不改凭据。随后在所有愿望、构建与发布空闲且 Runner 为新鲜 idle 时,按原运维流程重启本机服务,使新 origin 生效。`doctor.ready` 或 `/usage.activeRuns=0` 单独不足以证明安全空闲。
## 验收与运维
```bash
node scripts/local-entry-service.mjs status
```
检查可信 IP 证书、证书到期时间、HTTPS `/login`、未登录 API 拒绝、错误 Host/Origin 拒绝、HTTP 重定向不泄露本机端口,以及原 POC `/api/health` 和备用入口。
登录后的 Cookie、写入、SSE、WebSocket 检查必须使用已获授权的真实会话;不得读取管理员密码、伪造会话或擅自创建测试账号。没有验证的项目须明确标注,不得把匿名登录页可访问描述成完整业务验收。
服务由独立 LaunchAgent `cc.d-robotics.wishforge.local-entry` 管理,只随当前用户登录运行。不改变系统休眠设置;合盖、休眠和网络中断仍会影响访问和续签。
停止入口不会停止 WishForge:
```bash
node scripts/local-entry-service.mjs stop
```
按回执撤销本次新增的 origin,不整份覆盖旧环境文件:
```bash
node scripts/configure-local-entry.mjs --revert <回执文件> --apply
```
删除本次公网 Service 前必须确认它的 UID 和关联的 LB/EIP 属于本任务。删除会使地址失效,且地址可能无法恢复;需核对云端实际资源回收情况,不能仅凭 Kubernetes 对象消失就认定停止计费。命名空间中出现其他人或系统管理的额外对象时,不直接整体删除。
## 离线检查
```bash
node --test scripts/configure-local-entry.test.mjs scripts/local-entry-service.test.mjs
```
```bash
kubectl kustomize infra/k8s/local-entry
```

View File

@ -0,0 +1,227 @@
# 业务许愿试点:会议要求与 WishForge 差距分析
## 依据与边界
- 会议纪要:[业务许愿功能-展示交流,2026-10-28](https://horizonrobotics.feishu.cn/docx/XFtvdYthVoa66wxB9oxcA9ODnQf),读取版本 **6**,包含正文和两张功能流程图。
- 原始文字记录:[业务许愿功能-展示交流](https://horizonrobotics.feishu.cn/docx/P85OdAVrfoP3YrxLZjZcKaM8n7d),读取版本 **3** 中与权限、审批、回滚、修复、MCP 相关的片段。纪要和配图均为 AI 生成,存在歧义时以原话说明为依据,不擅自补成会议决策。
- 代码基线:`addf330`,包含六种账户类型、独立代码审核和发布权限、逐愿望前端范围、AI 优化、单运行撤销。
- 2026-10-28 对当前本机 API 做了只读检查:POC 环境 `autoDeploy=false`;后端路径为 `**`,例外为 `src/`、`tests/frontend/`、`**/*.md`;`wishRefinement=true`、`localAccounts=true`、`notifications=false`。
- 本次只做需求与实现对照,没有运行新的愿望、批准发布、修改线上配置或重跑测试。下述测试文件指已有覆盖,不代表本次执行通过。
- **优先级是本分析的建议,不是纪要原有排序。**
## 核心结论
现有技术流水线和权限基础已经具备。下一步不应重做账户或 AI 扩写,而应围绕 **业务提报简化、责任人审批、可控的需求恢复、真实案例验收** 完成试点闭环。
需要纠正三处容易误解的现状描述:
1. **线上回滚不是只有管理员能做。** 当前任何具备项目访问权与 `releases` 权限的人类账号都可以操作,包括预置的“发布负责人”。
2. **已有两种恢复能力。** 发布回滚恢复上一个兼容制品,不改 Git;“撤销这次改动”会在当前代码上反向撤销一个运行,形成新运行、重新验证,尽量保留后续改动。
3. **MCP 不是完全未实现。** 后端已有工具与路由;“暂不开放”应理解为本轮试点不向业务用户开放开发者接入,而不是从零开发 MCP。
## 调整清单
### 1. P0:拆出独立回滚权限
**依据:** 待办明确要求“新增回滚权限管控配置”;原话 00:23:49 为“这里就加一个回滚的权限”。
**现状:** `Permissions.releases` 同时包含请求、批准、拒绝和回滚发布。成员页面只有这一项,不能做到“可以审批上线,但不能回滚”。代码撤销另走许愿权限。
**建议:**
- 从发布权限中拆出独立的回滚权限,前后端、账号类型及旧账号迁移保持一致。
- 试点阶段只赋给约定的管理员/技术负责人,而不是所有发布审批人。
- 同时明确它只控制线上制品回退,还是也控制“撤销这次改动”。两种操作不能因都叫回滚而混为一谈。
- 保留操作者、恢复目标、影响范围和结果记录。
**验收:** 只有发布权限的人能够审批发布但不能回滚;无回滚权限的直接 API 请求也被拒绝。
证据:[权限定义](../../packages/contracts/src/permissions.ts:15)、[回滚入口](../../apps/api/src/domain/releases.ts:660)、[成员权限编辑](../../apps/web/src/features/members.tsx:232)。
### 2. P0:把发布审批收口到业务负责人
**依据:** 00:12:49 要求每次愿望收口到业务负责人;00:13:11 说明可以在构建镜像之后人工审批。
**现状:** 已有绑定精确代码、制品、环境和证据的发布审批;当前 POC 每次发布都需确认。但系统只校验 `releases` 操作权限,没有表达“本次愿望由谁承担业务确认责任”。“发布负责人”是权限模板名称,不是项目负责人的绑定。
**建议:**
- 建立可追溯的业务责任人分配:可考虑项目默认负责人、愿望继承或另行指派。
- 审批任务、待办和通知明确指向这次需求的负责人;审批人不能仅凭通用发布权限就被视为已完成业务负责人确认。
- 试点项目增加明确的“业务确认必需”策略,不仅依赖环境的默认值。`autoDeploy=true` 时低风险发布当前可以跳过人工审批。
- 审批页优先展示业务需求、验收点和实际变化;代码和镜像信息保留给技术人员。预览地址、前后对比截图是可考虑的辅助能力,不是会议已经确定的交付项。
**验收:** 可以追溯是谁被指定负责、谁做了确认、确认对应哪个版本;自动发布设置不能绕过试点要求的业务确认。
**待定设计:** 固定一个项目负责人、逐愿望指定或候选组内一人通过,会议没有定死;不要把某一种具体字段设计写成既定决策。
证据:[发布审批](../../apps/api/src/domain/releases.ts:434)、[发布风险策略](../../apps/api/src/domain/policy.ts:41)、[项目与审批数据结构](../../packages/contracts/src/index.ts:92)。
### 3. P0:让业务人员表达诉求,后端需求交给技术人员承接
**依据:** 00:10:44 业务人员不知道需求需要前端还是后端;00:11:27 强调业务用户表达诉求,平台判断并把涉及后端的需求交技术侧把关。会议当前只推荐前端需求,并未要求删除所有后端能力。
**现状:**
- 前端账号与逐愿望 `frontendOnly` 已有服务端强制;执行器发现非改后端不可时能够提问。
- 前后端边界依赖项目配置的路径,不是语义识别。项目未配置后端路径时,所有代码都按前端处理。
- 管理员、全栈开发的后端改动可直接合入。现有代码审核位于验证之后、合入之前。
- 当前“放开代码范围”仍是技术授权动作,不是“已安排技术人员承接需求”的完整工作流。
**建议:**
- 为试点增加简化的业务提报模式,默认前端范围;不要要求业务用户先作出技术判断。
- 检测到必须改后端时,明确显示“需要技术人员处理”,关联技术承接人和原因;不要诱导业务用户通过扩大权限继续自动尝试。
- 如果试点规定所有后端改动均需技术审核,应增加项目级强制审核策略,不应被个人的“直接合入”权限绕过;保留其他项目现有开发者模式。
- 试点接入前必须核对后端路径及例外规则。对未配置边界的项目,不宜直接向业务人员承诺“只能修改前端”。
**验收:** 业务人员可以只描述业务问题;必须改后端的需求能明确交到技术人员,而不是无限自动重试或自行扩围。
**不要擅自定案:** 原话并未明确技术审批必须在代码生成前,也未确定固定唯一技术审批人。
证据:[账号范围](../../apps/api/src/domain/permissions.ts:19)、[提交范围校验](../../apps/api/src/domain/control-plane.ts:363)、[执行器范围提示](../../packages/agent/src/prompt.ts:49)、[代码审核判断](../../apps/api/src/domain/control-plane.ts:709)。
### 4. P0:把业务页面与技术页面分层
**依据:** 00:06:07 说执行器与修复次数通常不需要用户修改;00:16:33 说许愿者无需关心代码变更、阶段事件和验证包,管理员看细节。
**现状:** 提交表单仍展示起点分支、执行器、Token、最长运行时间和修复次数;运行详情统一展示技术阶段及四个标签页。
**建议:**
- 业务提报默认只展示项目、业务诉求、影响页面/功能、验收标准。
- 分支、执行器、预算与修复配置移到“高级设置”,按使用场景或权限呈现。
- 业务运行详情突出“处理中 / 需要补充 / 等待负责人 / 已上线 / 需要技术处理”和结果入口;技术日志、diff、镜像与证据放在展开区或技术视图。
- 无管理权限的用户不应看到环境修改、Runner 和密钥配置等无效操作入口。
这里是默认界面与信息层级调整;会议没有要求禁止普通用户读取全部技术数据,不应擅自升级为新的数据访问限制。
证据:[提交表单](../../apps/web/src/features/runs.tsx:543)、[事件正文显示](../../apps/web/src/features/runs.tsx:1125)、[环境页](../../apps/web/src/features/environments.tsx:66)。
### 5. P1:指定版本/区间恢复,核心是保留有效需求
**依据:** 待办要求多版本提交后的指定区间回滚;00:20:17–00:22:00 关注误撤别人有效需求,以及再次上线带回旧 bug。指定版本回滚、有效需求重合并的具体实现仍有可行性研究成分。
**现状:**
- 发布回滚只接受当前发布,目标固定为直接前驱;没有用户可选的 `targetReleaseId`。
- 可以在兼容条件满足时逐级回退,但不是一次任意区间操作。
- 单运行撤销已经具备“移除一个坏愿望、保留后续提交”的基础,不必从零实现。
- 没有多运行选择、区间影响预览、保留/撤销集合和统一恢复计划。
**建议:**
1. 先明确“区间”指线上发布序列、Git 提交区间还是愿望集合。三者不能用同一个含糊的按钮表示。
2. 页面区分“紧急退回旧制品”和“修复代码以防再次发布带回 bug”。
3. 在现有撤销能力上增加恢复计划:当前基准、要保留/撤销的需求、关联提交、影响预览、冲突及依赖检查;通过独立验证后再审核/发布。
4. 如增加指定历史发布恢复,应复用现有 Runner、并发锁、验收和对账,不删除跨版本兼容性检查,也不改写旧发布的历史绑定。
5. 补发布包含的愿望与人工提交清单。一个 Release 的 `runId` 只是触发发布的运行,不表示制品只包含这一个愿望;此前 POC 发布也曾同时带上直接推送到目标分支的其他提交。
**无歧义验收例子:** A 是有效需求、B 有问题、C 是后来有效需求;恢复结果应尽量保留 A/C、去掉 B。如果 C 依赖 B,必须提示并经人工决策与重新验证,不能静默承诺保留成功。
原话“撤 2/3/4”与“保留 1/4/5”数字矛盾,不能据此定义区间边界。客户管理员与技术管理员 pair 是协作建议,不等于已经决定开发强制双人会签。
技术前置注意:GitHub 合入路径的 integration evidence 尚未像直接合入路径一样记录撤销所需的 `targetCommit`,扩展通用恢复能力时需补齐。
证据:[发布回滚](../../apps/api/src/domain/releases.ts:660)、[单运行撤销](../../apps/api/src/domain/control-plane.ts:640)、[Git 反向差异](../../packages/runtime/src/git.ts:646)、[GitHub 合入证据](../../apps/worker/src/verifier.ts:765)、[撤销已有测试](../../tests/local-loop.test.ts:1424)。
### 6. P1:补各阶段的中文业务总结
**依据:** 00:08:55 明确提到后续补每阶段的中文总结。
**现状:** 时间线类别有中文标签,但正文仍直接显示 `event.message`;目前没有独立的阶段中文总结字段和展示流程。
**建议:** 为主要阶段提供简短中文结果:做了什么、是否通过、等待谁、下一步是什么。保留原始日志作为技术详情。确定性的状态说明优先用模板生成,不必所有日志都再交给模型改写。
**验收:** 业务用户不读英文命令或堆栈也能理解当前进度、阻塞点和待处理事项。
证据:[事件标签](../../apps/web/src/lib/events.ts:1)、[事件正文](../../apps/web/src/features/runs.tsx:1133)。
### 7. P1:三次修复后提供人工拆解/接管出口
**依据:** 00:06:07 认为三次未闭环应人工拆解;纪要也明确了此限制。
**现状:** 自动修复预算最多 3 轮,耗尽会等待;但“继续”可以授权额外一轮,且业务页面的主要指引仍是继续重试。没有显式的技术承接任务或拆分需求关联。
**建议:**
- 业务试点默认在自动修复耗尽后引导“交给技术人员”或“拆成更小需求”。
- 自动附上原愿望、失败摘要、当前改动和验证证据,避免接管人重新找信息。
- 技术人员如确需追加修复轮,可保留显式授权入口;不要误把网络故障也计入三轮。
- 需求拆分结果关联原运行,避免业务用户误以为原需求已经完成。
证据:[自动修复上限](../../packages/contracts/src/index.ts:414)、[耗尽处理](../../apps/api/src/domain/control-plane.ts:1154)、[追加一轮](../../apps/api/src/domain/control-plane.ts:602)、[页面指引](../../apps/web/src/lib/waiting.ts:55)。
### 8. P1:接通飞书提醒,区分跳转审批与卡片内审批
**依据:** 00:17:03 提出飞书提醒并直接点 Approve 的方向。
**现状:** 已有代码审核、发布审批、等待、完成、失败通知;当前部署 `notifications=false`。卡片按钮是 URL 跳转,未实现审批回调;@ 对象来自部署级配置,不是逐愿望业务负责人。
**建议分两步:**
- 试点先配置机器人与可用的工作台入口,实现“提醒负责人 → 点击进入审批页 → 登录后确认”。这是已有能力的配置落地。
- 如果确定需要飞书内直接审批,再做交互卡片回调、飞书身份与平台账号映射、负责人校验、精确版本绑定、防重复/过期处理。不能凭按钮文案或回调参数直接批准。
临时公网隧道的地址和可用性不稳定,不宜直接当作长期审批回调与通知入口。
证据:[通知生成](../../apps/api/src/domain/notifications.ts:95)、[配置和 @ 对象](../../apps/api/src/domain/notifications.ts:158)、[卡片 URL 按钮](../../apps/api/src/domain/notifications.ts:180)。
### 9. P1:AI 优化已有,补验收模板和真实案例评估
**依据:** 00:11:27 提到验收模板;00:21:25 要求用实际案例验证 AI 扩写效果。
**现状:** 已有三行愿望、可勾选验收标准、最多三道选择题、按字段优化和人工采纳;不应再列为“从零开发”。当前优化只看文字、不读仓库,因此不应承担可靠的前后端代码判断。已有测试主要校验协议、提示规则与解析,不等于需求质量的业务验收。
**建议:**
- 增加适合业务用户的参考模板,例如文案/布局/列表筛选,并允许不采纳或编辑。
- 选择实际业务需求建立回归案例:是否遗漏原意、是否擅自增加功能、验收点是否可检查、是否问了业务人员无法决定的技术问题。
- 将代码范围识别放在具备仓库信息的执行/分析环节,而不是让纯文字优化器猜。
证据:[AI 改写规则](../../apps/api/src/domain/wish-refiner.ts:10)、[优化测试](../../tests/wish-refiner.test.ts:35)。
### 10. P1:交付业务简版手册、录屏与一个完整真实案例
**依据:** 纪要要求本周优化、提供操作录屏和使用文档,并选实际需求跑通。
**现状:** 仓库已有完整中文手册;录屏文件或交付清单本次未在仓库找到,不能据此断言外部没有录过。当前还有文档不一致:`local-browser-access.md` 仍写共享本机管理员、不是多用户权限系统,与现有个人账户设计冲突。
**建议:**
- 完整手册继续给维护者;另给业务用户短版“登录 → 提报 → 补充 → 负责人确认 → 看效果 → 问题反馈”。
- 录屏采用真实业务案例,不只演示添加测试文件或人工模拟执行器。
- 明确记录验收人、需求、部署版本、验收结果和异常处理;测试发布仍须用户明确批准。
- 修正文档中旧的共享管理员指引,并同步飞书手册与录屏内容。
证据:[现有用户手册](../user-manual.md)、[过时的登录说明](../local-browser-access.md:38)。
### 11. 后续:保留 MCP 基础,本轮不扩大对外开放
**依据:** 00:27:19 提到开发者本地改代码后的 MCP 路径;00:31:04 明确暂时不给外部使用,00:31:24 说先内部对齐。
**现状:** 已有 `list_projects`、`submit_wish`、`answer_question`、`get_delivery`、`request_release` 等工具与 `/mcp` 路由。`request_release` 要求平台已有验证和构建证据,不是上传任意本地代码即可上线。当前 POC 也限制起点分支,不能直接把通用开发者路径视作已开放给 POC 用户。
**建议:** 本轮只明确接入边界、文档和启用策略,不把 MCP 设为试点前置条件。将来再设计本地改动推送、候选提交识别、平台独立验证及人工发布审批;不能绕过已有验证与审批。
证据:[MCP 工具](../../apps/api/src/mcp.ts:86)、[发布证据要求](../../apps/api/src/mcp.ts:16)、[MCP 路由](../../apps/api/src/main.ts:166)。
## 不应混入 WishForge 本仓库的事项
文档中的双目视频同步、右视图加载、H.265 转 H.264、压缩测试和供应商带宽排查,属于被接入的标注/业务平台,应另列该项目的改造与运维任务:
- 核对真实资源请求链路、首帧与拖动加载耗时、左右视频时间戳/切片对齐。
- 用同一素材比较不同编码/码率下的体积、兼容性与标注精度。
- 收集供应商带宽与延迟数据,再判断瓶颈。
“BOS 直读、没有平台 5 Mbps 限流”是纪要中的排查结论,本次未在对应业务系统独立验证,不应据此排除其他网络或前端问题。
## 推荐实施顺序
1. **先把试点边界和审批责任明确下来:** 独立回滚权限、业务责任人、后端技术承接、轻量业务界面;确认试点环境每次人工发布。
2. **再补可理解、可求助的运行体验:** 中文阶段总结、三次失败人工出口、飞书提醒。
3. **同步用真实需求验收与交付资料:** AI 质量案例、操作录屏、简版与完整手册一致。
4. **单独设计恢复能力:** 发布内容清单、区间/需求集合定义、影响预览、兼容性和冲突处理;优先复用已有单运行撤销。
5. **MCP 开放和业务平台视频优化分开排期。**
在动手实现恢复与审批扩展前,需要明确的产品选择只有三类:恢复操作的对象(Release/commit/Run)、独立回滚权限覆盖哪种恢复、业务责任人如何分配。其余可以先按上述试点默认值推进设计。

View File

@ -0,0 +1,8 @@
# Python packages of the protected checks' toolchain in the cluster image (cluster-poc.Dockerfile):
# what the Mac's /opt/homebrew python3 has and DroboticFlow's operator runner uses for video and
# dataset operators. Wheels for CPython 3.11 on Linux x86_64, installed with --require-hashes.
numpy==2.4.6 --hash=sha256:89cd468399cfd2504718f0ba50e410dca55a170b61a02ad92bb18c8a65186e93
opencv-python-headless==4.13.0.92 \
--hash=sha256:0bd48544f77c68b2941392fcdf9bcd2b9cdf00e98cb8c29b2455d194763cf99e \
--hash=sha256:0525a3d2c0b46c611e2130b5fdebc94cf404845d8fa64d2f3a3b679572a5bd22
PyYAML==6.0.3 --hash=sha256:b8bb0864c5a28024fac8a632c443c87c5aa6f215c0b126c449ae1a150412f31d

View File

@ -0,0 +1,91 @@
# syntax=docker/dockerfile:1
# WishForge's development deployment in the POC cluster (docs/cluster-poc-deployment.md): the
# source tree, run as on the operator Mac; the protected checks' toolchains; Claude Code; MinIO,
# built from its public source since its images are no longer published; Caddy; PostgreSQL's dump
# tools; and kubectl.
# Built by scripts/cluster-poc.mjs, which pins every input. No credentials or endpoints are baked in.
ARG NODE_IMAGE
ARG GO_IMAGE
ARG CADDY_IMAGE
ARG POSTGRES_IMAGE
FROM ${GO_IMAGE} AS go
FROM ${CADDY_IMAGE} AS caddy
FROM ${POSTGRES_IMAGE} AS postgres
FROM go AS minio
ARG MINIO_RELEASE
ARG MINIO_COMMIT
ARG GOPROXY=https://goproxy.cn,direct
RUN git clone --depth 1 --branch "${MINIO_RELEASE}" https://github.com/minio/minio.git /src/minio \
&& test "$(git -C /src/minio rev-parse HEAD)" = "${MINIO_COMMIT}" \
&& cd /src/minio \
&& CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o /out/minio . \
&& /out/minio --version
FROM ${NODE_IMAGE} AS platform
USER root
# python3 with NumPy, OpenCV and PyYAML, and ffmpeg, are part of the protected checks' toolchain, as
# they are in /opt/homebrew on the Mac: DroboticFlow's Go tests run its operator runner
# (backend/operator-runner/main.py), which uses them for video and dataset operators.
RUN apt-get update \
&& apt-get install -y --no-install-recommends git openssh-client ca-certificates tini sqlite3 procps \
python3 python3-pip ffmpeg \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd --gid 10001 wishforge \
&& useradd --uid 10001 --gid 10001 --create-home --home-dir /home/wishforge --shell /bin/bash wishforge
COPY infra/images/check-python-requirements.txt /tmp/check-python-requirements.txt
RUN python3 -m pip install --break-system-packages --no-cache-dir --no-deps --only-binary=:all: --require-hashes \
-r /tmp/check-python-requirements.txt \
&& rm /tmp/check-python-requirements.txt \
&& python3 -c "import cv2, numpy, yaml; print('check python', cv2.__version__, numpy.__version__, yaml.__version__)" \
&& ffmpeg -hide_banner -version | head -1
COPY --from=go /usr/local/go /usr/local/go
COPY --from=minio /out/minio /usr/local/bin/minio
# The official binary carries a file capability, which a Pod without privilege escalation cannot
# execute; install copies it without one. It listens on unprivileged ports.
COPY --from=caddy /usr/bin/caddy /tmp/caddy
RUN install -m 0755 /tmp/caddy /usr/local/bin/caddy && rm /tmp/caddy && caddy version
# pg_dump and pg_restore of the database's own release, for the daily backup
# (scripts/cluster-poc-backup.mjs): Debian's client is older than the server. The image has every
# library they link except libpq, which comes with them.
COPY --from=postgres /usr/lib/postgresql/17/bin/pg_dump /usr/lib/postgresql/17/bin/pg_restore /usr/local/bin/
COPY --from=postgres /usr/lib/x86_64-linux-gnu/libpq.so.5.18 /usr/local/lib/
RUN ln -s libpq.so.5.18 /usr/local/lib/libpq.so.5 && ldconfig \
&& ldd /usr/local/bin/pg_dump | grep -q 'libpq.so.5 => /usr/local/lib/' \
&& ! ldd /usr/local/bin/pg_dump /usr/local/bin/pg_restore | grep -q 'not found' \
&& pg_dump --version && pg_restore --version
COPY .cluster-poc-build/kubectl /usr/local/bin/kubectl
ARG KUBECTL_SHA256
RUN echo "${KUBECTL_SHA256} /usr/local/bin/kubectl" | sha256sum -c - && chmod 0755 /usr/local/bin/kubectl
ARG CLAUDE_CODE_VERSION
RUN npm install -g "@anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}" --no-audit --no-fund \
&& claude --version
ENV PATH=/usr/local/go/bin:${PATH}
WORKDIR /opt/wishforge
# The manifests of every workspace first: dependencies install once and stay cached while only
# sources change.
COPY package.json package-lock.json tsconfig.base.json ./
COPY apps/api/package.json ./apps/api/
COPY apps/web/package.json ./apps/web/
COPY apps/worker/package.json ./apps/worker/
COPY apps/runner/package.json ./apps/runner/
COPY apps/git-service/package.json ./apps/git-service/
COPY apps/provisioner/package.json ./apps/provisioner/
COPY packages/agent/package.json ./packages/agent/
COPY packages/artifacts/package.json ./packages/artifacts/
COPY packages/contracts/package.json ./packages/contracts/
COPY packages/github/package.json ./packages/github/
COPY packages/runtime/package.json ./packages/runtime/
RUN npm ci --ignore-scripts --no-audit --no-fund
COPY . .
# Protected checks keep their caches beside the script (scripts/poc-project-check.mjs): on the run
# volume here, which check Pods mount too. The web build gets only what decides its shape (local
# sign-in, production); secrets are read at run time, never here.
RUN rm -rf .cluster-poc-build \
&& mkdir -p .wishforge && ln -s /var/lib/wishforge/exec/check-cache .wishforge/poc-check-cache \
&& WF_LOCAL_ACCESS=true NODE_ENV=production NEXT_TELEMETRY_DISABLED=1 npm run build -w @wishforge/web \
&& node -e "Promise.all([import('@temporalio/worker'),import('tsx')]).then(()=>console.log('runtime dependencies loaded'))"
ENV NODE_ENV=development NEXT_TELEMETRY_DISABLED=1
USER 10001:10001
ENTRYPOINT ["/usr/bin/tini", "--", "node", "/opt/wishforge/scripts/cluster-poc-entry.mjs"]
CMD ["platform"]

View File

@ -0,0 +1,80 @@
# What WishForge's identity may create, whatever a leaked token asks for. Check Pods: the pinned
# WishForge image, a subdirectory of the run volume, scratch space, no Service Account token, no
# Secret in any form. Build Pods in droboticflow: the POC's pinned Kaniko image, its registry
# credential and scratch space. Requests of anyone else are not affected.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: wishforge-check-pods
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
failurePolicy: Fail
matchConstraints:
namespaceSelector: { matchLabels: { kubernetes.io/metadata.name: wishforge-checks } }
resourceRules:
- { apiGroups: [''], apiVersions: [v1], operations: [CREATE, UPDATE], resources: [pods] }
matchConditions:
- name: wishforge-identity
expression: "request.userInfo.username == 'system:serviceaccount:wishforge:wishforge'"
variables:
- name: claimVolumes
expression: 'has(object.spec.volumes) ? object.spec.volumes.filter(v, has(v.persistentVolumeClaim)).map(v, v.name) : []'
validations:
- expression: "object.spec.containers.all(c, c.image.startsWith('ccr-29eug8s3-vpc.cnc.bj.baidubce.com/dataflow-poc/wishforge-cluster-poc@sha256:'))"
message: Check Pods run only the pinned WishForge image.
- expression: '!has(object.spec.initContainers) && !has(object.spec.ephemeralContainers)'
message: Check Pods have one container.
- expression: "!has(object.spec.volumes) || object.spec.volumes.all(v, has(v.emptyDir) || (has(v.persistentVolumeClaim) && v.persistentVolumeClaim.claimName == 'wishforge-exec'))"
message: Check Pods mount only the run volume and scratch space.
- expression: "object.spec.containers.all(c, !has(c.volumeMounts) || c.volumeMounts.all(m, !(m.name in variables.claimVolumes) || (has(m.subPath) && !m.subPath.contains('..') && (m.subPath.startsWith('runs/') || m.subPath == 'check-cache'))))"
message: Check Pods mount one workspace or the checks' cache, never the whole run volume.
- expression: "has(object.spec.automountServiceAccountToken) && object.spec.automountServiceAccountToken == false && (!has(object.spec.serviceAccountName) || object.spec.serviceAccountName == 'default')"
message: Check Pods get no Service Account token.
- expression: 'object.spec.containers.all(c, !has(c.envFrom) && (!has(c.env) || c.env.all(e, !has(e.valueFrom))))'
message: Check Pods read no Secret or ConfigMap.
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: wishforge-check-pods
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
policyName: wishforge-check-pods
validationActions: [Deny]
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: wishforge-poc-build-pods
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
failurePolicy: Fail
matchConstraints:
namespaceSelector: { matchLabels: { kubernetes.io/metadata.name: droboticflow } }
resourceRules:
- { apiGroups: [''], apiVersions: [v1], operations: [CREATE, UPDATE], resources: [pods] }
matchConditions:
- name: wishforge-identity
expression: "request.userInfo.username == 'system:serviceaccount:wishforge:wishforge'"
validations:
- expression: "object.spec.containers.all(c, c.image == 'gcr.io/kaniko-project/executor@sha256:fb6d29da5792b6b9886bb132d1bb600bec79a47a31e4c152df3e52de9c561a44')"
message: Build Pods run only the POC's pinned Kaniko image.
- expression: '!has(object.spec.initContainers) && !has(object.spec.ephemeralContainers)'
message: Build Pods have one container.
- expression: "!has(object.spec.volumes) || object.spec.volumes.all(v, has(v.emptyDir) || (has(v.secret) && v.secret.secretName == 'droboticflow-registry'))"
message: Build Pods mount only scratch space and the registry credential.
- expression: 'has(object.spec.automountServiceAccountToken) && object.spec.automountServiceAccountToken == false'
message: Build Pods get no Service Account token.
- expression: '(!has(object.spec.hostNetwork) || !object.spec.hostNetwork) && (!has(object.spec.hostPID) || !object.spec.hostPID) && (!has(object.spec.hostIPC) || !object.spec.hostIPC)'
message: Build Pods share no host namespace.
- expression: 'object.spec.containers.all(c, (!has(c.securityContext) || !has(c.securityContext.privileged) || !c.securityContext.privileged) && !has(c.envFrom) && (!has(c.env) || c.env.all(e, !has(e.valueFrom))))'
message: Build Pods are not privileged and read no other Secret.
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: wishforge-poc-build-pods
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
policyName: wishforge-poc-build-pods
validationActions: [Deny]

View File

@ -0,0 +1,59 @@
# Applied once, then deleted (scripts/cluster-poc.mjs bootstrap): mounting this volume makes the
# kubelet create the data directory on the node, which a local volume needs to exist. The Pod that
# mounts it is restricted like every other and only exits; nothing of WishForge mounts a host path.
apiVersion: v1
kind: PersistentVolume
metadata:
name: wishforge-bootstrap
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
capacity: { storage: 1Gi }
accessModes: [ReadWriteOnce]
persistentVolumeReclaimPolicy: Retain
storageClassName: wishforge-bootstrap
hostPath: { path: /home/cce/wishforge, type: DirectoryOrCreate }
claimRef: { namespace: wishforge, name: wishforge-bootstrap }
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions: [{ key: kubernetes.io/hostname, operator: In, values: ['192.168.80.249'] }]
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wishforge-bootstrap
namespace: wishforge
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
storageClassName: wishforge-bootstrap
accessModes: [ReadWriteOnce]
volumeName: wishforge-bootstrap
resources: { requests: { storage: 1Gi } }
---
apiVersion: v1
kind: Pod
metadata:
name: wishforge-bootstrap
namespace: wishforge
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
restartPolicy: Never
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 10001
runAsGroup: 10001
seccompProfile: { type: RuntimeDefault }
containers:
- name: bootstrap
image: docker.io/library/node:24-alpine@sha256:8a32c8cf649a49915a66e81e7a609223c708d0adabf288ee3f4077d765542f85
command: ['/bin/true']
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: { drop: [ALL] }
resources: { requests: { cpu: 10m, memory: 16Mi }, limits: { cpu: 100m, memory: 64Mi } }
volumeMounts: [{ name: directory, mountPath: /mnt/directory, readOnly: true }]
volumes:
- name: directory
persistentVolumeClaim: { claimName: wishforge-bootstrap, readOnly: true }

View File

@ -0,0 +1,21 @@
# WishForge in the POC cluster (docs/cluster-poc-deployment.md). Both namespaces enforce the
# restricted Pod Security level: nothing WishForge runs needs privileges, host paths or added
# capabilities.
apiVersion: v1
kind: Namespace
metadata:
name: wishforge
labels:
app.kubernetes.io/part-of: wishforge-cluster-poc
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/enforce-version: v1.34
---
# Check Pods only: each mounts one workspace of the run volume, with no credentials.
apiVersion: v1
kind: Namespace
metadata:
name: wishforge-checks
labels:
app.kubernetes.io/part-of: wishforge-cluster-poc
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/enforce-version: v1.34

View File

@ -0,0 +1,276 @@
# WishForge in one Pod, laid out like the operator Mac it replaces (docs/cluster-poc-deployment.md):
# the database, Temporal and object storage, the platform services, the executor that runs Claude
# Code, the POC Runner, the daily backup and the HTTPS entry share the Pod's loopback. Only Caddy
# listens on the Pod's address, so nothing else is reachable from the cluster whether or not it
# enforces network policies. Protected checks run in check Pods (wishforge-checks), never here.
# ${WISHFORGE_IMAGE}, ${RUNNER_DISABLED} and ${MAINTENANCE} are filled in by scripts/cluster-poc.mjs apply.
apiVersion: v1
kind: Service
metadata:
name: wishforge
namespace: wishforge
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
clusterIP: None
selector: { app.kubernetes.io/name: wishforge }
ports: [{ name: https, port: 8443, targetPort: https }]
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: wishforge
namespace: wishforge
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc, app.kubernetes.io/name: wishforge }
spec:
serviceName: wishforge
replicas: 1
selector: { matchLabels: { app.kubernetes.io/name: wishforge } }
template:
metadata:
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc, app.kubernetes.io/name: wishforge }
# The settings the containers read when they start (cluster-poc.mjs secrets): a change rolls the Pod.
annotations: { wishforge.io/settings: "${SETTINGS_DIGEST}" }
spec:
serviceAccountName: wishforge
automountServiceAccountToken: false
enableServiceLinks: false
imagePullSecrets: [{ name: cce-image-credential-ccr-29eug8s3-vpc.cnc.bj.baidubce.com }]
terminationGracePeriodSeconds: 60
securityContext:
runAsNonRoot: true
runAsUser: 10001
runAsGroup: 10001
fsGroup: 10001
fsGroupChangePolicy: OnRootMismatch
seccompProfile: { type: RuntimeDefault }
initContainers:
# Each container's directory, owned by the Pod's user and private to it.
- name: prepare
image: ${WISHFORGE_IMAGE}
command: ['/bin/sh', '-ec']
args:
- |
cd /mnt/data
for dir in postgres temporal minio git platform-state platform-state/home poc-state runner-state exec exec/runs \
exec/check-cache claude-home claude-home-api git-home caddy caddy/data caddy/config backups; do
mkdir -p "$dir"
chmod 0700 "$dir"
done
securityContext: &restricted
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: { drop: [ALL] }
resources: { requests: { cpu: 10m, memory: 32Mi }, limits: { cpu: 200m, memory: 128Mi } }
volumeMounts: [{ name: data, mountPath: /mnt/data }]
containers:
- name: postgres
image: docker.io/library/postgres:17.6-bookworm@sha256:f3bd19c606e442c3d7bdfa8002e03fe260a1023351e0ea4598032022b68dd6e3
args: ['-c', 'listen_addresses=127.0.0.1']
env:
- { name: POSTGRES_USER, value: wishforge }
- { name: POSTGRES_DB, value: wishforge }
- { name: POSTGRES_PASSWORD, valueFrom: { secretKeyRef: { name: wishforge-postgres, key: password } } }
- { name: PGDATA, value: /var/lib/postgresql/data/pgdata }
# Every TCP connection authenticates, loopback included: the Pod's other containers share it.
# Only this container reaches the Unix socket.
- { name: POSTGRES_INITDB_ARGS, value: '--auth-host=scram-sha-256' }
securityContext: *restricted
resources: { requests: { cpu: 250m, memory: 512Mi }, limits: { cpu: '2', memory: 2Gi } }
readinessProbe:
exec: { command: [pg_isready, -h, 127.0.0.1, -U, wishforge, -d, wishforge] }
periodSeconds: 10
volumeMounts:
- { name: data, mountPath: /var/lib/postgresql/data, subPath: postgres }
- { name: postgres-run, mountPath: /var/run/postgresql }
- { name: postgres-tmp, mountPath: /tmp }
- name: temporal
image: docker.io/temporalio/temporal:1.4.1@sha256:9844298258519ebece82b3253f1ee1fc4eb8d87b7abcc264cfb676be342c74a5
# Its Web UI could stop workflows and has no sign-in: off.
args:
[
server,
start-dev,
--ip,
127.0.0.1,
--port,
'7233',
--headless,
--db-filename,
/var/lib/temporal/temporal.db,
]
# The Pod's user has no entry in this image; without cgo, Go reads its name from USER.
env: [{ name: HOME, value: /tmp }, { name: USER, value: temporal }]
securityContext: *restricted
resources: { requests: { cpu: 200m, memory: 512Mi }, limits: { cpu: '2', memory: 2Gi } }
readinessProbe:
exec: { command: [temporal, operator, cluster, health, --address, '127.0.0.1:7233'] }
periodSeconds: 10
timeoutSeconds: 8
volumeMounts:
- { name: data, mountPath: /var/lib/temporal, subPath: temporal }
- { name: temporal-tmp, mountPath: /tmp }
- name: minio
image: ${WISHFORGE_IMAGE}
command: [/usr/local/bin/minio]
args: [server, /data, --address, '127.0.0.1:9000', --console-address, '127.0.0.1:9001']
env:
- { name: MINIO_ROOT_USER, valueFrom: { secretKeyRef: { name: wishforge-minio, key: user } } }
- { name: MINIO_ROOT_PASSWORD, valueFrom: { secretKeyRef: { name: wishforge-minio, key: password } } }
- { name: MINIO_BROWSER, value: 'off' }
- { name: HOME, value: /tmp }
securityContext: *restricted
resources: { requests: { cpu: 200m, memory: 512Mi }, limits: { cpu: '2', memory: 2Gi } }
readinessProbe:
exec:
command:
- node
- -e
- "fetch('http://127.0.0.1:9000/minio/health/live').then(r => process.exit(r.ok ? 0 : 1), () => process.exit(1))"
periodSeconds: 10
volumeMounts:
- { name: data, mountPath: /data, subPath: minio }
- { name: minio-tmp, mountPath: /tmp }
- name: platform
image: ${WISHFORGE_IMAGE}
args: [platform]
env:
# Not /tmp: SWC (Temporal's workflow bundler) refuses a native-module cache under a
# directory others may write to, as every emptyDir is.
- { name: HOME, value: /var/lib/wishforge/platform-state/home }
- { name: TMPDIR, value: /tmp }
- { name: WF_MAINTENANCE, value: '${MAINTENANCE}' }
securityContext: *restricted
resources: { requests: { cpu: '1', memory: 3Gi }, limits: { cpu: '4', memory: 6Gi } }
readinessProbe:
exec:
command:
- node
- -e
- "Promise.all(['http://127.0.0.1:4000/readyz','http://127.0.0.1:3000/login'].map(u => fetch(u).then(r => { if (!r.ok) throw 0 }))).then(() => process.exit(0), () => process.exit(1))"
periodSeconds: 15
timeoutSeconds: 10
volumeMounts:
- { name: env-platform, mountPath: /etc/wishforge/env, readOnly: true }
- { name: claude, mountPath: /etc/wishforge/claude, readOnly: true }
- { name: keys, mountPath: /etc/wishforge/keys, readOnly: true }
- { name: config, mountPath: /etc/wishforge/config, readOnly: true }
- { name: data, mountPath: /var/lib/wishforge/git, subPath: git }
- { name: data, mountPath: /var/lib/wishforge/platform-state, subPath: platform-state }
- { name: data, mountPath: /var/lib/wishforge/poc-state, subPath: poc-state }
- { name: data, mountPath: /var/lib/wishforge/claude-home-api, subPath: claude-home-api }
- { name: platform-tmp, mountPath: /tmp }
- { name: web-cache, mountPath: /opt/wishforge/apps/web/.next/cache }
- name: executor
image: ${WISHFORGE_IMAGE}
args: [executor]
env:
- { name: HOME, value: /tmp }
- { name: TMPDIR, value: /tmp }
- { name: WF_MAINTENANCE, value: '${MAINTENANCE}' }
securityContext: *restricted
resources: { requests: { cpu: '1', memory: 2Gi }, limits: { cpu: '4', memory: 8Gi } }
readinessProbe:
exec:
command:
- node
- -e
- "fetch('http://127.0.0.1:4450/healthz').then(r => process.exit(r.ok ? 0 : 1), () => process.exit(1))"
periodSeconds: 15
volumeMounts:
- { name: env-executor, mountPath: /etc/wishforge/env, readOnly: true }
- { name: claude, mountPath: /etc/wishforge/claude, readOnly: true }
- { name: git-key, mountPath: /etc/wishforge/git, readOnly: true }
- { name: config, mountPath: /etc/wishforge/config, readOnly: true }
- { name: kube-token, mountPath: /var/run/wishforge/kube, readOnly: true }
- { name: data, mountPath: /var/lib/wishforge/exec, subPath: exec }
- { name: data, mountPath: /var/lib/wishforge/poc-state, subPath: poc-state }
- { name: data, mountPath: /var/lib/wishforge/claude-home, subPath: claude-home }
# The deploy key and pinned host keys, where OpenSSH looks: the image user's home.
- { name: data, mountPath: /home/wishforge, subPath: git-home }
- { name: executor-tmp, mountPath: /tmp }
- name: runner
image: ${WISHFORGE_IMAGE}
args: [runner]
env:
- { name: HOME, value: /tmp }
- { name: TMPDIR, value: /tmp }
- { name: WF_RUNNER_DISABLED, value: '${RUNNER_DISABLED}' }
- { name: WF_MAINTENANCE, value: '${MAINTENANCE}' }
securityContext: *restricted
resources: { requests: { cpu: 100m, memory: 256Mi }, limits: { cpu: '1', memory: 1Gi } }
volumeMounts:
- { name: env-runner, mountPath: /etc/wishforge/env, readOnly: true }
- { name: config, mountPath: /etc/wishforge/config, readOnly: true }
- { name: kube-token, mountPath: /var/run/wishforge/kube, readOnly: true }
- { name: data, mountPath: /var/lib/wishforge/runner-state, subPath: runner-state }
- { name: data, mountPath: /var/lib/wishforge/poc-state, subPath: poc-state }
- { name: runner-tmp, mountPath: /tmp }
# Daily snapshots of the data onto this node's disk (scripts/cluster-poc-backup.mjs); the
# operator Mac copies them off the node (cluster-poc.mjs backup). It reads the data it saves
# read-only and the database through loopback; it has no token, settings or keys.
- name: backup
image: ${WISHFORGE_IMAGE}
args: [backup]
env:
- { name: HOME, value: /tmp }
- { name: TMPDIR, value: /tmp }
- { name: WF_MAINTENANCE, value: '${MAINTENANCE}' }
- { name: WF_IMAGE, value: '${WISHFORGE_IMAGE}' }
- { name: PGPASSWORD, valueFrom: { secretKeyRef: { name: wishforge-postgres, key: password } } }
securityContext: *restricted
resources: { requests: { cpu: 50m, memory: 128Mi }, limits: { cpu: '1', memory: 1Gi } }
volumeMounts:
- { name: data, mountPath: /var/lib/wishforge/backups, subPath: backups }
- { name: data, mountPath: /mnt/data/git, subPath: git, readOnly: true }
- { name: data, mountPath: /mnt/data/minio, subPath: minio, readOnly: true }
- { name: data, mountPath: /mnt/data/platform-state, subPath: platform-state, readOnly: true }
- { name: data, mountPath: /mnt/data/poc-state, subPath: poc-state, readOnly: true }
- { name: data, mountPath: /mnt/data/runner-state, subPath: runner-state, readOnly: true }
- { name: data, mountPath: /mnt/data/temporal, subPath: temporal, readOnly: true }
- { name: backup-tmp, mountPath: /tmp }
- name: caddy
image: ${WISHFORGE_IMAGE}
command: [/usr/local/bin/caddy]
args: [run, --config, /etc/caddy/Caddyfile, --adapter, caddyfile]
env:
- { name: HOME, value: /tmp }
- { name: XDG_DATA_HOME, value: /var/lib/caddy/data }
- { name: XDG_CONFIG_HOME, value: /var/lib/caddy/config }
ports:
- { name: http, containerPort: 8080 }
- { name: https, containerPort: 8443 }
securityContext: *restricted
resources: { requests: { cpu: 50m, memory: 64Mi }, limits: { cpu: '1', memory: 512Mi } }
volumeMounts:
- { name: caddyfile, mountPath: /etc/caddy, readOnly: true }
- { name: data, mountPath: /var/lib/caddy, subPath: caddy }
- { name: caddy-tmp, mountPath: /tmp }
volumes:
- { name: data, persistentVolumeClaim: { claimName: wishforge-data } }
# Each container reads only its own settings: the executor never sees the database's.
- name: env-platform
secret: { secretName: wishforge-env, defaultMode: 288, items: [{ key: platform.env, path: platform.env }] }
- name: env-executor
secret: { secretName: wishforge-env, defaultMode: 288, items: [{ key: executor.env, path: executor.env }] }
- name: env-runner
secret: { secretName: wishforge-env, defaultMode: 288, items: [{ key: runner.env, path: runner.env }] }
- { name: claude, secret: { secretName: wishforge-claude, defaultMode: 288 } }
- { name: git-key, secret: { secretName: wishforge-git, defaultMode: 288 } }
- { name: keys, secret: { secretName: wishforge-keys, defaultMode: 288 } }
- { name: config, configMap: { name: wishforge-config } }
- { name: caddyfile, configMap: { name: wishforge-caddy } }
# Short-lived and rotated by the kubelet; only the executor and the Runner mount it.
- name: kube-token
projected:
defaultMode: 288
sources: [{ serviceAccountToken: { path: token, expirationSeconds: 3600 } }]
- { name: postgres-run, emptyDir: {} }
- { name: postgres-tmp, emptyDir: { sizeLimit: 1Gi } }
- { name: temporal-tmp, emptyDir: { sizeLimit: 1Gi } }
- { name: minio-tmp, emptyDir: { sizeLimit: 1Gi } }
- { name: platform-tmp, emptyDir: { sizeLimit: 4Gi } }
- { name: web-cache, emptyDir: { sizeLimit: 2Gi } }
- { name: executor-tmp, emptyDir: { sizeLimit: 10Gi } }
- { name: runner-tmp, emptyDir: { sizeLimit: 2Gi } }
- { name: caddy-tmp, emptyDir: { sizeLimit: 256Mi } }
- { name: backup-tmp, emptyDir: { sizeLimit: 256Mi } }

View File

@ -0,0 +1,23 @@
# The public entry: a load balancer and elastic IP of WishForge's own (billed while they exist),
# never the POC's. Applied by scripts/cluster-poc.mjs public, not with the rest; `public --http`
# applies it without the HTTPS port.
apiVersion: v1
kind: Service
metadata:
name: wishforge-public
namespace: wishforge
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
annotations:
service.beta.kubernetes.io/cce-load-balancer-lb-name: wishforge-public
service.beta.kubernetes.io/cce-load-balancer-internal-vpc: 'false'
service.beta.kubernetes.io/cce-elastic-ip-route-type: BGP
service.beta.kubernetes.io/cce-elastic-ip-billing-method: ByTraffic
service.beta.kubernetes.io/cce-elastic-ip-bandwidth-in-mbps: '5'
service.beta.kubernetes.io/blb-performance-level: small1
spec:
type: LoadBalancer
externalTrafficPolicy: Cluster
selector: { app.kubernetes.io/name: wishforge }
ports:
- { name: http, protocol: TCP, port: 80, targetPort: http }
- { name: https, protocol: TCP, port: 443, targetPort: https }

View File

@ -0,0 +1,91 @@
# WishForge's one identity in the cluster. Its token is mounted only into the executor and Runner
# containers. It replaces the operator Mac's cluster-admin kubeconfig with the least the POC needs:
# check Pods in wishforge-checks, build Pods and the three POC Deployments in droboticflow.
apiVersion: v1
kind: ServiceAccount
metadata:
name: wishforge
namespace: wishforge
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
automountServiceAccountToken: false
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: wishforge-checks
namespace: wishforge-checks
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
rules:
- apiGroups: ['']
resources: [pods]
verbs: [create, get, list, watch, delete]
- apiGroups: ['']
resources: [pods/exec]
verbs: [create, get]
- apiGroups: ['']
resources: [pods/log]
verbs: [get]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: wishforge-checks
namespace: wishforge-checks
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
roleRef: { apiGroup: rbac.authorization.k8s.io, kind: Role, name: wishforge-checks }
subjects: [{ kind: ServiceAccount, name: wishforge, namespace: wishforge }]
---
# The POC delivery (packages/runtime/src/poc-release.ts, poc-build.ts): read and update the three
# Deployments' images, watch their rollouts, and run Kaniko build Pods.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: wishforge-poc
namespace: droboticflow
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
rules:
- apiGroups: [apps]
resources: [deployments]
resourceNames: [droboticflow-api, droboticflow-worker, drosync-coordinator]
verbs: [get, patch]
- apiGroups: [apps]
resources: [deployments, replicasets]
verbs: [list, watch]
- apiGroups: ['']
resources: [pods]
verbs: [create, get, list, watch, delete]
- apiGroups: ['']
resources: [pods/exec]
verbs: [create, get]
- apiGroups: ['']
resources: [pods/log]
verbs: [get]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: wishforge-poc
namespace: droboticflow
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
roleRef: { apiGroup: rbac.authorization.k8s.io, kind: Role, name: wishforge-poc }
subjects: [{ kind: ServiceAccount, name: wishforge, namespace: wishforge }]
---
# The delivery confirms the namespace's UID before acting; only that namespace is readable.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: wishforge-poc-namespace
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
rules:
- apiGroups: ['']
resources: [namespaces]
resourceNames: [droboticflow]
verbs: [get]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: wishforge-poc-namespace
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
roleRef: { apiGroup: rbac.authorization.k8s.io, kind: ClusterRole, name: wishforge-poc-namespace }
subjects: [{ kind: ServiceAccount, name: wishforge, namespace: wishforge }]

View File

@ -0,0 +1,64 @@
# The node-local disk of 192.168.80.249 holds everything WishForge keeps, as other POCs in this
# cluster do; the volume's node affinity places the Pods there. Retained when released: deleting a
# claim never deletes data. The directories are created once (bootstrap/directories.yaml).
apiVersion: v1
kind: PersistentVolume
metadata:
name: wishforge-data
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
capacity: { storage: 100Gi }
accessModes: [ReadWriteOnce]
persistentVolumeReclaimPolicy: Retain
storageClassName: wishforge-node-local
volumeMode: Filesystem
local: { path: /home/cce/wishforge }
claimRef: { namespace: wishforge, name: wishforge-data }
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions: [{ key: kubernetes.io/hostname, operator: In, values: ['192.168.80.249'] }]
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wishforge-data
namespace: wishforge
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
storageClassName: wishforge-node-local
accessModes: [ReadWriteOnce]
volumeName: wishforge-data
resources: { requests: { storage: 100Gi } }
---
# Only the run directory of that disk, for check Pods: workspaces and the checks' caches, never the
# database, keys or settings beside it.
apiVersion: v1
kind: PersistentVolume
metadata:
name: wishforge-checks-exec
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
capacity: { storage: 100Gi }
accessModes: [ReadWriteOnce]
persistentVolumeReclaimPolicy: Retain
storageClassName: wishforge-checks-local
volumeMode: Filesystem
local: { path: /home/cce/wishforge/exec }
claimRef: { namespace: wishforge-checks, name: wishforge-exec }
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions: [{ key: kubernetes.io/hostname, operator: In, values: ['192.168.80.249'] }]
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wishforge-exec
namespace: wishforge-checks
labels: { app.kubernetes.io/part-of: wishforge-cluster-poc }
spec:
storageClassName: wishforge-checks-local
accessModes: [ReadWriteOnce]
volumeName: wishforge-checks-exec
resources: { requests: { storage: 100Gi } }

View File

@ -0,0 +1,21 @@
bindAddr = "0.0.0.0"
bindPort = 7000
proxyBindAddr = "0.0.0.0"
allowPorts = [{ single = 18080 }, { single = 18443 }]
maxPortsPerClient = 2
transport.tls.force = true
transport.tls.certFile = "/run/entry-secret/server.crt"
transport.tls.keyFile = "/run/entry-secret/server.key"
transport.tls.trustedCaFile = "/run/entry-secret/ca.crt"
auth.method = "token"
auth.additionalScopes = ["HeartBeats", "NewWorkConns"]
auth.tokenSource.type = "file"
auth.tokenSource.file.path = "/run/entry-secret/token"
log.to = "console"
log.level = "info"
log.disablePrintColor = true
[[httpPlugins]]
name = "wishforge-web-only"
addr = "127.0.0.1:19000"
path = "/validate"
ops = ["NewProxy"]

View File

@ -0,0 +1,123 @@
apiVersion: v1
kind: Namespace
metadata:
name: wishforge-access
labels:
app.kubernetes.io/part-of: wishforge-local-entry
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/enforce-version: v1.34
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: local-entry
namespace: wishforge-access
labels:
app.kubernetes.io/part-of: wishforge-local-entry
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
app.kubernetes.io/name: wishforge-local-entry
template:
metadata:
labels:
app.kubernetes.io/name: wishforge-local-entry
app.kubernetes.io/part-of: wishforge-local-entry
spec:
automountServiceAccountToken: false
terminationGracePeriodSeconds: 20
nodeSelector:
kubernetes.io/os: linux
kubernetes.io/arch: amd64
securityContext:
runAsNonRoot: true
runAsUser: 10001
runAsGroup: 10001
fsGroup: 10001
seccompProfile:
type: RuntimeDefault
containers:
- name: frps
image: docker.io/fatedier/frps:v0.71.1@sha256:48720c81f048e842f7f0b8053753c1a8514053d59d2dee8a953f67995de73a18
args: ['-c', '/etc/entry/frps.toml']
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
resources:
requests: { cpu: 100m, memory: 64Mi }
limits: { cpu: 500m, memory: 256Mi }
ports:
- { name: tunnel, containerPort: 7000 }
- { name: web-http, containerPort: 18080 }
- { name: web-https, containerPort: 18443 }
readinessProbe:
tcpSocket: { port: tunnel }
periodSeconds: 5
livenessProbe:
tcpSocket: { port: tunnel }
initialDelaySeconds: 15
periodSeconds: 15
volumeMounts:
- { name: config, mountPath: /etc/entry, readOnly: true }
- { name: credentials, mountPath: /run/entry-secret, readOnly: true }
- name: proxy-policy
image: docker.io/library/node:24-alpine@sha256:8a32c8cf649a49915a66e81e7a609223c708d0adabf288ee3f4077d765542f85
command: ['node', '/etc/entry/proxy-policy.mjs']
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
resources:
requests: { cpu: 25m, memory: 32Mi }
limits: { cpu: 100m, memory: 128Mi }
readinessProbe:
exec:
command: ['node', '/etc/entry/proxy-policy.mjs', '--check']
timeoutSeconds: 3
periodSeconds: 10
livenessProbe:
exec:
command: ['node', '/etc/entry/proxy-policy.mjs', '--check']
timeoutSeconds: 3
initialDelaySeconds: 15
periodSeconds: 20
volumeMounts:
- { name: config, mountPath: /etc/entry, readOnly: true }
volumes:
- name: config
configMap: { name: entry-config }
- name: credentials
secret:
secretName: entry-mtls
defaultMode: 0440
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: wishforge-access
spec:
podSelector: {}
policyTypes: [Ingress, Egress]
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: entry-ports
namespace: wishforge-access
spec:
podSelector:
matchLabels:
app.kubernetes.io/name: wishforge-local-entry
policyTypes: [Ingress]
ingress:
- ports:
- { protocol: TCP, port: 7000 }
- { protocol: TCP, port: 18080 }
- { protocol: TCP, port: 18443 }

View File

@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: wishforge-access
resources:
- gateway.yaml
configMapGenerator:
- name: entry-config
files:
- frps.toml
- proxy-policy.mjs

View File

@ -0,0 +1,76 @@
import http from 'node:http';
import { realpathSync } from 'node:fs';
import { pathToFileURL } from 'node:url';
export const POLICY_PORT = 19000;
const ports = new Map([
['wishforge-http', 18080],
['wishforge-https', 18443],
]);
/** FRP's NewProxy hook: only the two named web transports, never another proxy type. */
export function proxyDecision(request) {
const proxy = request?.content;
const allowed =
request?.op === 'NewProxy' &&
proxy?.proxy_type === 'tcp' &&
ports.has(proxy.proxy_name) &&
ports.get(proxy.proxy_name) === proxy.remote_port &&
!proxy.group &&
!proxy.group_key &&
!proxy.custom_domains?.length &&
!proxy.subdomain &&
!proxy.multiplexer;
return allowed
? { reject: false, unchange: true }
: { reject: true, reject_reason: 'Only the configured WishForge HTTP and HTTPS TCP proxies are allowed' };
}
/** Loopback only; no request bodies or authentication material enter logs. */
export function policyServer() {
return http.createServer({ requestTimeout: 5000, headersTimeout: 5000, maxHeaderSize: 8192 }, async (req, res) => {
const reply = (status, body) => {
res.writeHead(status, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
res.end(JSON.stringify(body));
};
if (req.method === 'GET' && req.url === '/healthz') return reply(200, { ready: true });
if (req.method !== 'POST' || req.url?.split('?')[0] !== '/validate')
return reply(403, { reject: true, reject_reason: 'Unsupported operation' });
try {
const chunks = [];
let size = 0;
for await (const chunk of req) {
size += chunk.length;
if (size > 16384) {
reply(413, { reject: true, reject_reason: 'Request too large' });
req.destroy();
return;
}
chunks.push(chunk);
}
reply(200, proxyDecision(JSON.parse(Buffer.concat(chunks).toString('utf8'))));
} catch {
if (!res.headersSent) reply(400, { reject: true, reject_reason: 'Invalid request' });
}
});
}
/** ConfigMap mounts use symlinks; Node resolves the main module but keeps the original argv path. */
export function isPolicyMain(moduleUrl, script = process.argv[1]) {
try {
return Boolean(script && moduleUrl === pathToFileURL(realpathSync(script)).href);
} catch {
return false;
}
}
if (isPolicyMain(import.meta.url)) {
if (process.argv[2] === '--check') {
const response = await fetch(`http://127.0.0.1:${POLICY_PORT}/healthz`, { signal: AbortSignal.timeout(1500) });
if (!response.ok || !(await response.json()).ready) process.exitCode = 1;
} else {
const server = policyServer();
server.listen(POLICY_PORT, '127.0.0.1');
for (const signal of ['SIGTERM', 'SIGINT']) process.once(signal, () => server.close());
}
}

View File

@ -0,0 +1,25 @@
# Apply separately, only after the isolated gateway and NetworkPolicy checks pass.
# This creates a NEW billable BLB/EIP. It never references an existing business load balancer.
apiVersion: v1
kind: Service
metadata:
name: local-entry-public
namespace: wishforge-access
labels:
app.kubernetes.io/part-of: wishforge-local-entry
annotations:
service.beta.kubernetes.io/cce-load-balancer-lb-name: wishforge-access-local-entry
service.beta.kubernetes.io/cce-load-balancer-internal-vpc: 'false'
service.beta.kubernetes.io/cce-elastic-ip-route-type: BGP
service.beta.kubernetes.io/cce-elastic-ip-billing-method: ByTraffic
service.beta.kubernetes.io/cce-elastic-ip-bandwidth-in-mbps: '5'
service.beta.kubernetes.io/blb-performance-level: small1
spec:
type: LoadBalancer
externalTrafficPolicy: Cluster
selector:
app.kubernetes.io/name: wishforge-local-entry
ports:
- { name: http, protocol: TCP, port: 80, targetPort: web-http }
- { name: https, protocol: TCP, port: 443, targetPort: web-https }
- { name: tunnel, protocol: TCP, port: 7000, targetPort: tunnel }

View File

@ -308,8 +308,11 @@ export interface Evidence extends Entity {
backendPaths?: string[];
/** How the checks were isolated; production only accepts sandboxed verification. */
isolation?: 'host' | 'sandbox';
/** Development checks the operator sandboxed on macOS; still `host` isolation, never production evidence. */
checkSandbox?: 'seatbelt';
/**
* Development checks the operator sandboxed: under Seatbelt on macOS, or each in a credential-free
* check Pod of its own in the cluster. Still `host` isolation, never production evidence.
*/
checkSandbox?: 'seatbelt' | 'pod';
/** Integration evidence: the branch that received the commit, or the conflict that prevented it. */
targetRef?: string;
targetCommit?: string;
@ -644,7 +647,7 @@ export const evidenceInput = z
changedManifests: z.array(text.max(1024)).max(200).optional(),
backendPaths: z.array(text.max(1024)).max(200).optional(),
isolation: z.enum(['host', 'sandbox']).optional(),
checkSandbox: z.literal('seatbelt').optional(),
checkSandbox: z.enum(['seatbelt', 'pod']).optional(),
targetRef: z
.string()
.regex(/^refs\/heads\/[A-Za-z0-9._/-]{1,200}$/)

View File

@ -0,0 +1,547 @@
import { spawnSync } from 'node:child_process';
import { createHash, randomBytes } from 'node:crypto';
import { lstat, mkdir, mkdtemp, realpath } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { executeCommand, type Command, type CommandExecutor, type CommandResult } from './process.js';
import { RuntimeError } from './types.js';
/**
* Where a cluster-hosted development deployment runs protected checks and dependency
* installations: each workspace in a short-lived Pod of its own, in a namespace that holds no
* platform data. The Pod mounts only that workspace (its `.git` read-only) and the shared caches
* from the run volume, gets no credentials, Service Account token or platform service, and runs
* as the worker's own user under the default seccomp profile.
*/
export interface CheckPodConfig {
/** Absolute path of kubectl. */
kubectl: string;
/** Kubeconfig of an identity that may manage Pods in `namespace`, and nothing else. */
kubeconfig: string;
namespace: string;
/** The protected toolchain image, pinned by digest. */
image: string;
/** Claim in `namespace` on the run volume; the volume's node affinity places the Pods. */
claim: string;
/** Where this process sees the root of that volume. */
mountRoot: string;
/** Paths under mountRoot the commands may also write: caches shared between runs. */
writable: string[];
/** The user and group the commands run as: the owners of the run volume's files. */
uid: number;
gid: number;
/** Labels the Pods with their owner (this worker), so leftovers can be found. */
owner: string;
cpu?: string;
memory?: string;
/** The longest a Pod lives, so one its worker lost ends by itself. */
maxLifetimeSeconds?: number;
/** How long an unused Pod is kept for the workspace's next command. */
idleMs?: number;
}
const IMAGE = /^[a-z0-9][a-z0-9._:/-]*@sha256:[a-f0-9]{64}$/;
const NAME = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/;
const VARIABLE = /^[A-Za-z_][A-Za-z0-9_]*$/;
const MARKER = '__WISHFORGE_CHECK_EXIT__=';
// Runs inside the Pod: $1 directory, $2 home, $3 temporary directory, then the command itself.
const WRAPPER = `mkdir -p -- "$2" "$3" || exit 125; cd -- "$1" || exit 125; shift 3; "$@"; code=$?; printf '\\n${MARKER}%s\\n' "$code" >&2; exit "$code"`;
/** Whether `location` is `base` or inside it; both must already be resolved. */
const within = (base: string, location: string) => {
const relative = path.relative(base, location);
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
};
const short = (value: string) => createHash('sha256').update(value).digest('hex').slice(0, 10);
export function validateCheckPodConfig(config: CheckPodConfig): CheckPodConfig {
for (const [name, value] of [
['kubectl', config.kubectl],
['kubeconfig', config.kubeconfig],
['mountRoot', config.mountRoot],
...config.writable.map(location => ['writable', location] as const),
] as const)
if (!path.isAbsolute(value) || /[\0\r\n]/.test(value))
throw new RuntimeError('CHECK_POD_CONFIG', `Check Pod ${name} must be an absolute path`);
if (!NAME.test(config.namespace) || !NAME.test(config.claim))
throw new RuntimeError('CHECK_POD_CONFIG', 'Check Pod namespace and claim must be Kubernetes names');
if (!IMAGE.test(config.image))
throw new RuntimeError('CHECK_POD_CONFIG', 'The check Pod image must be pinned by digest');
if (!Number.isInteger(config.uid) || config.uid < 1 || !Number.isInteger(config.gid) || config.gid < 1)
throw new RuntimeError('CHECK_POD_CONFIG', 'Check Pods never run as root');
if (config.writable.some(location => !within(path.resolve(config.mountRoot), path.resolve(location))))
throw new RuntimeError('CHECK_POD_CONFIG', 'Writable check paths must lie on the run volume');
return config;
}
/** The mounts of one workspace's Pod: the workspace, its `.git` read-only, and the caches. */
export interface CheckPodMounts {
root: string;
/** Path of the workspace relative to the volume root. */
rootSubPath: string;
git?: 'directory' | 'file';
writable: { path: string; subPath: string }[];
}
/** The Pod that runs one workspace's commands; see {@link CheckPodConfig}. */
export function checkPodManifest(config: CheckPodConfig, name: string, mounts: CheckPodMounts) {
return {
apiVersion: 'v1',
kind: 'Pod',
metadata: {
name,
namespace: config.namespace,
labels: {
'app.kubernetes.io/part-of': 'wishforge-cluster-poc',
'app.kubernetes.io/name': 'wishforge-check',
'wishforge.io/owner': short(config.owner),
},
},
spec: {
restartPolicy: 'Never',
automountServiceAccountToken: false,
enableServiceLinks: false,
terminationGracePeriodSeconds: 5,
activeDeadlineSeconds: config.maxLifetimeSeconds ?? 7200,
securityContext: {
runAsNonRoot: true,
runAsUser: config.uid,
runAsGroup: config.gid,
seccompProfile: { type: 'RuntimeDefault' },
},
containers: [
{
name: 'check',
image: config.image,
command: ['/bin/sh', '-c', 'trap "exit 0" TERM; while :; do sleep 600 & wait $!; done'],
workingDir: mounts.root,
securityContext: {
allowPrivilegeEscalation: false,
readOnlyRootFilesystem: true,
capabilities: { drop: ['ALL'] },
},
resources: {
requests: { cpu: '500m', memory: '1Gi' },
limits: { cpu: config.cpu ?? '4', memory: config.memory ?? '8Gi' },
},
volumeMounts: [
{ name: 'run', mountPath: mounts.root, subPath: mounts.rootSubPath },
...(mounts.git
? [
{
name: 'run',
mountPath: path.join(mounts.root, '.git'),
subPath: path.posix.join(mounts.rootSubPath, '.git'),
readOnly: true,
},
]
: []),
...mounts.writable.map(item => ({ name: 'run', mountPath: item.path, subPath: item.subPath })),
{ name: 'tmp', mountPath: '/tmp' },
],
},
],
volumes: [
{ name: 'run', persistentVolumeClaim: { claimName: config.claim } },
{ name: 'tmp', emptyDir: { sizeLimit: '8Gi' } },
],
},
};
}
/**
* The command line that runs `command` in the Pod: a clean environment with only the command's
* own variables, its directory, a home and temporary directory of its own unless the command's
* lie in what it may write, and a time limit that outlasts the worker's own. The exit status is
* reported after the output, so a failure to reach the Pod is never taken for the command's.
*/
export function checkPodExec(
config: Pick<CheckPodConfig, 'kubectl' | 'kubeconfig' | 'namespace'>,
pod: string,
command: Command,
directories: { home: string; temporary: string },
cacheDirectory: string,
): string[] {
const env = { ...command.env, HOME: directories.home, TMPDIR: directories.temporary };
const variables = Object.entries(env).flatMap(([name, value]) => {
if (!VARIABLE.test(name)) throw new RuntimeError('INVALID_VERIFIER_COMMAND', `Invalid variable name: ${name}`);
return value === undefined ? [] : [`${name}=${value}`];
});
const seconds = Math.ceil((command.timeoutMs ?? 120_000) / 1000) + 60;
return [
'--kubeconfig',
config.kubeconfig,
`--cache-dir=${cacheDirectory}`,
'-n',
config.namespace,
'exec',
...(command.input === undefined ? [] : ['-i']),
pod,
'-c',
'check',
'--',
'/usr/bin/env',
'-i',
...variables,
'/usr/bin/timeout',
'-k',
'10',
String(seconds),
'/bin/sh',
'-c',
WRAPPER,
'wishforge-check',
command.cwd!,
directories.home,
directories.temporary,
command.executable,
...command.args,
];
}
/** The command's own exit status and output, or undefined when kubectl never reached it. */
export function checkPodResult(result: CommandResult): CommandResult | undefined {
const at = result.stderr.lastIndexOf(MARKER);
if (at < 0) return undefined;
const match = /^(\d{1,3})\r?\n?/.exec(result.stderr.slice(at + MARKER.length));
if (!match) return undefined;
const before = result.stderr.slice(0, at).replace(/\r?\n$/, '');
const after = result.stderr
.slice(at + MARKER.length + match[0].length)
.replace(/^command terminated with exit code \d+\r?\n?/m, '');
return { exitCode: Number(match[1]), stdout: result.stdout, stderr: before + after };
}
/** Pods to remove when the process exits; one hook for every executor in it. */
const leftovers = new Set<() => void>();
let exitHook = false;
function removeAtExit(cleanup: () => void) {
leftovers.add(cleanup);
if (!exitHook) {
exitHook = true;
process.once('exit', () => leftovers.forEach(remove => remove()));
}
return () => leftovers.delete(cleanup);
}
interface PodEntry {
name: string;
key: string;
ready: Promise<void>;
creating?: Promise<CommandResult>;
creationConfirmed: boolean;
removing?: Promise<void>;
retired: boolean;
users: number;
idle?: ReturnType<typeof setTimeout>;
}
// The provisioner may force-stop a worker after three seconds during its own shutdown.
const CLEANUP_MS = 2000;
function cleanupBudget() {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), CLEANUP_MS);
return { signal: controller.signal, until: Date.now() + CLEANUP_MS, close: () => clearTimeout(timer) };
}
type CleanupBudget = ReturnType<typeof cleanupBudget>;
const unavailable = (message: string) => new RuntimeError('VERIFIER_ISOLATION_UNAVAILABLE', message);
function withinBudget<T>(work: Promise<T>, budget: CleanupBudget): Promise<T> {
return new Promise((resolve, reject) => {
const abort = () => reject(unavailable('Check Pod cleanup exceeded its deadline; cleanup remains pending'));
budget.signal.addEventListener('abort', abort, { once: true });
if (budget.signal.aborted) abort();
work.then(resolve, reject).finally(() => budget.signal.removeEventListener('abort', abort));
});
}
/**
* A {@link CommandExecutor} that runs every command in its workspace's check Pod (see
* {@link CheckPodConfig}). Creation and Ready failures are infrastructure faults, never failing
* checks. The transport must be raw: only execution gets the caller's cancellation signal;
* cleanup has its own bounded lifetime, including after that signal was canceled.
*/
export function checkPodExecutor(
input: CheckPodConfig,
execute: CommandExecutor = executeCommand,
): CommandExecutor & { dispose(): Promise<void> } {
const config = validateCheckPodConfig(input);
const pods = new Map<string, PodEntry>();
// Retiring a cached Pod does not discharge responsibility for deleting it.
const owned = new Set<PodEntry>();
const pending = new Set<Promise<CommandResult>>();
const stopping = new AbortController();
let closed = false;
let sequence = 0;
let disposal: Promise<void> | undefined;
let closeBudget: CleanupBudget | undefined;
let prepared:
Promise<{ mountRoot: string; writable: { path: string; subPath: string }[]; cache: string }> | undefined;
const env = { PATH: '/usr/local/bin:/usr/bin:/bin', HOME: os.tmpdir(), LANG: 'C.UTF-8' };
const kubectl = async (args: string[], options: Partial<Command> = {}) =>
execute({
executable: config.kubectl,
args: ['--kubeconfig', config.kubeconfig, '-n', config.namespace, ...args],
cwd: config.mountRoot,
env,
timeoutMs: 60_000,
...options,
});
const active = (signal: AbortSignal) => {
if (closed || signal.aborted) throw new RuntimeError('CANCELED', 'Check command was canceled');
};
const forgetIfClosed = () => {
if (closed && !pending.size && !owned.size) forget();
};
const warn = (entry: PodEntry) => {
console.warn(`[check-pod] ${config.namespace}/${entry.name}: deletion not confirmed; cleanup remains pending`);
};
const prepare = async () => {
const mountRoot = await realpath(config.mountRoot);
const writable = [];
for (const location of config.writable) {
await mkdir(location, { recursive: true, mode: 0o700 });
const resolved = await realpath(location);
if (!within(mountRoot, resolved)) throw unavailable(`Writable check path ${location} leaves the run volume`);
writable.push({ path: resolved, subPath: path.relative(mountRoot, resolved).split(path.sep).join('/') });
}
const cache = await mkdtemp(path.join(os.tmpdir(), 'wishforge-kubectl-'));
return { mountRoot, writable, cache };
};
const remove = (entry: PodEntry, sharedBudget = closeBudget): Promise<void> => {
clearTimeout(entry.idle);
entry.retired = true;
if (pods.get(entry.key) === entry) pods.delete(entry.key);
if (!owned.has(entry)) return Promise.resolve();
if (entry.removing) return entry.removing;
const budget = sharedBudget ?? cleanupBudget();
entry.removing = (async () => {
// A delete that sees NotFound before create finishes must not forget a late creation.
await withinBudget(
entry.creating?.then(
() => undefined,
() => undefined,
) ?? Promise.resolve(),
budget,
);
const remaining = budget.until - Date.now();
if (remaining <= 0 || budget.signal.aborted) throw unavailable('Check Pod cleanup exceeded its deadline');
const result = await withinBudget(
kubectl(
['delete', 'pod', entry.name, '--ignore-not-found', '--wait=true', '-o', 'name', `--timeout=${remaining}ms`],
{ timeoutMs: remaining, signal: budget.signal },
),
budget,
);
if (
result.exitCode !== 0 ||
(!entry.creationConfirmed && !result.stdout.trim().split(/\r?\n/).includes(`pod/${entry.name}`))
)
throw unavailable(`Deletion of check Pod ${config.namespace}/${entry.name} was not confirmed`);
owned.delete(entry);
forgetIfClosed();
})().finally(() => {
entry.removing = undefined;
if (!sharedBudget) budget.close();
});
return entry.removing;
};
const cleanupAfterError = async (entry: PodEntry) => {
try {
await remove(entry);
} catch {
// Keep the command's original cancellation/timeout, and retry at dispose or process exit.
warn(entry);
}
};
const start = async (entry: PodEntry, mounts: CheckPodMounts, signal: AbortSignal) => {
try {
active(signal);
entry.creating = kubectl(['create', '-f', '-', '-o', 'name'], {
input: JSON.stringify(checkPodManifest(config, entry.name, mounts)),
signal,
}).then(result => {
entry.creationConfirmed = result.exitCode === 0;
return result;
});
const created = await entry.creating;
active(signal);
if (created.exitCode !== 0)
throw unavailable(`Cannot create a check Pod: ${created.stderr.trim().slice(0, 500)}`);
const ready = await kubectl(['wait', '--for=condition=Ready', `pod/${entry.name}`, '--timeout=600s'], {
timeoutMs: 630_000,
signal,
});
active(signal);
if (ready.exitCode !== 0) throw unavailable(`The check Pod did not start: ${ready.stderr.trim().slice(0, 800)}`);
} catch (error) {
if (error instanceof RuntimeError && error.code === 'CANCELED') throw error;
if (signal.aborted || closed) throw new RuntimeError('CANCELED', 'Check Pod startup was canceled');
throw unavailable(`Cannot start check Pod ${config.namespace}/${entry.name}: ${(error as Error).message}`);
}
};
/** The workspace's Pod, started anew when the directory was replaced since. */
const podFor = async (root: string, signal: AbortSignal): Promise<PodEntry> => {
const paths = await (prepared ??= prepare());
active(signal);
const resolved = await realpath(root);
if (!within(paths.mountRoot, resolved) || resolved === paths.mountRoot)
throw new RuntimeError('INVALID_VERIFIER_COMMAND', `Check workspaces must lie on the run volume: ${root}`);
const info = await lstat(resolved);
active(signal);
const key = `${resolved}\0${info.dev}:${info.ino}`;
const existing = pods.get(key);
if (existing) return existing;
for (const stale of [...owned].filter(entry => entry.key.startsWith(`${resolved}\0`))) {
await remove(stale);
active(signal);
}
const git = await lstat(path.join(resolved, '.git')).then(
stats => (stats.isDirectory() ? ('directory' as const) : stats.isFile() ? ('file' as const) : 'other'),
() => undefined,
);
active(signal);
if (git === 'other') throw new RuntimeError('INVALID_VERIFIER_COMMAND', 'A workspace .git must not be a link');
// Another command may have populated the cache while the directory was inspected.
const concurrent = pods.get(key);
if (concurrent) return concurrent;
const entry: PodEntry = {
name: `wf-check-${short(config.owner)}-${randomBytes(4).toString('hex')}`,
key,
ready: Promise.resolve(),
creationConfirmed: false,
retired: false,
users: 0,
};
owned.add(entry);
pods.set(key, entry);
entry.ready = start(
entry,
{
root: resolved,
rootSubPath: path.relative(paths.mountRoot, resolved).split(path.sep).join('/'),
git,
writable: paths.writable.filter(item => !within(resolved, item.path)),
},
signal,
);
// The owning command handles failure; the entry remains owned until deletion is confirmed.
void entry.ready.catch(() => undefined);
return entry;
};
const writableFor = async (root: string, location: string | undefined) => {
if (!location || !path.isAbsolute(location)) return false;
const paths = await prepared!;
const resolved = path.resolve(location);
return within(root, resolved) || paths.writable.some(item => within(item.path, resolved));
};
const run = async (command: Command, signal: AbortSignal): Promise<CommandResult> => {
active(signal);
if (!command.cwd) throw new RuntimeError('INVALID_VERIFIER_COMMAND', 'Sandboxed commands need a working directory');
let entry: PodEntry | undefined;
let completed = false;
try {
const root = await realpath(command.sandboxRoot ?? command.cwd);
active(signal);
const cwd = await realpath(command.cwd);
active(signal);
if (!within(root, cwd))
throw new RuntimeError('INVALID_VERIFIER_COMMAND', 'A check runs inside its own workspace');
entry = await podFor(root, signal);
entry.users++;
clearTimeout(entry.idle);
await entry.ready;
active(signal);
const own = `/tmp/command-${++sequence}`;
const directories = {
home: (await writableFor(root, command.env?.HOME)) ? command.env!.HOME! : `${own}/home`,
temporary: (await writableFor(root, command.env?.TMPDIR)) ? command.env!.TMPDIR! : `${own}/tmp`,
};
const paths = await prepared!;
active(signal);
const result = await execute({
executable: config.kubectl,
args: checkPodExec(config, entry.name, { ...command, cwd }, directories, paths.cache),
cwd: config.mountRoot,
env,
input: command.input,
timeoutMs: (command.timeoutMs ?? 120_000) + 15_000,
signal,
});
active(signal);
const reported = checkPodResult(result);
if (!reported) throw unavailable(`The check Pod did not run the command: ${result.stderr.trim().slice(-800)}`);
completed = true;
return reported;
} catch (error) {
if (entry) await cleanupAfterError(entry);
if (error instanceof RuntimeError) throw error;
if (signal.aborted || closed) throw new RuntimeError('CANCELED', 'Check command was canceled');
throw unavailable(`Cannot run the check in its Pod: ${(error as Error).message}`);
} finally {
if (entry) {
entry.users--;
if (completed && !closed && !entry.retired && entry.users === 0) {
entry.idle = setTimeout(() => void cleanupAfterError(entry!), config.idleMs ?? 120_000);
entry.idle.unref?.();
}
}
}
};
const executor: CommandExecutor = command => {
const signal = command.signal ? AbortSignal.any([stopping.signal, command.signal]) : stopping.signal;
const operation = run(command, signal);
pending.add(operation);
const finished = () => {
pending.delete(operation);
forgetIfClosed();
};
void operation.then(finished, finished);
return operation;
};
// Last chance only: SIGKILL cannot run this hook, and a deadline stops a Pod, not its API object.
const forget = removeAtExit(() => {
const names = [...owned].map(entry => entry.name);
if (names.length) {
const result = spawnSync(
config.kubectl,
[
'--kubeconfig',
config.kubeconfig,
'--request-timeout=2s',
'-n',
config.namespace,
'delete',
'pod',
...names,
'--ignore-not-found',
'--wait=false',
],
{ cwd: config.mountRoot, env, stdio: 'ignore', timeout: CLEANUP_MS },
);
if (result.status !== 0)
console.warn(`[check-pod] ${config.namespace}: could not confirm exit cleanup for ${names.join(', ')}`);
}
});
const dispose = (): Promise<void> => {
closed = true;
stopping.abort();
if (disposal) return disposal;
const budget = cleanupBudget();
closeBudget = budget;
disposal = (async () => {
await withinBudget(Promise.allSettled([...pending, ...[...owned].map(entry => remove(entry, budget))]), budget);
// One bounded retry for deletions that failed promptly; never retry execution or creation.
if (owned.size && !pending.size && !budget.signal.aborted)
await withinBudget(Promise.allSettled([...owned].map(entry => remove(entry, budget))), budget);
if (owned.size || pending.size)
throw unavailable(`Check Pod cleanup remains pending in ${config.namespace}; retain mounted workspaces`);
forgetIfClosed();
})().finally(() => {
budget.close();
closeBudget = undefined;
disposal = undefined;
});
return disposal;
};
return Object.assign(executor, { dispose });
}

View File

@ -5,6 +5,7 @@ export * from './git.js';
export * from './verify.js';
export * from './build.js';
export * from './sandbox.js';
export * from './check-pods.js';
export * from './deploy.js';
export * from './runner.js';
export * from './providers/codex.js';

View File

@ -174,14 +174,37 @@ export interface ClaudeCodeConfig extends CodeBuddyConfig {
commandSandbox?: CommandSandboxConfig;
}
/** Safe mode retains native OAuth/keychain auth but skips settings.env. Read only its auth keys. */
const NON_SECRET_CLAUDE_SETTINGS = new Set([
'ANTHROPIC_BASE_URL',
'ANTHROPIC_MODEL',
'ANTHROPIC_DEFAULT_OPUS_MODEL',
'ANTHROPIC_DEFAULT_SONNET_MODEL',
'ANTHROPIC_DEFAULT_HAIKU_MODEL',
'ANTHROPIC_SMALL_FAST_MODEL',
'CLAUDE_CODE_SUBAGENT_MODEL',
'CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC',
'DISABLE_AUTOUPDATER',
'DISABLE_TELEMETRY',
'DISABLE_ERROR_REPORTING',
]);
/**
* What safe mode, which skips settings.env, may still take from it: the account's credentials, a
* gateway's address and model names, and switches that stop the CLI calling services a gateway
* does not replace.
*/
export const LOCAL_CLAUDE_SETTINGS = [
'ANTHROPIC_API_KEY',
'ANTHROPIC_AUTH_TOKEN',
...NON_SECRET_CLAUDE_SETTINGS,
] as const;
/** Safe mode retains native OAuth/keychain auth but skips settings.env. Read only {@link LOCAL_CLAUDE_SETTINGS}. */
export async function localCredentialEnv(home: string): Promise<Record<string, string>> {
try {
const settings: unknown = JSON.parse(await readFile(path.join(home, '.claude', 'settings.json'), 'utf8'));
const env = (settings as { env?: Record<string, unknown> } | null)?.env ?? {};
return Object.fromEntries(
['ANTHROPIC_API_KEY', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_BASE_URL', 'ANTHROPIC_MODEL'].flatMap(name =>
typeof env[name] === 'string' && env[name] ? [[name, env[name]]] : [],
LOCAL_CLAUDE_SETTINGS.flatMap(name =>
typeof env[name] === 'string' && env[name] && !/[\r\n\0]/.test(env[name]) ? [[name, env[name]]] : [],
),
);
} catch (error) {
@ -286,11 +309,11 @@ export class StreamJsonCliAdapter extends ManagedProvider {
'Unsupported credential variable; control-plane environment is never inherited',
);
}
const credentialEnv = {
const cliEnv = {
...(nativeHost ? await localCredentialEnv(home) : {}),
...this.config.credentialEnv,
};
const commands = await this.commands(input.workspace, home, Object.keys(credentialEnv));
const commands = await this.commands(input.workspace, home, Object.keys(cliEnv));
const run = this.create(
input,
this.dialect.unsandboxed ? { unsandboxed: true, reason: this.dialect.unsandboxed } : commands.started,
@ -310,7 +333,7 @@ export class StreamJsonCliAdapter extends ManagedProvider {
PATH: process.env.PATH,
HOME: home,
...AGENT_GIT_IDENTITY,
...credentialEnv,
...cliEnv,
...commands.env,
},
},
@ -329,10 +352,12 @@ export class StreamJsonCliAdapter extends ManagedProvider {
let outputBytes = 0;
let failureReason: string | undefined;
const decoder = new StringDecoder('utf8');
// Unclassified variables remain secret, including custom authentication headers.
const secretValues = Object.entries(cliEnv).flatMap(([name, value]) =>
value && !NON_SECRET_CLAUDE_SETTINGS.has(name) ? [value] : [],
);
const redact = (value: string) =>
Object.values(credentialEnv)
.filter(Boolean)
.reduce((text, key) => text.replaceAll(key, '[REDACTED]'), value);
secretValues.reduce((text, secret) => text.replaceAll(secret, '[REDACTED]'), value);
let lastText: string | undefined;
// Usage of each model response, by message ID: the CLI repeats a response's usage on every
// content block. Only a session that ends normally reports its total; for one that is stopped

View File

@ -0,0 +1,532 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { mkdir, mkdtemp, realpath, rm } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import {
CommandStopped,
RuntimeError,
checkPodExec,
checkPodExecutor,
checkPodManifest,
checkPodResult,
validateCheckPodConfig,
type CheckPodConfig,
type Command,
type CommandResult,
} from '../src/index.js';
const dirs: string[] = [];
afterEach(async () => {
await Promise.all(dirs.splice(0).map(directory => rm(directory, { recursive: true, force: true })));
});
const IMAGE = `registry.example/wishforge/cluster-poc@sha256:${'a'.repeat(64)}`;
async function volume() {
const root = await realpath(await mkdtemp(path.join(os.tmpdir(), 'wishforge-check-volume-')));
dirs.push(root);
const workspace = path.join(root, 'runs/demo/run-1/gen-1/verifier/workspace-tree');
await mkdir(workspace, { recursive: true });
const config: CheckPodConfig = {
kubectl: '/usr/local/bin/kubectl',
kubeconfig: '/etc/wishforge/kube/config',
namespace: 'wishforge-checks',
image: IMAGE,
claim: 'wishforge-exec',
mountRoot: root,
writable: [path.join(root, 'check-cache')],
uid: 10001,
gid: 10001,
owner: 'verifier-gen-1',
};
return { root, workspace, config };
}
/** A kubectl that creates, waits for and removes Pods and runs commands with the given results. */
type KubectlReply = (command: Command) => CommandResult | Promise<CommandResult>;
function fakeKubectl(run: KubectlReply, hooks: Partial<Record<'create' | 'wait' | 'delete', KubectlReply>> = {}) {
const calls: Command[] = [];
const execute = async (command: Command): Promise<CommandResult> => {
calls.push(command);
const verb = command.args[command.args.indexOf('-n') + 2];
const hook = hooks[verb as keyof typeof hooks];
if (hook) return hook(command);
if (verb === 'create') return { exitCode: 0, stdout: 'pod/created', stderr: '' };
if (verb === 'wait') return { exitCode: 0, stdout: '', stderr: '' };
if (verb === 'delete') return deleted(command);
return run(command);
};
const verbs = () => calls.map(call => call.args[call.args.indexOf('-n') + 2]);
const created = () =>
calls.filter(call => call.args.includes('create')).map(call => JSON.parse(call.input!) as Record<string, any>);
return { execute, calls, verbs, created };
}
function deferred<T>() {
let resolve!: (value: T) => void;
let reject!: (error: unknown) => void;
const promise = new Promise<T>((yes, no) => {
resolve = yes;
reject = no;
});
return { promise, resolve, reject };
}
const ok = () => ({ exitCode: 0, stdout: '', stderr: '' });
const deleted = (command: Command) => ({
...ok(),
stdout: `pod/${command.args[command.args.indexOf('pod') + 1]}\n`,
});
const reported = (code: number, stdout = 'ok\n', stderr = '') => ({
exitCode: code,
stdout,
stderr: `${stderr}\n__WISHFORGE_CHECK_EXIT__=${code}\n${code ? `command terminated with exit code ${code}\n` : ''}`,
});
describe('check Pods for cluster-hosted development checks', () => {
it('builds a credential-free Pod that mounts only the workspace, a read-only .git and the caches', async () => {
const { workspace, config } = await volume();
const manifest = checkPodManifest(config, 'wf-check-x', {
root: workspace,
rootSubPath: 'runs/demo/run-1/gen-1/verifier/workspace-tree',
git: 'directory',
writable: [{ path: path.join(config.mountRoot, 'check-cache'), subPath: 'check-cache' }],
});
const spec = manifest.spec;
expect(spec.automountServiceAccountToken).toBe(false);
expect(spec.enableServiceLinks).toBe(false);
expect(spec.securityContext).toEqual({
runAsNonRoot: true,
runAsUser: 10001,
runAsGroup: 10001,
seccompProfile: { type: 'RuntimeDefault' },
});
const [container] = spec.containers;
expect(container!.image).toBe(IMAGE);
expect(container!.securityContext).toEqual({
allowPrivilegeEscalation: false,
readOnlyRootFilesystem: true,
capabilities: { drop: ['ALL'] },
});
expect(container!.volumeMounts).toEqual([
{ name: 'run', mountPath: workspace, subPath: 'runs/demo/run-1/gen-1/verifier/workspace-tree' },
{
name: 'run',
mountPath: path.join(workspace, '.git'),
subPath: 'runs/demo/run-1/gen-1/verifier/workspace-tree/.git',
readOnly: true,
},
{ name: 'run', mountPath: path.join(config.mountRoot, 'check-cache'), subPath: 'check-cache' },
{ name: 'tmp', mountPath: '/tmp' },
]);
// Only the run volume and a scratch directory: never a Secret, a ConfigMap or a host path.
expect(spec.volumes.map(volume => Object.keys(volume).filter(key => key !== 'name'))).toEqual([
['persistentVolumeClaim'],
['emptyDir'],
]);
expect(spec.activeDeadlineSeconds).toBeGreaterThan(0);
});
it('refuses images by tag, root users and caches off the run volume', async () => {
const { config } = await volume();
expect(() => validateCheckPodConfig({ ...config, image: 'registry.example/check:latest' })).toThrow(/digest/);
expect(() => validateCheckPodConfig({ ...config, uid: 0 })).toThrow(/root/);
expect(() => validateCheckPodConfig({ ...config, writable: ['/etc'] })).toThrow(/run volume/);
expect(() => validateCheckPodConfig({ ...config, namespace: 'Bad_Name' })).toThrow(/Kubernetes names/);
});
it('runs the command with only its own variables and reports the exit status after the output', async () => {
const { workspace, config } = await volume();
const args = checkPodExec(
config,
'wf-check-x',
{
executable: '/usr/local/bin/node',
args: ['/opt/wishforge/scripts/poc-project-check.mjs', 'verify'],
cwd: workspace,
env: { PATH: '/usr/bin:/bin', LANG: 'C.UTF-8', CI: 'true' },
timeoutMs: 60_000,
},
{ home: '/tmp/command-1/home', temporary: '/tmp/command-1/tmp' },
'/tmp/kubectl-cache',
);
const after = args.slice(args.indexOf('--') + 1);
expect(after.slice(0, 2)).toEqual(['/usr/bin/env', '-i']);
expect(after).toContain('HOME=/tmp/command-1/home');
expect(after).toContain('TMPDIR=/tmp/command-1/tmp');
expect(after.join(' ')).not.toMatch(/TOKEN|KUBECONFIG|DATABASE/);
expect(after[after.indexOf('/usr/bin/timeout') + 3]).toBe('120');
expect(after.slice(-5)).toEqual([
'/tmp/command-1/home',
'/tmp/command-1/tmp',
'/usr/local/bin/node',
'/opt/wishforge/scripts/poc-project-check.mjs',
'verify',
]);
// No input: kubectl attaches no stdin.
expect(args.slice(0, args.indexOf('--'))).not.toContain('-i');
expect(() =>
checkPodExec(
config,
'x',
{ executable: 'a', args: [], cwd: workspace, env: { 'BAD-NAME': 'x' } },
{
home: '/tmp/h',
temporary: '/tmp/t',
},
'/tmp/c',
),
).toThrow(/variable/);
});
it('takes the reported status, never kubectl’s own failure, for the command’s', () => {
expect(checkPodResult(reported(3, 'out\n', 'error: tests failed'))).toEqual({
exitCode: 3,
stdout: 'out\n',
stderr: 'error: tests failed',
});
expect(checkPodResult(reported(0))).toEqual({ exitCode: 0, stdout: 'ok\n', stderr: '' });
// kubectl could not reach the Pod: no status, so no verdict on the check.
expect(
checkPodResult({ exitCode: 1, stdout: '', stderr: 'error: unable to upgrade connection: container not found' }),
).toBeUndefined();
});
it('reuses a workspace’s Pod, replaces it when the directory was recreated, and removes it when idle', async () => {
const { workspace, config } = await volume();
const fake = fakeKubectl(() => reported(0));
const executor = checkPodExecutor({ ...config, idleMs: 20 }, fake.execute);
const command = { executable: '/usr/bin/true', args: [], cwd: workspace, sandboxRoot: workspace, env: {} };
await executor(command);
await executor({ ...command, network: true });
expect(fake.verbs().filter(verb => verb === 'create')).toHaveLength(1);
// verifyWorkspace removes and recreates the exported tree for every verification.
await rm(workspace, { recursive: true });
await mkdir(workspace);
await executor(command);
expect(fake.verbs().filter(verb => verb === 'create')).toHaveLength(2);
await new Promise(resolve => setTimeout(resolve, 80));
expect(fake.verbs().filter(verb => verb === 'delete')).toHaveLength(2);
await executor.dispose();
});
it('removes the Pod when a command stops at its limit or is canceled, and keeps the stop', async () => {
const { workspace, config } = await volume();
const fake = fakeKubectl(() => {
throw new CommandStopped('TIMEOUT', 'Command exceeded its time limit', { stdout: 'partial', stderr: '' });
});
const executor = checkPodExecutor(config, fake.execute);
await expect(executor({ executable: '/usr/bin/true', args: [], cwd: workspace, env: {} })).rejects.toBeInstanceOf(
CommandStopped,
);
expect(fake.verbs()).toContain('delete');
await executor.dispose();
});
it('treats an exec that never reached the command as an infrastructure fault', async () => {
const { workspace, config } = await volume();
const fake = fakeKubectl(() => ({ exitCode: 1, stdout: '', stderr: 'error: dial tcp: i/o timeout' }));
const executor = checkPodExecutor(config, fake.execute);
const failure = await executor({ executable: '/usr/bin/true', args: [], cwd: workspace, env: {} }).catch(
error => error,
);
expect(failure).toBeInstanceOf(RuntimeError);
expect(failure.code).toBe('VERIFIER_ISOLATION_UNAVAILABLE');
await executor.dispose();
});
it('does not create a Pod for a command canceled before it starts', async () => {
const { workspace, config } = await volume();
const fake = fakeKubectl(() => reported(0));
const executor = checkPodExecutor(config, fake.execute);
try {
await expect(
executor({ executable: '/usr/bin/true', args: [], cwd: workspace, signal: AbortSignal.abort() }),
).rejects.toMatchObject({ code: 'CANCELED' });
expect(fake.calls).toHaveLength(0);
} finally {
await executor.dispose();
}
});
it('removes a Pod when cancellation interrupts its Ready wait', async () => {
const { workspace, config } = await volume();
const controller = new AbortController();
const started = deferred<Command>();
const ready = deferred<CommandResult>();
const fake = fakeKubectl(() => reported(0), {
wait: command => {
started.resolve(command);
return ready.promise;
},
});
const executor = checkPodExecutor(config, fake.execute);
const command = executor({ executable: '/usr/bin/true', args: [], cwd: workspace, signal: controller.signal });
const outcome = command.catch(error => error);
const wait = await started.promise;
controller.abort();
ready.reject(new RuntimeError('CANCELED', 'Ready wait canceled'));
try {
expect(await outcome).toMatchObject({ code: 'CANCELED' });
expect(wait.signal?.aborted).toBe(true);
expect(fake.verbs()).toContain('delete');
expect(fake.verbs()).not.toContain('exec');
const deletion = fake.calls.find(call => call.args.includes('delete'))!;
expect(deletion.signal?.aborted).not.toBe(true);
} finally {
await executor.dispose();
}
});
it('reclaims a possibly created Pod when the creation response is lost', async () => {
const { workspace, config } = await volume();
let live = false;
const fake = fakeKubectl(() => reported(0), {
create: () => {
live = true;
throw new Error('Creation response lost');
},
delete: command => {
live = false;
return deleted(command);
},
});
const executor = checkPodExecutor(config, fake.execute);
try {
await expect(executor({ executable: '/usr/bin/true', args: [], cwd: workspace })).rejects.toMatchObject({
code: 'VERIFIER_ISOLATION_UNAVAILABLE',
});
expect(live).toBe(false);
expect(fake.verbs()).not.toContain('exec');
} finally {
await executor.dispose();
}
});
it('classifies a startup timeout as infrastructure failure and deletes its Pod', async () => {
const { workspace, config } = await volume();
const fake = fakeKubectl(() => reported(0), {
wait: () => {
throw new CommandStopped('TIMEOUT', 'Ready wait timed out', { stdout: '', stderr: '' });
},
});
const executor = checkPodExecutor(config, fake.execute);
try {
await expect(executor({ executable: '/usr/bin/true', args: [], cwd: workspace })).rejects.toMatchObject({
code: 'VERIFIER_ISOLATION_UNAVAILABLE',
});
expect(fake.verbs()).toContain('delete');
expect(fake.verbs()).not.toContain('exec');
} finally {
await executor.dispose();
}
});
it('waits for a late creation before deleting it when disposed during startup', async () => {
const { workspace, config } = await volume();
const started = deferred<Command>();
const created = deferred<CommandResult>();
let live = false;
const fake = fakeKubectl(() => reported(0), {
create: async command => {
started.resolve(command);
const result = await created.promise;
live = true;
return result;
},
delete: command => {
live = false;
return deleted(command);
},
});
const executor = checkPodExecutor(config, fake.execute);
const outcome = executor({ executable: '/usr/bin/true', args: [], cwd: workspace }).catch(error => error);
const creation = await started.promise;
const disposed = executor.dispose();
expect(creation.signal?.aborted).toBe(true);
created.resolve(ok());
await disposed;
expect(await outcome).toMatchObject({ code: 'CANCELED' });
expect(live).toBe(false);
expect(fake.verbs()).not.toContain('exec');
await executor.dispose();
const count = fake.calls.length;
await expect(executor({ executable: '/usr/bin/true', args: [], cwd: workspace })).rejects.toMatchObject({
code: 'CANCELED',
});
expect(fake.calls).toHaveLength(count);
});
it('closes before asynchronous preparation can start a Pod', async () => {
const { workspace, config } = await volume();
const fake = fakeKubectl(() => reported(0));
const executor = checkPodExecutor(config, fake.execute);
const outcome = executor({ executable: '/usr/bin/true', args: [], cwd: workspace }).catch(error => error);
await executor.dispose();
expect(await outcome).toMatchObject({ code: 'CANCELED' });
expect(fake.calls).toHaveLength(0);
});
it.each(['exit', 'throw'] as const)('keeps failed %s deletions available for a later dispose', async failure => {
const { workspace, config } = await volume();
let fail = true;
const fake = fakeKubectl(() => reported(0), {
delete: () => {
if (!fail) return ok();
if (failure === 'throw') throw new Error('Delete connection failed');
return { exitCode: 1, stdout: '', stderr: 'Deletion refused' };
},
});
const executor = checkPodExecutor(config, fake.execute);
await executor({ executable: '/usr/bin/true', args: [], cwd: workspace });
try {
await expect(executor.dispose()).rejects.toMatchObject({ code: 'VERIFIER_ISOLATION_UNAVAILABLE' });
const attempts = fake.verbs().filter(verb => verb === 'delete').length;
fail = false;
await executor.dispose();
expect(fake.verbs().filter(verb => verb === 'delete')).toHaveLength(attempts + 1);
expect(fake.calls.filter(call => call.args.includes('delete')).every(call => call.cwd === config.mountRoot)).toBe(
true,
);
} finally {
fail = false;
await executor.dispose();
}
});
it('preserves a canceled command when deletion fails and retries its Pod at disposal', async () => {
const { workspace, config } = await volume();
const warning = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
let fail = true;
const canceled = new RuntimeError('CANCELED', 'Check canceled');
const fake = fakeKubectl(
() => {
throw canceled;
},
{
delete: () => (fail ? { exitCode: 1, stdout: '', stderr: 'Unavailable' } : ok()),
},
);
const executor = checkPodExecutor(config, fake.execute);
try {
await expect(executor({ executable: '/usr/bin/true', args: [], cwd: workspace })).rejects.toBe(canceled);
expect(warning).toHaveBeenCalled();
fail = false;
await executor.dispose();
expect(fake.verbs().filter(verb => verb === 'delete').length).toBeGreaterThan(1);
} finally {
fail = false;
await executor.dispose();
warning.mockRestore();
}
});
it('retains an ambiguous creation after NotFound and can remove it when it appears later', async () => {
const { workspace, config } = await volume();
const warning = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
let live = false;
const fake = fakeKubectl(() => reported(0), {
create: () => {
throw new Error('Create request outcome is unknown');
},
delete: command => {
if (!live) return ok(); // --ignore-not-found: nothing was observed yet.
live = false;
return deleted(command);
},
});
const executor = checkPodExecutor(config, fake.execute);
try {
await expect(executor({ executable: '/usr/bin/true', args: [], cwd: workspace })).rejects.toMatchObject({
code: 'VERIFIER_ISOLATION_UNAVAILABLE',
});
await expect(executor.dispose()).rejects.toMatchObject({ code: 'VERIFIER_ISOLATION_UNAVAILABLE' });
live = true;
await executor.dispose();
expect(live).toBe(false);
} finally {
live = true;
await executor.dispose();
warning.mockRestore();
}
});
it('bounds disposal without forgetting a creation that finishes after the close deadline', async () => {
const { workspace, config } = await volume();
const started = deferred<Command>();
const created = deferred<CommandResult>();
let live = false;
const fake = fakeKubectl(() => reported(0), {
create: async command => {
started.resolve(command);
const result = await created.promise;
live = true;
return result;
},
delete: command => {
live = false;
return deleted(command);
},
});
const executor = checkPodExecutor(config, fake.execute);
const outcome = executor({ executable: '/usr/bin/true', args: [], cwd: workspace }).catch(error => error);
await started.promise;
vi.useFakeTimers();
try {
const disposal = executor.dispose().catch(error => error);
await vi.advanceTimersByTimeAsync(2000);
expect(await disposal).toMatchObject({ code: 'VERIFIER_ISOLATION_UNAVAILABLE' });
expect(fake.verbs()).not.toContain('delete');
created.resolve(ok());
expect(await outcome).toMatchObject({ code: 'CANCELED' });
await executor.dispose();
expect(live).toBe(false);
expect(fake.verbs()).not.toContain('exec');
} finally {
created.resolve(ok());
await outcome;
await executor.dispose();
vi.useRealTimers();
}
});
it('reuses one Pod for concurrent commands and coalesces concurrent disposal', async () => {
const { workspace, config } = await volume();
const deleting = deferred<void>();
const deletedPod = deferred<CommandResult>();
const fake = fakeKubectl(() => reported(0), {
delete: () => {
deleting.resolve();
return deletedPod.promise;
},
});
const executor = checkPodExecutor(config, fake.execute);
const command = { executable: '/usr/bin/true', args: [], cwd: workspace };
await Promise.all([executor(command), executor(command)]);
expect(fake.created()).toHaveLength(1);
const first = executor.dispose();
const second = executor.dispose();
expect(first).toBe(second);
await deleting.promise;
deletedPod.resolve(ok());
await first;
await executor.dispose();
expect(fake.verbs().filter(verb => verb === 'delete')).toHaveLength(1);
});
it('keeps a home inside the workspace and gives the others a private one, and refuses paths off the volume', async () => {
const { root, workspace, config } = await volume();
const fake = fakeKubectl(() => reported(0));
const executor = checkPodExecutor(config, fake.execute);
await executor({ executable: '/usr/bin/true', args: [], cwd: workspace, env: { HOME: workspace } });
await executor({ executable: '/usr/bin/true', args: [], cwd: workspace, env: { HOME: '/home/operator' } });
const execs = fake.calls.filter(call => call.args.includes('exec'));
expect(execs[0]!.args).toContain(`HOME=${workspace}`);
expect(execs[1]!.args.find(arg => arg.startsWith('HOME='))).toMatch(/^HOME=\/tmp\/command-\d+\/home$/);
const outside = await realpath(await mkdtemp(path.join(os.tmpdir(), 'wishforge-outside-')));
dirs.push(outside);
await expect(executor({ executable: '/usr/bin/true', args: [], cwd: outside, env: {} })).rejects.toThrow(
/run volume/,
);
await expect(executor({ executable: '/usr/bin/true', args: [], cwd: root, env: {} })).rejects.toThrow(/run volume/);
await executor.dispose();
});
});

View File

@ -8,7 +8,7 @@ const dirs: string[] = [];
afterEach(async () => {
await Promise.all(dirs.splice(0).map(directory => rm(directory, { recursive: true, force: true })));
});
async function fixture(source: string, timeoutMs = 5000) {
async function fixture(source: string, timeoutMs = 5000, env: Record<string, string> = {}) {
const home = await mkdtemp(path.join(os.tmpdir(), 'wishforge-claude-native-'));
dirs.push(home);
await mkdir(path.join(home, '.claude'));
@ -17,6 +17,7 @@ async function fixture(source: string, timeoutMs = 5000) {
ANTHROPIC_AUTH_TOKEN: 'fixture-secret-token',
ANTHROPIC_BASE_URL: 'https://example.invalid',
DATABASE_URL: 'private',
...env,
},
hooks: { mustNeverExecute: true },
});
@ -85,6 +86,90 @@ setTimeout(() => process.stdout.write(result.subarray(split)), 20);
expect(await readFile(path.join(f.home, '.claude/settings.json'), 'utf8')).toBe(f.settings);
});
it.each([
{ label: 'success', isError: false, apiKey: 'fixture-api-key', authToken: 'fixture-secret-token' },
{ label: 'failure', isError: true, apiKey: 'fixture-api-key', authToken: 'fixture-secret-token' },
{ label: 'one-character credentials', isError: true, apiKey: '7', authToken: '8' },
])('preserves non-secret settings and redacts credentials in $label', async ({ isError, apiKey, authToken }) => {
const configuration = {
ANTHROPIC_BASE_URL: 'https://gateway.invalid/v1',
ANTHROPIC_MODEL: 'fixture-main-1',
ANTHROPIC_DEFAULT_OPUS_MODEL: 'fixture-opus-1',
ANTHROPIC_DEFAULT_SONNET_MODEL: 'fixture-sonnet-1',
ANTHROPIC_DEFAULT_HAIKU_MODEL: 'fixture-haiku-1',
ANTHROPIC_SMALL_FAST_MODEL: 'fixture-small-1',
CLAUDE_CODE_SUBAGENT_MODEL: 'fixture-subagent-1',
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
DISABLE_AUTOUPDATER: '1',
DISABLE_TELEMETRY: '1',
DISABLE_ERROR_REPORTING: '1',
};
const env = { ...configuration, ANTHROPIC_API_KEY: apiKey, ANTHROPIC_AUTH_TOKEN: authToken };
const visible = `internal/wishforgeacceptance20261101/name.go A-B_01 ${Object.values(configuration).join(' ')}`;
const redacted = `${visible} [REDACTED] [REDACTED]`;
const f = await fixture(
`
const assert = require('node:assert/strict');
for (const [name, value] of Object.entries(${JSON.stringify(env)})) assert.equal(process.env[name], value);
const text = ${JSON.stringify(visible)} + ' ' + process.env.ANTHROPIC_API_KEY + ' ' + process.env.ANTHROPIC_AUTH_TOKEN;
const assistant = JSON.stringify({type:'assistant',message:{content:[
{type:'text',text:'stream: ' + text},
{type:'tool_use',name:'Bash',input:{command:'printf ' + text}}
]}}) + '\\n';
const split = assistant.indexOf(process.env.ANTHROPIC_AUTH_TOKEN) + 1;
process.stdout.write(assistant.slice(0, split));
setTimeout(() => {
process.stdout.write(assistant.slice(split));
console.log(JSON.stringify({type:'result',subtype:${JSON.stringify(isError ? 'error_during_execution' : 'success')},is_error:${isError},result:'final: ' + text}));
process.stderr.write('private: ' + text);
}, 20);
`,
5000,
env,
);
await f.start();
const events = await f.collect();
expect(events.map(event => event.type)).toEqual([
'started',
'output',
'command',
'output',
isError ? 'failed' : 'completed',
]);
expect(events[1]?.data).toEqual({ text: `stream: ${redacted}` });
expect(events[2]?.data).toEqual({ command: `printf ${redacted}` });
expect(events[3]?.data).toEqual({ text: `final: ${redacted}` });
expect(events[4]?.data).toEqual(isError ? { message: `final: ${redacted}` } : {});
expect(await f.adapter.inspect('run')).toMatchObject({
status: isError ? 'failed' : 'completed',
...(isError ? { error: `final: ${redacted}` } : {}),
});
});
it('redacts credentials in child process errors without redacting ordinary digits', async () => {
const f = await fixture('', 5000, { ANTHROPIC_API_KEY: 'fixture-api-key', DISABLE_TELEMETRY: '1' });
const binary = path.join(f.home, 'fixture-api-key-fixture-secret-token-01');
await writeFile(binary, `#!${path.join(f.home, 'missing-interpreter')}\n`);
await chmod(binary, 0o700);
const adapter = new ClaudeCodeAdapter({
binary,
isolationConfirmed: true,
localAuth: { home: f.home, developmentHost: true },
});
await adapter.start({
runId: 'run',
tenantId: 'tenant',
workspace: f.home,
baseCommit: 'a'.repeat(40),
prompt: 'test',
});
const events: ProviderEvent[] = [];
for await (const event of adapter.events('run')) events.push(event);
const message = `spawn ${path.join(f.home, '[REDACTED]-[REDACTED]-01')} ENOENT`;
expect(events.at(-1)).toMatchObject({ type: 'failed', data: { message } });
expect(await adapter.inspect('run')).toMatchObject({ status: 'failed', error: message });
});
it('requires the explicit host opt-in and refuses relative auth homes', async () => {
const f = await fixture('');
expect(
@ -174,3 +259,41 @@ line({type:'result',subtype:'success',is_error:false,result:'Done: added the lab
expect((await canceled.adapter.inspect('run')).status).toBe('canceled');
});
});
describe('gateway settings for the native Claude CLI', () => {
it('passes only the gateway address, credentials, model names and traffic switches', async () => {
const { localCredentialEnv } = await import('../src/providers/codebuddy.js');
const home = await mkdtemp(path.join(os.tmpdir(), 'wishforge-claude-gateway-'));
dirs.push(home);
await mkdir(path.join(home, '.claude'));
await writeFile(
path.join(home, '.claude/settings.json'),
JSON.stringify({
env: {
ANTHROPIC_BASE_URL: 'https://gateway.invalid',
ANTHROPIC_API_KEY: 'sk-fixture',
ANTHROPIC_MODEL: 'deepseek-v4-pro[1m]',
ANTHROPIC_DEFAULT_OPUS_MODEL: 'deepseek-v4-pro[1m]',
ANTHROPIC_DEFAULT_SONNET_MODEL: 'deepseek-v4-pro[1m]',
ANTHROPIC_DEFAULT_HAIKU_MODEL: 'deepseek-v4-flash[1m]',
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
DISABLE_AUTOUPDATER: '1',
ANTHROPIC_CUSTOM_HEADERS: 'X-Injected: yes',
ANTHROPIC_SMALL_FAST_MODEL: 'line\nbreak',
DATABASE_URL: 'private',
NODE_OPTIONS: '--require evil',
},
}),
);
expect(await localCredentialEnv(home)).toEqual({
ANTHROPIC_BASE_URL: 'https://gateway.invalid',
ANTHROPIC_API_KEY: 'sk-fixture',
ANTHROPIC_MODEL: 'deepseek-v4-pro[1m]',
ANTHROPIC_DEFAULT_OPUS_MODEL: 'deepseek-v4-pro[1m]',
ANTHROPIC_DEFAULT_SONNET_MODEL: 'deepseek-v4-pro[1m]',
ANTHROPIC_DEFAULT_HAIKU_MODEL: 'deepseek-v4-flash[1m]',
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
DISABLE_AUTOUPDATER: '1',
});
});
});

View File

@ -368,6 +368,56 @@ describe('portable provider execution', () => {
expect(events[2]?.data).toEqual({ command: 'npm test' });
expect(events[3]?.data).toEqual({ changes: [{ path: 'src/app.ts' }] });
});
it.each([
['Claude Code', ClaudeCodeAdapter, 'ANTHROPIC'],
['CodeBuddy', CodeBuddyAdapter, 'CODEBUDDY'],
] as const)('redacts explicit %s credentials but not gateway configuration', async (_label, Adapter, prefix) => {
const home = await temp();
const binary = path.join(home, 'cli-redaction');
const credentialEnv = {
[`${prefix}_API_KEY`]: 'fixture-explicit-key',
[`${prefix}_AUTH_TOKEN`]: 'fixture-explicit-token',
[`${prefix}_CUSTOM_HEADERS`]: 'X-Api-Key: fixture-header-secret',
ANTHROPIC_BASE_URL: 'https://gateway.invalid/v1',
ANTHROPIC_MODEL: 'fixture-model-1',
};
const visible = 'internal/wishforgeacceptance20261101/name.go A-B_01 https://gateway.invalid/v1 fixture-model-1';
const text = `${visible} fixture-explicit-key fixture-explicit-token X-Api-Key: fixture-header-secret`;
const redacted = `${visible} [REDACTED] [REDACTED] [REDACTED]`;
const lines = [
{
type: 'assistant',
message: {
content: [
{ type: 'text', text },
{ type: 'tool_use', name: 'Bash', input: { command: text } },
],
},
},
{ type: 'result', subtype: 'error_during_execution', is_error: true, result: `failed: ${text}` },
];
await writeFile(
binary,
`#!/usr/bin/env node\n${lines.map(line => `console.log(${JSON.stringify(JSON.stringify(line))});`).join('\n')}\n`,
);
await chmod(binary, 0o700);
const adapter = new Adapter({
binary,
isolatedHome: home,
credentialEnv,
isolationConfirmed: true,
allowUnsandboxed: true,
});
await adapter.start({ runId: 'r', tenantId: 't', workspace: home, baseCommit: 'a'.repeat(40), prompt: 'test' });
const events = [];
for await (const event of adapter.events('r')) events.push(event);
expect(events.map(event => event.type)).toEqual(['started', 'output', 'command', 'output', 'failed']);
expect(events[1]?.data).toEqual({ text: redacted });
expect(events[2]?.data).toEqual({ command: redacted });
expect(events[3]?.data).toEqual({ text: `failed: ${redacted}` });
expect(events[4]?.data).toEqual({ message: `failed: ${redacted}` });
expect(await adapter.inspect('r')).toMatchObject({ status: 'failed', error: `failed: ${redacted}` });
});
it('runs Claude Code headless with only workspace file tools and its own credential variable', async () => {
const home = await temp();
const binary = path.join(home, 'claude-fixture');

View File

@ -0,0 +1,304 @@
#!/usr/bin/env node
// Daily snapshots of WishForge's data in the POC cluster (docs/cluster-poc-deployment.md), taken by
// the WishForge Pod's backup container onto the node's disk; `cluster-poc.mjs backup` copies the
// newest one off the node to the operator Mac. Importing it starts nothing.
//
// node scripts/cluster-poc-backup.mjs take one snapshot a day, until Kubernetes stops the container
// node scripts/cluster-poc-backup.mjs once take one snapshot now
// node scripts/cluster-poc-backup.mjs latest print the newest complete snapshot's manifest and the last result
import { spawn } from 'node:child_process';
import { createHash } from 'node:crypto';
import { createReadStream } from 'node:fs';
import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { setTimeout as delay } from 'node:timers/promises';
/** Where the backup container finds what it saves (each mounted read-only) and keeps the snapshots. */
export const BACKUP_ROOT = '/var/lib/wishforge/backups';
export const DATA_ROOT = '/mnt/data';
/** The database beside it on the Pod's loopback; the password comes from PGPASSWORD. */
const DATABASE = { host: '127.0.0.1', port: 5432, user: 'wishforge', database: 'wishforge' };
/** The directories saved as archives, beside the database dump and Temporal's database. */
export const ARCHIVES = ['git', 'minio', 'platform-state', 'poc-state', 'runner-state'];
/** Not saved: the platform container's caches, rebuilt when it starts, and MinIO's scratch space and trash. */
const ARCHIVE_EXCLUDES = { 'platform-state': ['./home'], minio: ['./.minio.sys/tmp'] };
/** Snapshots kept on the node; the operator Mac keeps its own copies longer. */
export const KEEP = 7;
/** 03:20 in Beijing, when nobody is expected to be working. */
export const SCHEDULE = { hourUtc: 19, minute: 20 };
const NAME = /^\d{8}T\d{6}Z$/;
/** Row counts of every table, to compare a copy with its source. */
export const COUNTS_SQL = `select string_agg(table_name || '=' || (xpath('/row/c/text()', query_to_xml('select count(*) as c from public.' || quote_ident(table_name), false, true, '')))[1]::text, ',' order by table_name)
from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE'`;
/** A snapshot's name: its UTC time, so names sort in the order they were taken. */
export const snapshotName = date =>
date
.toISOString()
.replace(/[-:]/g, '')
.replace(/\.\d+Z$/, 'Z');
/** The first scheduled time after `now`. */
export function nextRun(now, { hourUtc, minute } = SCHEDULE) {
const next = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), hourUtc, minute));
if (next <= now) next.setUTCDate(next.getUTCDate() + 1);
return next;
}
/** Which entries of the snapshot directory stay: the newest `keep` complete snapshots. Leftover partial ones go. */
export function retention(entries, keep = KEEP) {
const complete = entries.filter(entry => NAME.test(entry)).sort();
return {
keep: complete.slice(-keep),
remove: [
...complete.slice(0, Math.max(0, complete.length - keep)),
...entries.filter(e => e.startsWith('.partial-')),
],
};
}
/** Whether `files` (name → {bytes, sha256}) in `directory` are exactly what a manifest says. */
export async function verifyFiles(directory, files) {
for (const [file, expected] of Object.entries(files)) {
const location = path.join(directory, file);
const info = await stat(location).catch(() => undefined);
if (!info) throw new Error(`${file} is missing`);
if (info.size !== expected.bytes) throw new Error(`${file} has ${info.size} bytes, not ${expected.bytes}`);
if ((await sha256File(location)) !== expected.sha256) throw new Error(`${file} does not match its SHA-256`);
}
}
export const sha256File = file =>
new Promise((resolve, reject) => {
const hash = createHash('sha256');
createReadStream(file)
.on('data', chunk => hash.update(chunk))
.on('error', reject)
.on('end', () => resolve(hash.digest('hex')));
});
function run(executable, args, { signal, env = process.env } = {}) {
return new Promise((resolve, reject) => {
const child = spawn(executable, args, { env, signal, stdio: ['ignore', 'pipe', 'pipe'] });
const out = [];
const err = [];
child.stdout.on('data', chunk => out.push(chunk));
child.stderr.on('data', chunk => err.push(chunk));
child.once('error', reject);
child.once('close', code =>
resolve({ code, stdout: Buffer.concat(out).toString('utf8'), stderr: Buffer.concat(err).toString('utf8') }),
);
});
}
async function must(executable, args, options) {
const result = await run(executable, args, options);
if (result.code !== 0) throw new Error(`${path.basename(executable)} failed: ${result.stderr.trim().slice(0, 800)}`);
return result;
}
/**
* The database as of one moment: pg_dump reads the snapshot of a transaction that also counts every
* table's rows, so a restore can be checked against exactly what was dumped.
*/
async function dumpDatabase(file, { signal, database }) {
const { default: pg } = await import('pg');
const client = new pg.Client({
...database,
password: process.env.PGPASSWORD,
});
await client.connect();
try {
await client.query('begin isolation level repeatable read read only');
const snapshot = (await client.query('select pg_export_snapshot() as id')).rows[0].id;
const counts = (await client.query(`select (${COUNTS_SQL}) as counts`)).rows[0].counts;
await must(
'pg_dump',
[
'-h',
database.host,
'-p',
String(database.port),
'-U',
database.user,
'-d',
database.database,
'-Fc',
'--no-owner',
'--no-privileges',
`--snapshot=${snapshot}`,
'-f',
file,
],
{ signal },
);
await client.query('commit');
// The archive's table of contents reads back: the dump is complete.
await must('pg_restore', ['-l', file], { signal });
return counts;
} finally {
await client.end().catch(() => undefined);
}
}
/** Temporal's SQLite database through SQLite's online backup, which waits out its writers. */
async function copyTemporal(file, { signal, data }) {
const source = path.join(data, 'temporal/temporal.db');
await must('sqlite3', ['-readonly', '-cmd', '.timeout 60000', source, `.backup '${file}'`], { signal });
const check = await must('sqlite3', [file, 'pragma integrity_check'], { signal });
if (check.stdout.trim() !== 'ok')
throw new Error(`Temporal's copy fails its integrity check: ${check.stdout.trim()}`);
}
/** A directory as a gzip archive; tried again while files change under it (GNU tar's exit code 1). */
async function archive(name, file, { signal, data }) {
const args = [
'-czf',
file,
...(ARCHIVE_EXCLUDES[name] ?? []).map(entry => `--exclude=${entry}`),
'-C',
path.join(data, name),
'.',
];
for (let attempt = 1; ; attempt++) {
const result = await run('tar', args, { signal });
if (result.code === 0) return;
if (result.code !== 1 || attempt === 3)
throw new Error(`Archiving ${name} failed: ${result.stderr.trim().slice(0, 800)}`);
await delay(5000, undefined, { signal });
}
}
/** One snapshot, complete or not at all: built under a partial name, renamed once its manifest is written. */
export async function takeSnapshot({
root = BACKUP_ROOT,
data = DATA_ROOT,
database = DATABASE,
now = new Date(),
signal,
} = {}) {
await mkdir(root, { recursive: true, mode: 0o700 });
const lock = path.join(root, '.lock');
const held = await stat(lock).catch(() => undefined);
// A lock older than any snapshot takes is left by a container that was stopped mid-way.
if (held && Date.now() - held.mtimeMs < 2 * 3600_000) throw new Error('Another snapshot is being taken');
await rm(lock, { recursive: true, force: true });
await mkdir(lock);
const name = snapshotName(now);
const partial = path.join(root, `.partial-${name}`);
try {
for (const entry of retention(await readdir(root)).remove.filter(entry => entry.startsWith('.partial-')))
await rm(path.join(root, entry), { recursive: true, force: true });
await mkdir(partial, { mode: 0o700 });
const counts = await dumpDatabase(path.join(partial, 'postgres.dump'), { signal, database });
await copyTemporal(path.join(partial, 'temporal.db'), { signal, data });
for (const directory of ARCHIVES)
await archive(directory, path.join(partial, `${directory}.tgz`), { signal, data });
const files = {};
for (const file of (await readdir(partial)).sort()) {
const location = path.join(partial, file);
files[file] = { bytes: (await stat(location)).size, sha256: await sha256File(location) };
}
const manifest = {
name,
takenAt: now.toISOString(),
image: process.env.WF_IMAGE || undefined,
database: { counts },
files,
};
await writeFile(path.join(partial, 'manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`, { mode: 0o600 });
await rename(partial, path.join(root, name));
for (const entry of retention(await readdir(root)).remove)
await rm(path.join(root, entry), { recursive: true, force: true });
return manifest;
} catch (error) {
await rm(partial, { recursive: true, force: true });
throw error;
} finally {
await rm(lock, { recursive: true, force: true });
}
}
async function record(root, result) {
await writeFile(path.join(root, 'last.json'), `${JSON.stringify(result, null, 2)}\n`, { mode: 0o600 });
}
/** The newest complete snapshot's manifest, and the last attempt's result. */
export async function latest(root = BACKUP_ROOT) {
const names = retention(await readdir(root).catch(() => [])).keep;
const newest = names.at(-1);
const read = async file => JSON.parse(await readFile(file, 'utf8'));
return {
snapshots: names,
manifest: newest ? await read(path.join(root, newest, 'manifest.json')) : undefined,
last: await read(path.join(root, 'last.json')).catch(() => undefined),
};
}
async function once(root, signal) {
const startedAt = new Date();
try {
const manifest = await takeSnapshot({ root, now: startedAt, signal });
const bytes = Object.values(manifest.files).reduce((sum, file) => sum + file.bytes, 0);
await record(root, { ok: true, name: manifest.name, at: new Date().toISOString(), bytes });
console.log(`[backup] snapshot ${manifest.name}: ${(bytes / 1e6).toFixed(1)} MB`);
return manifest;
} catch (error) {
if (signal?.aborted) throw error;
await record(root, { ok: false, at: new Date().toISOString(), error: error.message });
throw error;
}
}
/**
* Takes a snapshot every day at {@link SCHEDULE}, and at once when the newest is more than a day
* old (a Pod that was down at the scheduled time). A failure is retried an hour later.
*/
export async function backupLoop({ root = BACKUP_ROOT } = {}) {
const stop = new AbortController();
process.once('SIGTERM', () => stop.abort());
const sleep = ms => delay(ms, undefined, { signal: stop.signal });
try {
const newest = (await latest(root)).manifest;
let due = newest && Date.now() - Date.parse(newest.takenAt) < 24 * 3600_000 ? nextRun(new Date()) : new Date();
// The database starts beside this container: give it time before the first attempt.
if (due <= new Date()) await sleep(60_000);
for (;;) {
await sleep(Math.max(0, due - Date.now()));
try {
await once(root, stop.signal);
due = nextRun(new Date());
} catch (error) {
if (stop.signal.aborted) break;
console.error(`[backup] ${error.message}; trying again in an hour`);
due = new Date(Date.now() + 3600_000);
}
}
} catch (error) {
if (!stop.signal.aborted) throw error;
}
return 0;
}
export async function main(argv = process.argv.slice(2)) {
if (argv.length === 0) return backupLoop();
if (argv[0] === 'once' && argv.length === 1) {
await once(BACKUP_ROOT);
return 0;
}
if (argv[0] === 'latest' && argv.length === 1) {
process.stdout.write(`${JSON.stringify(await latest())}\n`);
return 0;
}
throw new Error('Usage: cluster-poc-backup.mjs [once|latest]');
}
if (process.argv[1] && pathToFileURL(path.resolve(process.argv[1])).href === import.meta.url)
main().then(
code => process.exit(code),
error => {
console.error(`[backup] ${error.message}`);
process.exit(1);
},
);

View File

@ -0,0 +1,82 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { mkdir, mkdtemp, readdir, rm, stat, writeFile } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { nextRun, retention, snapshotName, takeSnapshot, verifyFiles, sha256File } from './cluster-poc-backup.mjs';
import { failureNotification, launchAgentPlist } from './cluster-poc.mjs';
test('snapshots are taken daily at 03:20 Beijing time and named by their UTC time', () => {
assert.equal(nextRun(new Date('2026-11-01T10:00:00Z')).toISOString(), '2026-11-01T19:20:00.000Z');
assert.equal(nextRun(new Date('2026-11-01T19:20:00Z')).toISOString(), '2026-11-02T19:20:00.000Z');
assert.equal(nextRun(new Date('2026-12-31T23:00:00Z')).toISOString(), '2027-01-01T19:20:00.000Z');
assert.equal(snapshotName(new Date('2026-11-01T19:20:05.123Z')), '20261101T192005Z');
});
test('the newest complete snapshots are kept; older ones and leftover partial ones go', () => {
const names = ['20261103T192000Z', '20261101T192000Z', '20261102T192000Z', '20261104T192000Z'];
const { keep, remove } = retention([...names, '.partial-20261105T192000Z', '.lock', 'last.json'], 2);
assert.deepEqual(keep, ['20261103T192000Z', '20261104T192000Z']);
assert.deepEqual(remove, ['20261101T192000Z', '20261102T192000Z', '.partial-20261105T192000Z']);
assert.deepEqual(retention(names.slice(0, 1), 7).remove, []);
});
test('a copied snapshot is accepted only when every file has its recorded size and SHA-256', async t => {
const directory = await mkdtemp(path.join(os.tmpdir(), 'wf-backup-verify-'));
t.after(() => rm(directory, { recursive: true, force: true }));
await writeFile(path.join(directory, 'git.tgz'), 'archive');
const files = { 'git.tgz': { bytes: 7, sha256: await sha256File(path.join(directory, 'git.tgz')) } };
await verifyFiles(directory, files);
await assert.rejects(verifyFiles(directory, { ...files, 'minio.tgz': { bytes: 1, sha256: '' } }), /missing/);
await assert.rejects(verifyFiles(directory, { 'git.tgz': { ...files['git.tgz'], bytes: 8 } }), /bytes/);
await writeFile(path.join(directory, 'git.tgz'), 'archivX');
await assert.rejects(verifyFiles(directory, files), /SHA-256/);
});
test('a snapshot that fails leaves no partial snapshot or lock behind, and a held lock stops a second one', async t => {
const directory = await mkdtemp(path.join(os.tmpdir(), 'wf-backup-fail-'));
t.after(() => rm(directory, { recursive: true, force: true }));
const root = path.join(directory, 'backups');
// Nothing listens on port 9: the database dump fails first.
const database = { host: '127.0.0.1', port: 9, user: 'wishforge', database: 'wishforge' };
await assert.rejects(takeSnapshot({ root, data: directory, database }));
assert.deepEqual(await readdir(root), []);
await mkdir(path.join(root, '.lock'));
await assert.rejects(takeSnapshot({ root, data: directory, database }), /Another snapshot/);
assert.ok(await stat(path.join(root, '.lock')));
});
test('the Mac copies the newest snapshot every day through a launchd job it can read back', async t => {
const plist = launchAgentPlist({
node: '/opt/homebrew/bin/node',
script: '/repo/scripts/cluster-poc.mjs',
root: '/repo & co',
pathEnv: '/opt/homebrew/bin:/usr/bin',
home: '/Users/someone',
log: '/repo/.wishforge/cluster-poc/backup.log',
});
assert.match(plist, /<key>Hour<\/key><integer>10<\/integer>/);
assert.match(plist, /<string>backup<\/string>/);
assert.match(plist, /\/repo &#38; co/);
if (process.platform !== 'darwin') return;
const directory = await mkdtemp(path.join(os.tmpdir(), 'wf-backup-plist-'));
t.after(() => rm(directory, { recursive: true, force: true }));
const file = path.join(directory, 'job.plist');
await writeFile(file, plist);
const parsed = JSON.parse(execFileSync('plutil', ['-convert', 'json', '-o', '-', file], { encoding: 'utf8' }));
assert.deepEqual(parsed.ProgramArguments, ['/opt/homebrew/bin/node', '/repo/scripts/cluster-poc.mjs', 'backup']);
assert.equal(parsed.WorkingDirectory, '/repo & co');
assert.deepEqual(parsed.StartCalendarInterval, { Hour: 10, Minute: 17 });
assert.equal(parsed.EnvironmentVariables.WF_BACKUP_NOTIFY, '1');
});
test('a failing daily copy is announced in a notification whose text cannot break out of its quotes', () => {
const script = failureNotification('Backup needs attention: "x" \\ end\nsecond line');
assert.equal(
script,
'display notification "Backup needs attention: \\"x\\" \\\\ end second line" with title "WishForge 集群备份失败" sound name "Basso"',
);
if (process.platform === 'darwin')
execFileSync('osacompile', ['-o', path.join(os.tmpdir(), `wf-notify-${process.pid}.scpt`), '-e', script]);
});

View File

@ -0,0 +1,260 @@
#!/usr/bin/env node
// Entry of WishForge's containers in the POC cluster (infra/images/cluster-poc.Dockerfile,
// docs/cluster-poc-deployment.md). Each role prepares the private files it needs from its own
// mounted Secret, waits for the services it depends on, and then runs in the foreground; a
// service that exits ends the container, which Kubernetes restarts. Importing it starts nothing.
import { spawn } from 'node:child_process';
import { randomUUID } from 'node:crypto';
import { chmod, copyFile, mkdir, readFile, rename, rm, stat } from 'node:fs/promises';
import net from 'node:net';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { setTimeout as delay } from 'node:timers/promises';
import { backupLoop } from './cluster-poc-backup.mjs';
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const ROLES = {
platform: { env: '/etc/wishforge/env/platform.env', services: 'git,api,coordinator,deployer,web' },
executor: { env: '/etc/wishforge/env/executor.env', services: 'provisioner' },
runner: { env: '/etc/wishforge/env/runner.env' },
// Daily snapshots of the data (cluster-poc-backup.mjs); it reads no settings file.
backup: {},
};
/** A KEY=value file's settings, without changing this process's environment. */
export function parseEnvFile(text) {
const values = {};
for (const line of text.split('\n')) {
const match = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=(.*)$/.exec(line);
if (!match) continue;
let value = match[2].trim();
if (/^(['"]).*\1$/.test(value)) value = value.slice(1, -1);
values[match[1]] = value;
}
return values;
}
/** Host and port of the address a setting names: a URL, a host:port pair or a database URL. */
export function endpoint(address) {
const url = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(address) ? address : `tcp://${address}`);
const port = Number(url.port || { 'http:': 80, 'https:': 443, 'postgresql:': 5432 }[url.protocol]);
if (!url.hostname || !Number.isInteger(port)) throw new Error(`Not a service address: ${address}`);
return { host: url.hostname.replace(/^\[|\]$/g, ''), port };
}
async function reachable({ host, port }) {
return new Promise(resolve => {
const socket = net.connect({ host, port, timeout: 2000 });
socket.once('connect', () => (socket.destroy(), resolve(true)));
socket.once('timeout', () => (socket.destroy(), resolve(false)));
socket.once('error', () => resolve(false));
});
}
async function waitFor(name, address, minutes = 10) {
const target = endpoint(address);
for (const until = Date.now() + minutes * 60_000; Date.now() < until; await delay(2000))
if (await reachable(target)) return;
throw new Error(`${name} at ${target.host}:${target.port} did not become reachable`);
}
async function waitForHttp(name, url, minutes = 10) {
for (const until = Date.now() + minutes * 60_000; Date.now() < until; await delay(2000)) {
const ok = await fetch(url, { signal: AbortSignal.timeout(3000) }).then(
response => response.ok,
() => false,
);
if (ok) return;
}
throw new Error(`${name} at ${url} did not become ready`);
}
/**
* A private copy, owned by this user and readable only by it, of a file Kubernetes mounted. It
* replaces the target in one step, so containers copying the same file at once never see half.
*/
export async function privateCopy(source, target) {
await mkdir(path.dirname(target), { recursive: true, mode: 0o700 });
const temporary = `${target}.${randomUUID()}.tmp`;
try {
await copyFile(source, temporary);
await chmod(temporary, 0o600);
await rename(temporary, target);
} finally {
await rm(temporary, { force: true });
}
}
const exists = location =>
stat(location).then(
() => true,
() => false,
);
/** The Claude CLI's home: its settings (the gateway, its key and models) from the mounted Secret. */
async function prepareClaudeHome(home) {
if (!home || !path.isAbsolute(home)) throw new Error('WF_CLAUDE_LOCAL_AUTH_HOME must be an absolute path');
await mkdir(path.join(home, '.claude'), { recursive: true, mode: 0o700 });
await chmod(home, 0o700);
await privateCopy('/etc/wishforge/claude/settings.json', path.join(home, '.claude/settings.json'));
}
/** The SSH home through which POC integration fetches and pushes: its deploy key and pinned host keys. */
async function prepareGitHome(home) {
const ssh = path.join(home, '.ssh');
await mkdir(ssh, { recursive: true, mode: 0o700 });
await chmod(home, 0o700);
await chmod(ssh, 0o700);
await privateCopy('/etc/wishforge/git/id_ed25519', path.join(ssh, 'id_ed25519'));
await privateCopy('/etc/wishforge/config/known_hosts', path.join(ssh, 'known_hosts'));
}
/** POC files the runtime only accepts as the operator's own: copied from the read-only mounts. */
async function preparePocFiles(env) {
if (env.WF_POC_PROFILE_FILE) await privateCopy('/etc/wishforge/config/poc-profile.json', env.WF_POC_PROFILE_FILE);
if (env.WF_LOCAL_POC_BINDING_FILE)
await privateCopy('/etc/wishforge/config/project.json', env.WF_LOCAL_POC_BINDING_FILE);
}
/**
* A project's protected install or verify commands, pointed at this image's Node and check script
* when they run the POC check from elsewhere (a project migrated from the Mac). Anything else is
* returned unchanged, the same array: commands a person chose, or ones already pointing here.
*/
export function clusterCheckCommands(
commands,
step,
node = process.execPath,
script = path.join(ROOT, 'scripts/poc-project-check.mjs'),
) {
const [argv, ...others] = commands ?? [];
const pocCheck =
!others.length && argv?.length === 3 && path.basename(argv[1]) === 'poc-project-check.mjs' && argv[2] === step;
return pocCheck && (argv[0] !== node || argv[1] !== script) ? [[node, script, step]] : commands;
}
/** Stays up, doing nothing, until Kubernetes stops the container; a signal handler alone keeps no process alive. */
export function idle() {
return new Promise(resolve => {
const timer = setInterval(() => undefined, 1 << 30);
process.once('SIGTERM', () => {
clearInterval(timer);
resolve(0);
});
});
}
function run(executable, args, env, { inherit = true } = {}) {
return new Promise((resolve, reject) => {
const child = spawn(executable, args, { cwd: ROOT, env, stdio: inherit ? 'inherit' : 'ignore' });
const forward = signal => child.kill(signal);
process.on('SIGTERM', forward);
process.on('SIGINT', forward);
child.once('error', reject);
child.once('exit', (code, signal) => {
process.off('SIGTERM', forward);
process.off('SIGINT', forward);
resolve(code ?? (signal ? 128 : 1));
});
});
}
const base = () => ({
PATH: process.env.PATH,
HOME: process.env.HOME,
LANG: 'C.UTF-8',
TMPDIR: process.env.TMPDIR || '/tmp',
...Object.fromEntries(
['HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY'].filter(key => process.env[key]).map(key => [key, process.env[key]]),
),
});
async function platform(file) {
const env = parseEnvFile(await readFile(file, 'utf8'));
await waitFor('PostgreSQL', env.DATABASE_ADMIN_URL);
await waitFor('Temporal', env.TEMPORAL_ADDRESS);
await waitFor('object storage', env.S3_ENDPOINT);
const migrated = await run(process.execPath, ['--import', 'tsx', 'apps/api/src/db/migrate.ts'], {
...base(),
DATABASE_ADMIN_URL: env.DATABASE_ADMIN_URL,
WF_DATABASE_APP_PASSWORD: env.WF_DATABASE_APP_PASSWORD,
WF_DEPLOYMENT_MODE: 'development',
});
if (migrated !== 0) throw new Error('Database migration failed');
await preparePocFiles(env);
if (env.WF_LOCAL_POC_BINDING_FILE) {
const pointed = await run(process.execPath, ['--import', 'tsx', 'scripts/cluster-poc-project.ts'], {
...base(),
DATABASE_URL: env.DATABASE_URL,
WF_LOCAL_POC_BINDING_FILE: env.WF_LOCAL_POC_BINDING_FILE,
});
if (pointed !== 0) throw new Error('Could not point the POC project’s checks at this image');
}
if (!(await exists(env.WF_LOCAL_ACCESS_FILE))) {
const created = await run(process.execPath, ['scripts/setup-local-access.mjs'], {
...base(),
WF_LOCAL_ACCESS_FILE: env.WF_LOCAL_ACCESS_FILE,
});
if (created !== 0) throw new Error('Could not create the local administrator credentials');
}
await prepareClaudeHome(env.WF_CLAUDE_LOCAL_AUTH_HOME);
return run(process.execPath, ['scripts/dev.mjs'], {
...base(),
WF_LOCAL_ENV_FILE: file,
WF_LOCAL_SERVICES: ROLES.platform.services,
WF_LOCAL_REUSE_SERVICES: 'false',
});
}
async function executor(file) {
const env = parseEnvFile(await readFile(file, 'utf8'));
await prepareClaudeHome(env.WF_CLAUDE_LOCAL_AUTH_HOME);
await preparePocFiles(env);
if (env.WF_LOCAL_POC_BINDING_FILE) {
const binding = JSON.parse(await readFile(env.WF_LOCAL_POC_BINDING_FILE, 'utf8'));
await prepareGitHome(binding.gitHome);
await mkdir(binding.stateDirectory, { recursive: true, mode: 0o700 });
}
await mkdir(env.WF_LOCAL_RUN_ROOT, { recursive: true, mode: 0o700 });
await waitForHttp('the control plane', `${env.WF_CONTROL_PLANE_URL}/readyz`);
return run(process.execPath, ['scripts/dev.mjs'], {
...base(),
WF_LOCAL_ENV_FILE: file,
WF_LOCAL_SERVICES: ROLES.executor.services,
WF_LOCAL_REUSE_SERVICES: 'false',
});
}
async function runner(file) {
const env = parseEnvFile(await readFile(file, 'utf8'));
await preparePocFiles(env);
await mkdir(env.WF_RUNNER_STATE_DIR, { recursive: true, mode: 0o700 });
await waitForHttp('the control plane', `${env.WF_CONTROL_PLANE_URL}/readyz`);
// A rehearsal deployment that must never act on the POC keeps its Runner idle.
if (process.env.WF_RUNNER_DISABLED === 'true') {
console.log('Runner disabled for this deployment (WF_RUNNER_DISABLED=true); idling.');
return idle();
}
return run(process.execPath, [`--env-file=${file}`, '--import', 'tsx', 'apps/runner/src/main.ts'], base());
}
export async function main(argv = process.argv.slice(2)) {
const role = argv[0];
if (argv.length !== 1 || !ROLES[role])
throw new Error(`Usage: cluster-poc-entry.mjs ${Object.keys(ROLES).join('|')}`);
// While data is restored, the database, Temporal and object storage run and nothing writes to them.
if (process.env.WF_MAINTENANCE === 'true') {
console.log(`${role}: maintenance (WF_MAINTENANCE=true); not starting.`);
return idle();
}
if (role === 'backup') return backupLoop();
const file = process.env.WF_ROLE_ENV_FILE || ROLES[role].env;
if (role === 'platform') return platform(file);
if (role === 'executor') return executor(file);
return runner(file);
}
if (process.argv[1] && pathToFileURL(path.resolve(process.argv[1])).href === import.meta.url)
main().then(
code => process.exit(code),
error => {
console.error(`[cluster-poc-entry] ${error.message}`);
process.exit(1);
},
);

View File

@ -0,0 +1,34 @@
/**
* Points the bound POC project's protected checks at this image (docs/cluster-poc-deployment.md):
* a project migrated from the Mac still names the Mac's Node and check script, which no check Pod
* has. The platform container runs this before the control plane starts; see clusterCheckCommands.
*/
import { readFile } from 'node:fs/promises';
import { PgStore } from '../apps/api/src/db/store.js';
import { touch } from '../apps/api/src/domain/control-plane.js';
import { localPocBindingSchema } from '../packages/runtime/src/index.js';
import type { Project } from '../packages/contracts/src/index.js';
import { clusterCheckCommands } from './cluster-poc-entry.mjs';
const binding = localPocBindingSchema.parse(JSON.parse(await readFile(process.env.WF_LOCAL_POC_BINDING_FILE!, 'utf8')));
const store = new PgStore(process.env.DATABASE_URL!);
try {
await store.assertSafeRole();
const changed = await store.transaction(binding.tenantId, async tx => {
const project = await tx.get<Project>('project', binding.projectId);
if (!project) return false;
const installCommands = clusterCheckCommands(project.installCommands, 'install');
const verificationCommands = clusterCheckCommands(project.verificationCommands, 'verify');
if (installCommands === project.installCommands && verificationCommands === project.verificationCommands)
return false;
await tx.put('project', touch({ ...project, installCommands, verificationCommands }));
return true;
});
console.log(
changed
? 'Pointed the POC project’s protected checks at this image.'
: 'The POC project’s protected checks already point at this image.',
);
} finally {
await store.close();
}

1567
scripts/cluster-poc.mjs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,321 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { parseAllDocuments } from 'yaml';
import {
buildFiles,
CARRIED,
clusterCaddyfile,
clusterHttpCaddyfile,
publicService,
clusterEnvironments,
clusterKubeconfig,
clusterPocFiles,
envFile,
imageBuildPod,
renderPlatform,
} from './cluster-poc.mjs';
import { clusterCheckCommands, endpoint, parseEnvFile, privateCopy } from './cluster-poc-entry.mjs';
const IMAGE = `ccr-29eug8s3-vpc.cnc.bj.baidubce.com/dataflow-poc/wishforge-cluster-poc@sha256:${'c'.repeat(64)}`;
const local = Object.fromEntries(CARRIED.map(key => [key, `value-of-${key.toLowerCase()}`]));
const runner = {
WF_RUNNER_TOKEN: 'runner-token',
WF_TENANT_ID: 'demo',
WF_ENVIRONMENT_ID: '6fabde42-b8e0-4398-80bb-be6ef78e5436',
WF_RUNNER_PUBLIC_KEYS: 'key',
WF_RUNNER_EXECUTE: 'true',
};
const generated = {
postgresPassword: 'p@ss/word',
appPassword: 'app-password-123456',
objectStorageUser: 'wishforge-user',
objectStoragePassword: 'object-storage-password',
};
test('the build sends only what Git tracks, never local agent settings or private state', () => {
const listing = [
'package.json',
'.claude/settings.local.json',
'.wishforge/local-access.json',
'.env.local',
'apps/web/.env.production',
'apps/ide/package.json',
'scripts/dev.mjs',
].join('\0');
assert.deepEqual(buildFiles(`${listing}\0`), ['package.json', 'scripts/dev.mjs']);
});
test('each container gets its own settings: no Mac path, and the executor no database or storage secret', () => {
const env = clusterEnvironments({ local, runner, image: IMAGE, generated, origins: ['https://120.48.1.2'] });
for (const values of Object.values(env))
assert.ok(!Object.values(values).some(value => value.includes('/Users/')), 'no Mac paths');
assert.equal(env.platform.DATABASE_ADMIN_URL, 'postgresql://wishforge:p%40ss%2Fword@127.0.0.1:5432/wishforge');
assert.equal(
env.platform.WF_LOCAL_ALLOWED_ORIGINS,
'http://127.0.0.1:3000,http://localhost:3000,http://127.0.0.1:13000,https://120.48.1.2',
);
assert.equal(env.platform.WF_VAULT_KEY, local.WF_VAULT_KEY);
for (const key of [
'DATABASE_URL',
'DATABASE_ADMIN_URL',
'S3_SECRET_ACCESS_KEY',
'WF_DEV_AUTH_TOKEN',
'WF_LOCAL_API_TOKEN',
'WF_VAULT_KEY',
])
assert.equal(env.executor[key], undefined, `executor has no ${key}`);
assert.equal(env.executor.WF_HOST_CHECK_POD_IMAGE, IMAGE);
assert.deepEqual(Object.keys(env.runner).sort(), [
'WF_CONTROL_PLANE_URL',
'WF_DEPLOYMENT_MODE',
'WF_ENVIRONMENT_ID',
'WF_POC_PROFILE_FILE',
'WF_RUNNER_ALLOW_LOCAL_HTTP',
'WF_RUNNER_EXECUTE',
'WF_RUNNER_PUBLIC_KEYS',
'WF_RUNNER_STATE_DIR',
'WF_RUNNER_TOKEN',
'WF_TENANT_ID',
]);
assert.throws(() => clusterEnvironments({ local: {}, runner, image: IMAGE, generated }), /Missing settings/);
assert.throws(() => clusterEnvironments({ local, runner, image: IMAGE, generated, origins: ['http://x'] }), /origin/);
});
test('the console receives the control plane credential under the name its launcher allows', () => {
const env = clusterEnvironments({
local: { ...local, WF_LOCAL_API_TOKEN: 'stale-mac-console-token' },
runner,
image: IMAGE,
generated,
});
assert.equal(env.platform.WF_LOCAL_API_TOKEN, env.platform.WF_DEV_AUTH_TOKEN);
assert.equal(env.platform.WF_WEB_SERVE_MODE, 'production');
assert.equal(env.executor.WF_LOCAL_API_TOKEN, undefined);
assert.equal(env.runner.WF_LOCAL_API_TOKEN, undefined);
});
test('settings files hold one value per line and read back the same', () => {
const text = envFile({ A: 'plain', B: 'with space #', C: 'postgresql://u:p%40@127.0.0.1:5432/db' });
assert.deepEqual(parseEnvFile(text), { A: 'plain', B: 'with space #', C: 'postgresql://u:p%40@127.0.0.1:5432/db' });
assert.throws(() => envFile({ A: 'two\nlines' }), /single-line/);
assert.throws(() => envFile({ A: "it's" }), /single-line/);
});
test('POC files keep their bindings and only move to the containers’ paths', () => {
const files = clusterPocFiles({
profile: { id: 'droboticflow-poc', kubeconfig: '/Users/x/poc.config', namespaceUid: 'u' },
binding: { projectId: 'p', profileFile: '/Users/x/p.json', stateDirectory: '/Users/x/s', gitHome: '/Users/x' },
});
assert.deepEqual(files.profile, {
id: 'droboticflow-poc',
kubeconfig: '/etc/wishforge/config/kubeconfig',
namespaceUid: 'u',
});
assert.equal(files.binding.projectId, 'p');
assert.equal(files.binding.gitHome, '/home/wishforge');
const config = JSON.parse(clusterKubeconfig('Q0E='));
assert.equal(config.clusters[0].cluster.server, 'https://120.48.181.105:6443');
assert.deepEqual(config.users[0].user, { tokenFile: '/var/run/wishforge/kube/token' });
assert.throws(() => clusterKubeconfig('not base64!'), /CA/);
});
test('the public entry serves a Let’s Encrypt IP certificate and redirects to the standard HTTPS port', () => {
const caddy = clusterCaddyfile('120.48.1.2');
assert.match(caddy, /https_port 8443/);
assert.match(caddy, /redir @safe https:\/\/\{host\}\{uri\} 308/);
assert.match(caddy, /^https:\/\/120\.48\.1\.2:8443 \{$/m);
assert.match(caddy, /profile shortlived/);
assert.match(caddy, /disable_tlsalpn_challenge/);
assert.match(caddy, /acme-v02\.api\.letsencrypt\.org/);
assert.match(clusterCaddyfile('120.48.1.2', { staging: true }), /acme-staging-v02/);
assert.throws(() => clusterCaddyfile('192.168.1.2'));
});
test('a plain-HTTP entry serves only port 80, proxies the console and asks for no certificate', async () => {
const caddy = clusterHttpCaddyfile('120.48.1.2');
assert.match(caddy, /^http:\/\/120\.48\.1\.2:8080 \{$/m);
assert.match(caddy, /reverse_proxy 127\.0\.0\.1:3000/);
assert.match(caddy, /header_up X-Forwarded-Proto http$/m);
assert.match(caddy, /auto_https off/);
assert.doesNotMatch(caddy, /8443|tls|acme|https:\/\//);
assert.throws(() => clusterHttpCaddyfile('192.168.1.2'));
const template = await readFile(new URL('../infra/k8s/cluster-poc/public-service.yaml', import.meta.url), 'utf8');
const ports = text =>
parseAllDocuments(text)
.map(document => document.toJS())[0]
.spec.ports.map(port => port.port);
assert.deepEqual(ports(publicService(template)), [80, 443]);
assert.deepEqual(ports(publicService(template, { http: true })), [80]);
const env = clusterEnvironments({ local, runner, image: IMAGE, generated, origins: ['http://120.48.1.2'] });
assert.equal(env.platform.WF_PUBLIC_URL, 'http://120.48.1.2');
assert.ok(env.platform.WF_LOCAL_ALLOWED_ORIGINS.split(',').includes('http://120.48.1.2'));
});
test('the WishForge Pod is restricted everywhere and only Caddy listens beyond loopback', async () => {
const template = await readFile(new URL('../infra/k8s/cluster-poc/platform.yaml', import.meta.url), 'utf8');
const settings = 'a'.repeat(32);
assert.throws(() => renderPlatform(template, { image: 'wishforge:latest', settings }), /pinned/);
assert.throws(() => renderPlatform(template, { image: IMAGE }), /settings digest/);
const rendered = renderPlatform(template, { image: IMAGE, runnerDisabled: true, maintenance: false, settings });
const statefulSet = parseAllDocuments(rendered)
.map(document => document.toJS())
.find(object => object.kind === 'StatefulSet');
const pod = statefulSet.spec.template.spec;
assert.equal(statefulSet.spec.template.metadata.annotations['wishforge.io/settings'], settings);
assert.equal(pod.automountServiceAccountToken, false);
assert.deepEqual(pod.securityContext.seccompProfile, { type: 'RuntimeDefault' });
assert.equal(pod.securityContext.runAsNonRoot, true);
assert.ok(!pod.volumes.some(volume => volume.hostPath));
for (const container of [...pod.initContainers, ...pod.containers]) {
assert.equal(container.securityContext.allowPrivilegeEscalation, false, container.name);
assert.equal(container.securityContext.readOnlyRootFilesystem, true, container.name);
assert.deepEqual(container.securityContext.capabilities, { drop: ['ALL'] }, container.name);
}
const mounts = name =>
pod.containers.find(container => container.name === name).volumeMounts.map(mount => mount.name);
assert.deepEqual(
pod.containers.filter(container => container.ports).map(container => container.name),
['caddy'],
);
for (const name of ['executor', 'runner']) assert.ok(mounts(name).includes('kube-token'), name);
for (const name of ['postgres', 'temporal', 'minio', 'platform', 'caddy', 'backup'])
assert.ok(!mounts(name).includes('kube-token'), name);
// The backup reads what it saves and writes only its own directory; no settings, keys or token.
const backup = pod.containers.find(container => container.name === 'backup');
assert.deepEqual(
backup.volumeMounts.filter(mount => mount.name === 'data' && !mount.readOnly).map(mount => mount.subPath),
['backups'],
);
assert.deepEqual(
backup.volumeMounts.filter(mount => mount.readOnly).map(mount => mount.subPath),
['git', 'minio', 'platform-state', 'poc-state', 'runner-state', 'temporal'],
);
assert.deepEqual([...new Set(mounts('backup'))], ['data', 'backup-tmp']);
assert.equal(backup.env.find(item => item.name === 'WF_IMAGE').value, IMAGE);
assert.match(pod.initContainers[0].args[0], / backups; do/);
assert.ok(!mounts('platform').includes('git-key') && mounts('executor').includes('git-key'));
assert.ok(mounts('platform').includes('env-platform') && !mounts('executor').includes('env-platform'));
const runnerEnv = pod.containers.find(container => container.name === 'runner').env;
assert.deepEqual(
runnerEnv.find(item => item.name === 'WF_RUNNER_DISABLED'),
{ name: 'WF_RUNNER_DISABLED', value: 'true' },
);
});
test('image builds run the POC’s Kaniko with only the registry credential and no token', () => {
const pod = imageBuildPod(
{
namespace: 'droboticflow',
registry: 'registry.example/ns',
registrySecret: 'droboticflow-registry',
kanikoImage: `gcr.io/kaniko-project/executor@sha256:${'d'.repeat(64)}`,
registryMirrors: ['mirror.gcr.io'],
},
{ name: 'wishforge-image-x', tag: 't' },
);
assert.equal(pod.spec.automountServiceAccountToken, false);
assert.deepEqual(
pod.spec.volumes.map(volume => Object.keys(volume).filter(key => key !== 'name')[0]),
['emptyDir', 'secret'],
);
assert.ok(pod.spec.containers[0].args.includes('--destination=registry.example/ns/wishforge-cluster-poc:t'));
assert.ok(pod.spec.containers[0].args.some(arg => arg.startsWith('--build-arg=MINIO_COMMIT=')));
});
test('the container entry reads service addresses and copies mounted files privately in one step', async t => {
assert.deepEqual(endpoint('postgresql://u:p@127.0.0.1:5432/db'), { host: '127.0.0.1', port: 5432 });
assert.deepEqual(endpoint('127.0.0.1:7233'), { host: '127.0.0.1', port: 7233 });
assert.deepEqual(endpoint('http://127.0.0.1:9000'), { host: '127.0.0.1', port: 9000 });
const directory = await mkdtemp(path.join(os.tmpdir(), 'wishforge-entry-'));
t.after(() => rm(directory, { recursive: true, force: true }));
const source = path.join(directory, 'mounted.json');
await writeFile(source, '{"a":1}', { mode: 0o644 });
const target = path.join(directory, 'private/copy.json');
await Promise.all([privateCopy(source, target), privateCopy(source, target)]);
assert.equal(await readFile(target, 'utf8'), '{"a":1}');
assert.equal((await stat(target)).mode & 0o777, 0o600);
});
test('a project migrated from the Mac runs its POC checks with this image’s Node and script', () => {
const node = '/usr/local/bin/node',
script = '/opt/wishforge/scripts/poc-project-check.mjs';
const mac = [
['/opt/homebrew/Cellar/node/26.7.0/bin/node', '/Users/me/wishforge-ide/scripts/poc-project-check.mjs', 'install'],
];
assert.deepEqual(clusterCheckCommands(mac, 'install', node, script), [[node, script, 'install']]);
const here = [[node, script, 'verify']];
assert.equal(clusterCheckCommands(here, 'verify', node, script), here);
for (const commands of [
[['npm', 'test']],
[mac[0], ['npm', 'test']],
[[mac[0][0], mac[0][1], 'verify']],
[[...mac[0], '--fast']],
[],
undefined,
])
assert.equal(clusterCheckCommands(commands, 'install', node, script), commands);
});
test('a domain the operator points at the load balancer becomes the console’s address, beside the IP', async () => {
const { publicDomain } = await import('./cluster-poc.mjs');
assert.equal(publicDomain(' WishForge.Example.cc '), 'wishforge.example.cc');
for (const name of ['x', 'http://wishforge.example.cc', '120.48.1.2', '-bad.example.cc', 'a..b.cc', undefined])
assert.throws(() => publicDomain(name), /domain/);
assert.match(
clusterHttpCaddyfile('120.48.1.2', { domain: 'wishforge.example.cc' }),
/^http:\/\/wishforge\.example\.cc:8080, http:\/\/120\.48\.1\.2:8080 \{$/m,
);
const https = clusterCaddyfile('120.48.1.2', { domain: 'wishforge.example.cc' });
assert.match(https, /^http:\/\/wishforge\.example\.cc:8080, http:\/\/120\.48\.1\.2:8080 \{$/m);
assert.match(https, /^https:\/\/wishforge\.example\.cc:8443, https:\/\/120\.48\.1\.2:8443 \{$/m);
assert.match(https, /default_sni 120\.48\.1\.2/);
const env = clusterEnvironments({
local,
runner,
image: IMAGE,
generated,
origins: ['http://wishforge.example.cc', 'http://120.48.1.2'],
});
assert.equal(env.platform.WF_PUBLIC_URL, 'http://wishforge.example.cc');
assert.deepEqual(env.platform.WF_LOCAL_ALLOWED_ORIGINS.split(',').slice(-2), [
'http://wishforge.example.cc',
'http://120.48.1.2',
]);
});
test('the public address is the load balancer’s public IPv4, never its VPC address', async () => {
const { publicAddressOf } = await import('./cluster-poc.mjs');
assert.equal(
publicAddressOf({ status: { loadBalancer: { ingress: [{ ip: '192.168.0.74' }, { ip: '120.48.164.20' }] } } }),
'120.48.164.20',
);
assert.equal(publicAddressOf({ status: { loadBalancer: {} } }), undefined);
assert.equal(publicAddressOf({ status: { loadBalancer: { ingress: [{ ip: '192.168.0.74' }] } } }), undefined);
});
test('a container in maintenance stays up until Kubernetes stops it', async () => {
const { spawn } = await import('node:child_process');
const child = spawn(process.execPath, [new URL('./cluster-poc-entry.mjs', import.meta.url).pathname, 'platform'], {
env: { PATH: process.env.PATH, WF_MAINTENANCE: 'true' },
stdio: 'ignore',
});
const exited = new Promise(resolve => child.once('exit', (code, signal) => resolve({ code, signal })));
await new Promise(resolve => setTimeout(resolve, 1500));
assert.equal(child.exitCode, null, 'still running');
child.kill('SIGTERM');
assert.deepEqual(await exited, { code: 0, signal: null });
});
test('the Claude CLI reaches the gateway by its Anthropic address with the requested models', async () => {
const { claudeSettings } = await import('./cluster-poc.mjs');
const pending = claudeSettings();
assert.equal(pending.env.ANTHROPIC_BASE_URL, 'https://ai-api.d-robotics.cc');
assert.equal(pending.env.ANTHROPIC_API_KEY, undefined);
assert.equal(pending.env.ANTHROPIC_MODEL, 'deepseek-pro@latest[1m]');
assert.equal(pending.env.ANTHROPIC_DEFAULT_HAIKU_MODEL, 'deepseek-flash@latest[1m]');
assert.equal(pending.env.CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC, '1');
assert.equal(claudeSettings('sk-fixture').env.ANTHROPIC_API_KEY, 'sk-fixture');
});

View File

@ -0,0 +1,248 @@
#!/usr/bin/env node
import { constants } from 'node:fs';
import { lstat, mkdir, open, readFile, writeFile } from 'node:fs/promises';
import { randomUUID } from 'node:crypto';
import { isIP } from 'node:net';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { parseEnv } from 'node:util';
import { replaceEnvFile, setEnvValues } from './env-file.mjs';
export const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const KEY = 'WF_LOCAL_ALLOWED_ORIGINS';
export const entryRoot = (root = ROOT) => path.join(root, '.wishforge/local-entry');
export function publicIPv4(value) {
if (isIP(value) !== 4) throw new Error('A public IPv4 address is required');
const [a, b, c] = value.split('.').map(Number);
if (
a === 0 ||
a === 10 ||
a === 127 ||
a >= 224 ||
(a === 100 && b >= 64 && b <= 127) ||
(a === 169 && b === 254) ||
(a === 172 && b >= 16 && b <= 31) ||
(a === 192 && (b === 168 || b === 0 || (b === 88 && c === 99))) ||
(a === 198 && (b === 18 || b === 19 || (b === 51 && c === 100))) ||
(a === 203 && b === 0 && c === 113)
)
throw new Error('The entry must use a publicly routable IPv4 address');
return value;
}
export async function privateDirectory(directory) {
await mkdir(directory, { recursive: true, mode: 0o700 });
const stat = await lstat(directory);
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid() || stat.mode & 0o077)
throw new Error('The entry state directory must be operator-owned and private');
}
export async function readPrivate(file) {
const handle = await open(file, constants.O_RDONLY | constants.O_NOFOLLOW);
try {
const stat = await handle.stat();
if (!stat.isFile() || stat.uid !== process.getuid() || stat.mode & 0o077)
throw new Error('Configuration must be an operator-owned private file');
return await handle.readFile('utf8');
} finally {
await handle.close();
}
}
function originsIn(source) {
const env = parseEnv(source);
if (
env.WF_LOCAL_ACCESS !== 'true' ||
env.WF_WEB_SERVE_MODE !== 'production' ||
env.WF_DEPLOYMENT_MODE !== 'development'
)
throw new Error('An authenticated production Web build in local development mode is required');
const origins = (env[KEY] ?? '')
.split(',')
.map(value => value.trim())
.filter(Boolean);
for (const origin of origins) {
const url = new URL(origin);
if (!['http:', 'https:'].includes(url.protocol) || url.origin !== origin || url.username || url.password)
throw new Error('Existing allowed origins must be exact HTTP(S) origins');
}
if (!origins.length) throw new Error('Keep the existing local entry origins configured');
return origins;
}
export function entryPlan(source, address) {
const origin = `https://${publicIPv4(address)}`;
const previous = originsIn(source);
const origins = [...new Set([...previous, origin])];
return {
origin,
previous,
origins,
added: !previous.includes(origin),
source: setEnvValues(source, { [KEY]: origins.join(',') }),
};
}
/** Preview is read-only. Applying only adds this origin; its receipt can remove only that addition. */
export async function configureEntry({ root = ROOT, address, apply = false, revert }) {
const file = path.join(root, '.env.local');
const before = await readPrivate(file);
if (revert) {
const receipts = path.join(entryRoot(root), 'receipts');
const receiptFile = path.resolve(revert);
if (path.dirname(receiptFile) !== receipts) throw new Error('Use a receipt from this entry state directory');
const receipt = JSON.parse(await readPrivate(receiptFile));
if (
receipt.version !== 1 ||
receipt.added !== true ||
receipt.origin !== `https://${publicIPv4(new URL(receipt.origin).hostname)}`
)
throw new Error('The receipt does not describe an origin this tool added');
const previous = originsIn(before);
const origins = previous.filter(value => value !== receipt.origin);
const changed = origins.length !== previous.length;
if (apply && changed) await replaceEnvFile(file, before, setEnvValues(before, { [KEY]: origins.join(',') }));
return {
origin: receipt.origin,
removed: changed,
applied: apply && changed,
origins,
restartRequired: apply && changed,
};
}
const { source: next, ...summary } = entryPlan(before, address);
if (!apply || !summary.added) return { ...summary, applied: false };
const state = entryRoot(root);
await privateDirectory(state);
const receipts = path.join(state, 'receipts');
await privateDirectory(receipts);
const id = randomUUID();
await writeFile(path.join(receipts, `${id}.env`), before, { flag: 'wx', mode: 0o600 });
const receipt = path.join(receipts, `${id}.json`);
await writeFile(receipt, JSON.stringify({ version: 1, origin: summary.origin, added: true }, null, 2), {
flag: 'wx',
mode: 0o600,
});
await replaceEnvFile(file, before, next);
return { ...summary, applied: true, receipt, restartRequired: true };
}
/** All user HTTPS terminates on this Mac; the cluster transports opaque TCP. */
export function entryConfigs(address, state, staging = false) {
const ip = publicIPv4(address);
const ca = `https://acme${staging ? '-staging' : ''}-v02.api.letsencrypt.org/directory`;
const caddy = `{
admin off
skip_install_trust
default_bind 127.0.0.1
http_port 18080
https_port 18443
default_sni ${ip}
auto_https disable_redirects
servers {
protocols h1 h2
}
}
http://${ip}:18080 {
bind 127.0.0.1
@safe method GET HEAD
redir @safe https://${ip}{uri} 308
respond 405
}
https://${ip}:18443 {
bind 127.0.0.1
tls {
issuer acme {
dir ${ca}
test_dir ${ca}
profile shortlived
disable_tlsalpn_challenge
alt_http_port 18080
}
}
reverse_proxy 127.0.0.1:3000 {
header_up X-Forwarded-Proto https
header_up -Forwarded
}
}
`;
const file = name => JSON.stringify(path.join(state, 'mtls', name));
const frpc = `serverAddr = "${ip}"
serverPort = 7000
loginFailExit = false
transport.protocol = "tcp"
transport.tls.enable = true
transport.tls.serverName = "wishforge-entry.internal"
transport.tls.certFile = ${file('client.crt')}
transport.tls.keyFile = ${file('client.key')}
transport.tls.trustedCaFile = ${file('ca.crt')}
auth.method = "token"
auth.additionalScopes = ["HeartBeats", "NewWorkConns"]
auth.tokenSource.type = "file"
auth.tokenSource.file.path = ${file('token')}
log.to = "console"
log.level = "info"
log.disablePrintColor = true
[[proxies]]
name = "wishforge-http"
type = "tcp"
localIP = "127.0.0.1"
localPort = 18080
remotePort = 18080
[[proxies]]
name = "wishforge-https"
type = "tcp"
localIP = "127.0.0.1"
localPort = 18443
remotePort = 18443
`;
return { caddy, frpc };
}
export async function writeEntryConfigs({ root = ROOT, address, staging = false }) {
const state = entryRoot(root);
await privateDirectory(state);
const configs = entryConfigs(address, state, staging);
for (const [name, content] of [
['Caddyfile', configs.caddy],
['frpc.toml', configs.frpc],
]) {
const file = path.join(state, name);
try {
const before = await readPrivate(file);
await replaceEnvFile(file, before, content);
} catch (error) {
if (error.code !== 'ENOENT') throw error;
await writeFile(file, content, { flag: 'wx', mode: 0o600 });
}
}
const settings = path.join(state, 'entry.json');
const content = JSON.stringify({ version: 1, address: publicIPv4(address), staging }, null, 2);
try {
const before = await readPrivate(settings);
await replaceEnvFile(settings, before, content);
} catch (error) {
if (error.code !== 'ENOENT') throw error;
await writeFile(settings, content, { flag: 'wx', mode: 0o600 });
}
return { address, staging, state };
}
if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
const args = process.argv.slice(2);
try {
let result;
if (args[0] === '--address' && args[1] && args.length <= 3 && (!args[2] || args[2] === '--apply'))
result = await configureEntry({ address: args[1], apply: args[2] === '--apply' });
else if (args[0] === '--revert' && args[1] && args.length <= 3 && (!args[2] || args[2] === '--apply'))
result = await configureEntry({ revert: args[1], apply: args[2] === '--apply' });
else if (args[0] === '--config' && args[1] && args.length <= 3 && (!args[2] || args[2] === '--staging'))
result = await writeEntryConfigs({ address: args[1], staging: args[2] === '--staging' });
else
throw new Error(
'Usage: configure-local-entry.mjs --address <public-ip> [--apply] | --revert <receipt> [--apply] | --config <public-ip> [--staging]',
);
console.log(JSON.stringify(result, null, 2));
} catch (error) {
console.error(error.message);
process.exitCode = 1;
}
}

View File

@ -0,0 +1,115 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { chmod, lstat, mkdtemp, readFile, rm, symlink, writeFile } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import {
configureEntry,
entryConfigs,
entryPlan,
entryRoot,
publicIPv4,
writeEntryConfigs,
} from './configure-local-entry.mjs';
const IP = '120.48.164.20';
const SOURCE = [
'WF_DEPLOYMENT_MODE=development',
'WF_LOCAL_ACCESS=true',
'WF_WEB_SERVE_MODE=production',
'WF_LOCAL_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000,https://previous.trycloudflare.com',
'WF_DEV_AUTH_TOKEN=fixture-private-value',
'',
].join('\n');
async function fixture(t) {
const root = await mkdtemp(path.join(os.tmpdir(), 'wf-entry-config-test-'));
t.after(() => rm(root, { recursive: true, force: true }));
await writeFile(path.join(root, '.env.local'), SOURCE, { mode: 0o600 });
return root;
}
test('only accepts public IPv4, never a URL, private or documentation address', () => {
assert.equal(publicIPv4(IP), IP);
for (const value of [
'https://8.8.8.8',
'localhost',
'127.0.0.1',
'10.0.0.1',
'192.168.1.2',
'172.16.2.1',
'100.64.1.2',
'169.254.169.254',
'203.0.113.1',
'198.51.100.1',
'224.0.0.1',
'::1',
'8.8.8.8\n',
])
assert.throws(() => publicIPv4(value));
});
test('previews without writing, retains old origins and never returns private environment text', async t => {
const root = await fixture(t);
const result = await configureEntry({ root, address: IP });
assert.equal(result.applied, false);
assert.equal(await readFile(path.join(root, '.env.local'), 'utf8'), SOURCE);
assert.ok(result.origins.includes('https://previous.trycloudflare.com'));
assert.ok(!JSON.stringify(result).includes('fixture-private-value'));
await assert.rejects(lstat(entryRoot(root)), { code: 'ENOENT' });
assert.throws(() => entryPlan(SOURCE.replace('WF_LOCAL_ACCESS=true', 'WF_LOCAL_ACCESS=false'), IP));
assert.throws(() => entryPlan(SOURCE.replace('WF_WEB_SERVE_MODE=production', 'WF_WEB_SERVE_MODE=development'), IP));
});
test('applies once and reverts only its addition, preserving later changes', async t => {
const root = await fixture(t);
const result = await configureEntry({ root, address: IP, apply: true });
assert.equal(result.applied, true);
assert.equal((await lstat(result.receipt)).mode & 0o777, 0o600);
const file = path.join(root, '.env.local');
const applied = await readFile(file, 'utf8');
assert.ok(applied.includes('fixture-private-value'));
assert.ok(applied.includes(`https://${IP}`));
assert.equal((await configureEntry({ root, address: IP, apply: true })).applied, false);
await writeFile(file, `${applied.replace(`https://${IP}`, `https://${IP},https://later.example`)}OTHER=new\n`);
const preview = await configureEntry({ root, revert: result.receipt });
assert.equal(preview.applied, false);
const reverted = await configureEntry({ root, revert: result.receipt, apply: true });
assert.equal(reverted.applied, true);
const after = await readFile(file, 'utf8');
assert.ok(!after.includes(IP));
assert.ok(after.includes('https://later.example'));
assert.ok(after.includes('https://previous.trycloudflare.com'));
assert.ok(after.includes('OTHER=new'));
assert.equal((await lstat(file)).mode & 0o777, 0o600);
await assert.rejects(configureEntry({ root, revert: path.join(root, 'elsewhere.json'), apply: true }));
});
test('refuses shared or symbolic-link environment files', async t => {
const root = await fixture(t);
const file = path.join(root, '.env.local');
await chmod(file, 0o644);
await assert.rejects(configureEntry({ root, address: IP, apply: true }));
await rm(file);
await writeFile(path.join(root, 'elsewhere'), SOURCE, { mode: 0o600 });
await symlink(path.join(root, 'elsewhere'), file);
await assert.rejects(configureEntry({ root, address: IP, apply: true }));
});
test('generates fixed loopback targets, explicit IP ACME and distinct staging storage settings', async t => {
const root = await fixture(t);
const result = await writeEntryConfigs({ root, address: IP, staging: true });
const { caddy, frpc } = entryConfigs(IP, result.state, true);
assert.match(caddy, /default_bind 127\.0\.0\.1/);
assert.match(caddy, new RegExp(`default_sni ${IP.replaceAll('.', '\\.')}`));
assert.match(caddy, /acme-staging-v02/);
assert.match(caddy, /profile shortlived/);
assert.match(caddy, /disable_tlsalpn_challenge/);
assert.match(caddy, /auto_https disable_redirects/);
assert.match(caddy, /reverse_proxy 127\.0\.0\.1:3000/);
assert.match(caddy, /header_up X-Forwarded-Proto https/);
assert.ok(!caddy.includes('tls internal'));
assert.ok(!caddy.includes('strict_sni_host'));
assert.match(frpc, /transport\.tls\.trustedCaFile/);
assert.match(frpc, /transport\.tls\.certFile/);
assert.match(frpc, /auth\.tokenSource\.file\.path/);
assert.equal((frpc.match(/\[\[proxies\]\]/g) ?? []).length, 2);
for (const unsafe of ['4000', '4300', 'visitors', 'plugins', 'webServer']) assert.ok(!frpc.includes(unsafe));
await writeEntryConfigs({ root, address: IP, staging: false });
assert.ok(!(await readFile(path.join(result.state, 'Caddyfile'), 'utf8')).includes('acme-staging'));
assert.equal((await lstat(path.join(result.state, 'entry.json'))).mode & 0o777, 0o600);
});

View File

@ -1,5 +1,12 @@
import { resolve } from 'node:path';
import { environment, loadLocalEnvironment, platformPorts, startServices, webListener } from './local-services.mjs';
import {
environment,
loadLocalEnvironment,
platformPorts,
selectServices,
startServices,
webListener,
} from './local-services.mjs';
loadLocalEnvironment();
const root = process.cwd();
@ -17,7 +24,7 @@ const worker = (role, token) => ({
}),
});
await startServices(
[
selectServices([
{
name: 'git',
cwd: root,
@ -51,7 +58,8 @@ await startServices(
/^WF_CLAUDE_BIN$/,
/^WF_CLAUDE_LOCAL_AUTH_HOME$/,
/^WF_CLAUDE_COMMAND_(SANDBOX|READ_PATHS|ENV)$/,
/^WF_HOST_CHECK_(SANDBOX|READ_PATHS|WRITE_PATHS|LOOPBACK)$/,
/^WF_HOST_CHECK_(SANDBOX|READ_PATHS|WRITE_PATHS|LOOPBACK|KUBECONFIG|KUBECTL)$/,
/^WF_HOST_CHECK_POD_(NAMESPACE|IMAGE|CLAIM|ROOT|CPU|MEMORY)$/,
],
{
// Sandboxed checks never reach the platform's own services, whatever the operator listed.
@ -80,7 +88,7 @@ await startServices(
),
url: `http://${web.probe}:${web.port}${process.env.WF_LOCAL_ACCESS === 'true' ? '/login' : '/api/session'}`,
},
],
]),
`WishForge console: http://localhost:${web.port} · API: http://127.0.0.1:4000 · Temporal: http://127.0.0.1:8233`,
// The LaunchAgent supervisor starts every service itself; one already answering is a leftover.
{ reuse: process.env.WF_LOCAL_REUSE_SERVICES !== 'false' },

View File

@ -0,0 +1,305 @@
#!/usr/bin/env node
// A separate LaunchAgent for the public entry. Importing this module starts nothing.
import { spawn, spawnSync } from 'node:child_process';
import { existsSync, lstatSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
import { readdir, readFile } from 'node:fs/promises';
import { homedir } from 'node:os';
import { X509Certificate } from 'node:crypto';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { setTimeout as delay } from 'node:timers/promises';
import { ROOT, entryRoot, entryConfigs, privateDirectory, readPrivate, publicIPv4 } from './configure-local-entry.mjs';
import { minimalEnvironment, rotateAppend } from './local-poc-service.mjs';
export const LABEL = 'cc.d-robotics.wishforge.local-entry';
const STATE = entryRoot();
const NODE = '/opt/homebrew/bin/node';
const DOMAIN = `gui/${process.getuid?.()}`;
const SERVICE = `${DOMAIN}/${LABEL}`;
const PLIST = path.join(homedir(), 'Library/LaunchAgents', `${LABEL}.plist`);
const STATE_FILE = path.join(STATE, 'service-state.json');
const log = (name, message) => rotateAppend(path.join(STATE, 'logs', `${name}.log`), message);
export function entryEnvironment(state, staging, network = {}) {
const proxies = Object.fromEntries(
['HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY'].filter(key => network[key]).map(key => [key, network[key]]),
);
return {
...minimalEnvironment(state),
TMPDIR: path.join(state, 'tmp'),
XDG_DATA_HOME: path.join(state, staging ? 'caddy-staging' : 'caddy-production'),
XDG_CONFIG_HOME: path.join(state, 'caddy-config'),
...proxies,
};
}
export function entryCommands(state) {
return [
{
name: 'caddy',
binary: path.join(state, 'bin/caddy'),
args: ['run', '--config', path.join(state, 'Caddyfile'), '--adapter', 'caddyfile'],
},
{ name: 'frpc', binary: path.join(state, 'bin/frpc'), args: ['-c', path.join(state, 'frpc.toml')] },
];
}
const xml = value =>
String(value).replace(
/[<>&"']/g,
char => ({ '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;', "'": '&apos;' })[char],
);
export function entryPlist(root = ROOT, network = {}) {
const env = entryEnvironment(entryRoot(root), false, network);
return `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>${LABEL}</string>
<key>ProgramArguments</key><array>${[NODE, path.join(root, 'scripts/local-entry-service.mjs'), 'run'].map(value => `<string>${xml(value)}</string>`).join('')}</array>
<key>WorkingDirectory</key><string>${xml(root)}</string>
<key>EnvironmentVariables</key><dict>${Object.entries(env)
.map(([key, value]) => `<key>${key}</key><string>${xml(value)}</string>`)
.join('')}</dict>
<key>RunAtLoad</key><true/><key>KeepAlive</key><true/>
<key>ThrottleInterval</key><integer>30</integer><key>ExitTimeOut</key><integer>25</integer>
<key>Umask</key><integer>63</integer><key>ProcessType</key><string>Background</string>
<key>StandardOutPath</key><string>/dev/null</string><key>StandardErrorPath</key><string>/dev/null</string>
</dict></plist>\n`;
}
function launchctl(args, checked = true) {
const result = spawnSync('/bin/launchctl', args, { encoding: 'utf8', timeout: 35000, env: minimalEnvironment() });
if (checked && result.status !== 0) throw new Error(`launchctl ${args[0]} failed (exit ${result.status})`);
return result;
}
const registered = () => launchctl(['print', SERVICE], false).status === 0;
async function settings() {
const data = JSON.parse(await readPrivate(path.join(STATE, 'entry.json')));
if (data.version !== 1 || typeof data.staging !== 'boolean') throw new Error('Invalid entry configuration');
publicIPv4(data.address);
return data;
}
async function preflight() {
if (process.platform !== 'darwin') throw new Error('The entry service uses a macOS user LaunchAgent');
await privateDirectory(STATE);
const data = await settings();
const expected = entryConfigs(data.address, STATE, data.staging);
for (const [name, content] of [
['Caddyfile', expected.caddy],
['frpc.toml', expected.frpc],
])
if ((await readPrivate(path.join(STATE, name))) !== content)
throw new Error(`Regenerate the managed ${name} before starting`);
for (const name of ['ca.crt', 'client.crt', 'client.key', 'token']) await readPrivate(path.join(STATE, 'mtls', name));
for (const { binary } of entryCommands(STATE)) {
const stat = lstatSync(binary);
if (!stat.isFile() || stat.isSymbolicLink() || stat.uid !== process.getuid() || stat.mode & 0o022)
throw new Error('Entry binaries must be operator-owned regular files, not writable by others');
}
const env = entryEnvironment(STATE, data.staging, process.env);
for (const directory of [env.TMPDIR, env.XDG_DATA_HOME, env.XDG_CONFIG_HOME, path.join(STATE, 'logs')])
await privateDirectory(directory);
return { data, env };
}
async function validate() {
const { env } = await preflight();
for (const [binary, args] of [
[path.join(STATE, 'bin/caddy'), ['validate', '--config', path.join(STATE, 'Caddyfile'), '--adapter', 'caddyfile']],
[path.join(STATE, 'bin/frpc'), ['verify', '-c', path.join(STATE, 'frpc.toml')]],
]) {
const result = spawnSync(binary, args, { env, cwd: ROOT, timeout: 30000, encoding: 'utf8' });
if (result.status !== 0)
throw new Error(`${path.basename(binary)} configuration validation failed (exit ${result.status})`);
}
return { valid: true };
}
/** Signals only children this supervisor spawned, never PIDs loaded from a stale state file. */
export async function stopChildren(children, kill = process.kill, wait = delay) {
const active = child => child.pid && child.exitCode === null && child.signalCode === null;
const signal = name => {
for (const child of children.filter(active)) {
try {
kill(-child.pid, name);
} catch (error) {
if (error.code !== 'ESRCH') throw error;
}
}
};
signal('SIGTERM');
for (let attempt = 0; attempt < 30 && children.some(active); attempt++) await wait(200);
signal('SIGKILL');
}
async function supervise() {
const { data, env } = await preflight();
const children = [];
let stopping;
const stop = () => (stopping ??= stopChildren(children));
for (const signal of ['SIGTERM', 'SIGINT']) process.once(signal, () => void stop());
const ended = [];
for (const command of entryCommands(STATE)) {
const child = spawn(command.binary, command.args, {
cwd: ROOT,
env,
shell: false,
detached: true,
stdio: ['ignore', 'pipe', 'pipe'],
});
children.push(child);
child.stdout.on('data', bytes => log(command.name, bytes));
child.stderr.on('data', bytes => log(command.name, bytes));
ended.push(
new Promise(resolve => {
child.once('error', () => {
log('supervisor', `${command.name} failed to start\n`);
resolve();
});
child.once('close', code => {
log('supervisor', `${command.name} exited ${code}\n`);
resolve();
});
}),
);
}
writeFileSync(
STATE_FILE,
JSON.stringify({
supervisorPid: process.pid,
children: children.map((child, index) => ({ name: entryCommands(STATE)[index].name, pid: child.pid })),
address: data.address,
staging: data.staging,
startedAt: new Date().toISOString(),
}),
{ mode: 0o600 },
);
await Promise.race(ended);
await stop();
await Promise.all(ended);
}
async function certificates(directory, address) {
const found = [];
async function visit(dir, depth) {
if (depth > 8) return;
for (const entry of await readdir(dir, { withFileTypes: true }).catch(() => [])) {
const file = path.join(dir, entry.name);
if (entry.isDirectory()) await visit(file, depth + 1);
else if (entry.isFile() && entry.name.endsWith('.crt')) {
try {
const cert = new X509Certificate(await readFile(file));
if (cert.checkIP(address))
found.push({
subjectAltName: cert.subjectAltName,
issuer: cert.issuer,
validTo: cert.validTo,
expiresInHours: Math.floor((Date.parse(cert.validTo) - Date.now()) / 3600000),
});
} catch {
/* An unrelated certificate is not an entry certificate. */
}
}
}
}
await visit(directory, 0);
return found;
}
async function status() {
const printed = launchctl(['print', SERVICE], false);
const pid = printed.status === 0 ? Number(printed.stdout.match(/^\s*pid = (\d+)$/m)?.[1]) || null : null;
let data;
try {
data = await settings();
} catch {
/* Not yet configured. */
}
let saved;
try {
saved = JSON.parse(readFileSync(STATE_FILE, 'utf8'));
} catch {
/* No matching supervisor state. */
}
let httpsStatus = null;
if (pid && data && !data.staging) {
try {
httpsStatus = (
await fetch(`https://${data.address}/login`, { redirect: 'manual', signal: AbortSignal.timeout(7000) })
).status;
} catch {
/* Unavailable or an untrusted/expired certificate. */
}
}
return {
label: LABEL,
installed: existsSync(PLIST),
registered: printed.status === 0,
pid,
children: pid && saved?.supervisorPid === pid ? saved.children : [],
address: data?.address,
staging: data?.staging,
httpsStatus,
ready: Boolean(pid && httpsStatus === 200),
certificates: data ? await certificates(entryEnvironment(STATE, data.staging).XDG_DATA_HOME, data.address) : [],
};
}
export function entryAction(args) {
if (!args.length) return 'status';
if (args.length !== 1 || !['install', 'start', 'stop', 'status', 'validate', 'run'].includes(args[0]))
throw new Error('Usage: local-entry-service.mjs install|start|stop|status|validate');
return args[0];
}
export async function main(args = process.argv.slice(2)) {
const action = entryAction(args);
if (action === 'run') return supervise();
if (action === 'status') return status();
if (action === 'validate') return validate();
if (action === 'stop') {
const printed = launchctl(['print', SERVICE], false);
const pid = printed.status === 0 ? Number(printed.stdout.match(/^\s*pid = (\d+)$/m)?.[1]) || null : null;
const pids = pid ? [pid] : [];
try {
const saved = JSON.parse(await readPrivate(STATE_FILE));
if (pid && saved.supervisorPid === pid)
pids.push(
...saved.children
.filter(child => ['caddy', 'frpc'].includes(child.name) && Number.isSafeInteger(child.pid) && child.pid > 1)
.map(child => child.pid),
);
} catch {
/* No current supervisor state to wait for. */
}
const alive = value => {
try {
process.kill(value, 0);
return true;
} catch (error) {
return error.code !== 'ESRCH';
}
};
launchctl(['disable', SERVICE]);
if (registered()) launchctl(['bootout', DOMAIN, PLIST]);
for (let attempt = 0; attempt < 60 && (registered() || pids.some(alive)); attempt++) await delay(250);
return { label: LABEL, stopCompleted: !registered() && !pids.some(alive) };
}
await validate();
if (action === 'install') {
const content = entryPlist(ROOT, process.env);
if (registered()) throw new Error('Stop this entry service before installing its LaunchAgent');
const temporary = `${PLIST}.tmp`;
writeFileSync(temporary, content, { mode: 0o600 });
const result = spawnSync('/usr/bin/plutil', ['-lint', temporary], { encoding: 'utf8', timeout: 10000 });
if (result.status !== 0) throw new Error('Invalid entry LaunchAgent plist');
renameSync(temporary, PLIST);
}
if (!existsSync(PLIST)) throw new Error('Install the entry service first');
launchctl(['enable', SERVICE]);
if (!registered()) launchctl(['bootstrap', DOMAIN, PLIST]);
launchctl(['kickstart', SERVICE]);
return status();
}
if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href)
main()
.then(result => {
if (result) console.log(JSON.stringify(result, null, 2));
if (result?.stopCompleted === false) process.exitCode = 1;
})
.catch(error => {
console.error(error.message);
process.exitCode = 1;
});

View File

@ -0,0 +1,148 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { mkdtemp, readFile, rm, symlink } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { once } from 'node:events';
import { parseAllDocuments } from 'yaml';
import {
entryAction,
entryCommands,
entryEnvironment,
entryPlist,
LABEL,
stopChildren,
} from './local-entry-service.mjs';
import { isPolicyMain, policyServer, proxyDecision } from '../infra/k8s/local-entry/proxy-policy.mjs';
test('recognizes the policy entrypoint through a ConfigMap-style symlink without starting on import', async t => {
const directory = await mkdtemp(path.join(os.tmpdir(), 'wf-policy-link-'));
t.after(() => rm(directory, { recursive: true, force: true }));
const moduleUrl = new URL('../infra/k8s/local-entry/proxy-policy.mjs', import.meta.url);
const link = path.join(directory, 'proxy-policy.mjs');
await symlink(fileURLToPath(moduleUrl), link);
assert.equal(isPolicyMain(moduleUrl.href, link), true);
assert.equal(isPolicyMain(import.meta.url, link), false);
assert.equal(isPolicyMain(moduleUrl.href, path.join(directory, 'missing')), false);
});
test('entry commands and environment do not inherit platform credentials or control its services', () => {
const env = entryEnvironment('/private/state', true, {
WF_DEV_AUTH_TOKEN: 'never-copy',
HOME: '/Users/operator',
HTTPS_PROXY: 'http://127.0.0.1:8089',
});
assert.ok(!('WF_DEV_AUTH_TOKEN' in env));
assert.equal(env.HOME, '/private/state');
assert.equal(env.HTTPS_PROXY, 'http://127.0.0.1:8089');
assert.ok(env.XDG_DATA_HOME.endsWith('caddy-staging'));
assert.ok(entryEnvironment('/private/state', false).XDG_DATA_HOME.endsWith('caddy-production'));
const commands = entryCommands('/private/state');
assert.deepEqual(
commands.map(command => command.name),
['caddy', 'frpc'],
);
assert.ok(commands.every(command => command.binary.startsWith('/private/state/bin/')));
const plist = entryPlist('/work/repo&space', { WF_DEV_AUTH_TOKEN: 'never-copy' });
assert.match(plist, /repo&amp;space/);
assert.ok(plist.includes(LABEL));
assert.ok(!plist.includes('never-copy'));
assert.ok(!plist.includes('cc.d-robotics.wishforge.local-poc'));
assert.equal(entryAction([]), 'status');
assert.throws(() => entryAction(['start', '--anything']));
});
test('stops only live children it owns, never already finished processes', async () => {
const children = [
{ pid: 10001, exitCode: null, signalCode: null },
{ pid: 10002, exitCode: 0, signalCode: null },
];
const sent = [];
await stopChildren(
children,
(pid, signal) => {
sent.push([pid, signal]);
children[0].signalCode = signal;
},
async () => {},
);
assert.deepEqual(sent, [[-10001, 'SIGTERM']]);
});
test('FRP registration only accepts the two named TCP ports', () => {
const base = { op: 'NewProxy', content: { proxy_name: 'wishforge-http', proxy_type: 'tcp', remote_port: 18080 } };
assert.deepEqual(proxyDecision(base), { reject: false, unchange: true });
assert.equal(
proxyDecision({ ...base, content: { proxy_name: 'wishforge-https', proxy_type: 'tcp', remote_port: 18443 } })
.reject,
false,
);
for (const change of [
{ proxy_type: 'stcp' },
{ proxy_type: 'udp' },
{ remote_port: 4000 },
{ proxy_name: 'other' },
{ group: 'shared' },
{ custom_domains: ['anything.example'] },
])
assert.equal(proxyDecision({ ...base, content: { ...base.content, ...change } }).reject, true);
for (const request of [null, {}, { ...base, op: 'Login' }]) assert.equal(proxyDecision(request).reject, true);
});
test('policy endpoint rejects malformed input and reports health without logging content', async t => {
const server = policyServer();
server.listen(0, '127.0.0.1');
await once(server, 'listening');
t.after(() => {
server.closeAllConnections();
server.close();
});
const origin = `http://127.0.0.1:${server.address().port}`;
assert.equal((await fetch(`${origin}/healthz`)).status, 200);
assert.equal((await fetch(`${origin}/other`)).status, 403);
const invalid = await fetch(`${origin}/validate`, { method: 'POST', body: '{' });
assert.equal(invalid.status, 400);
assert.equal((await invalid.json()).reject, true);
const allowed = await fetch(`${origin}/validate?op=NewProxy`, {
method: 'POST',
body: JSON.stringify({
op: 'NewProxy',
content: { proxy_name: 'wishforge-https', proxy_type: 'tcp', remote_port: 18443 },
}),
});
assert.equal((await allowed.json()).reject, false);
});
test('cluster manifests are isolated and do not implicitly create the billable Service', async () => {
const directory = new URL('../infra/k8s/local-entry/', import.meta.url);
const raw = await readFile(new URL('gateway.yaml', directory), 'utf8');
const resources = parseAllDocuments(raw).map(document => document.toJS());
const deploy = resources.find(resource => resource.kind === 'Deployment');
assert.equal(deploy.metadata.namespace, 'wishforge-access');
assert.equal(deploy.spec.replicas, 1);
assert.equal(deploy.spec.strategy.type, 'Recreate');
const pod = deploy.spec.template.spec;
assert.equal(pod.automountServiceAccountToken, false);
assert.equal(pod.securityContext.runAsNonRoot, true);
assert.ok(
pod.containers.every(
container =>
container.image.includes('@sha256:') &&
container.securityContext.readOnlyRootFilesystem &&
!container.securityContext.allowPrivilegeEscalation,
),
);
assert.equal(pod.containers[0].readinessProbe.tcpSocket.port, 'tunnel');
assert.ok(!pod.volumes.some(volume => volume.hostPath || volume.persistentVolumeClaim));
const kustomization = await readFile(new URL('kustomization.yaml', directory), 'utf8');
assert.ok(!kustomization.includes('public-service.yaml'));
const service = parseAllDocuments(await readFile(new URL('public-service.yaml', directory), 'utf8'))[0].toJS();
assert.deepEqual(
service.spec.ports.map(port => port.port),
[80, 443, 7000],
);
assert.equal(service.metadata.annotations['service.beta.kubernetes.io/cce-elastic-ip-bandwidth-in-mbps'], '5');
assert.equal(service.metadata.annotations['service.beta.kubernetes.io/cce-elastic-ip-billing-method'], 'ByTraffic');
assert.equal(service.metadata.annotations['service.beta.kubernetes.io/cce-elastic-ip-route-type'], 'BGP');
assert.ok(!('service.beta.kubernetes.io/cce-load-balancer-id' in service.metadata.annotations));
assert.ok(!service.spec.loadBalancerIP);
assert.ok(!raw.includes('droboticflow-api'));
assert.ok(!raw.includes('wishforge.io/tenant'));
});

View File

@ -3,11 +3,15 @@
import { spawn } from 'node:child_process';
import { setTimeout as delay } from 'node:timers/promises';
export function loadLocalEnvironment() {
/**
* Loads the private settings: .env.local on the operator's machine, or the file a container is
* given (WF_LOCAL_ENV_FILE), which holds only what that container's services need.
*/
export function loadLocalEnvironment(file = process.env.WF_LOCAL_ENV_FILE || '.env.local') {
try {
process.loadEnvFile('.env.local');
process.loadEnvFile(file);
} catch {
throw new Error('.env.local is missing; run npm run setup:local first');
throw new Error(`${file} is missing; run npm run setup:local first`);
}
if (process.env.WF_DEPLOYMENT_MODE !== 'development')
throw new Error('Local services need WF_DEPLOYMENT_MODE=development in .env.local; run npm run setup:local');
@ -73,6 +77,22 @@ export function platformPorts(env = process.env) {
for (const port of (env.WF_HOST_CHECK_BLOCKED_PORTS ?? '').split(',')) if (port.trim()) ports.add(Number(port));
return [...ports].filter(port => Number.isInteger(port) && port > 0 && port < 65536).sort((a, b) => a - b);
}
/**
* The services this process starts: all of them, or those WF_LOCAL_SERVICES names (separated by
* commas), where they run in separate containers of one Pod. An unknown name is an error.
*/
export function selectServices(services, env = process.env) {
const wanted = (env.WF_LOCAL_SERVICES ?? '')
.split(',')
.map(name => name.trim())
.filter(Boolean);
if (!wanted.length) return services;
const known = new Set(services.map(service => service.name));
const unknown = wanted.filter(name => !known.has(name));
if (unknown.length) throw new Error(`WF_LOCAL_SERVICES names unknown services: ${unknown.join(', ')}`);
return services.filter(service => wanted.includes(service.name));
}
/** Each process sees only the settings matching its patterns, plus the deployment mode. */
export function environment(patterns, extra = {}) {
return {

View File

@ -3,7 +3,7 @@ import { mkdtemp, readFile, rm } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import test from 'node:test';
import { platformPorts, startServices, webListener } from './local-services.mjs';
import { platformPorts, selectServices, startServices, webListener } from './local-services.mjs';
const alive = pid => {
try {
@ -90,3 +90,17 @@ test("the platform's own ports come from its configured addresses", () => {
[3000, 4000, 4300, 4301, 4450, 4504, 6379, 7233, 8233, 49000, 55432],
);
});
test('starts every service, or only those a container is given, in their order', () => {
const services = ['git', 'api', 'provisioner', 'coordinator', 'deployer', 'web'].map(name => ({ name }));
assert.equal(selectServices(services, {}), services);
assert.deepEqual(
selectServices(services, { WF_LOCAL_SERVICES: 'web, api ,git' }).map(service => service.name),
['git', 'api', 'web'],
);
assert.deepEqual(
selectServices(services, { WF_LOCAL_SERVICES: 'provisioner' }).map(service => service.name),
['provisioner'],
);
assert.throws(() => selectServices(services, { WF_LOCAL_SERVICES: 'api,database' }), /unknown services: database/);
});

View File

@ -10,12 +10,29 @@ const APPROVED_ORIGINS = new Set([
'ssh://git@gitea.d-robotics.cc/longtao.wu/droboticflow.git',
'git@gitea.d-robotics.cc:longtao.wu/droboticflow.git',
]);
const TOOLS = {
git: '/usr/bin/git',
node: '/opt/homebrew/bin/node',
npm: '/opt/homebrew/bin/npm',
go: '/opt/homebrew/bin/go',
/** Fixed absolute tools, never a PATH lookup: the operator Mac's Homebrew, or the cluster image's. */
export const TOOLCHAINS = {
darwin: {
git: '/usr/bin/git',
node: '/opt/homebrew/bin/node',
npm: '/opt/homebrew/bin/npm',
go: '/opt/homebrew/bin/go',
path: '/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin',
},
linux: {
git: '/usr/bin/git',
node: '/usr/local/bin/node',
npm: '/usr/local/bin/npm',
go: '/usr/local/go/bin/go',
path: '/usr/local/go/bin:/usr/local/bin:/usr/bin:/bin',
},
};
export function toolchain(platform = process.platform) {
const tools = TOOLCHAINS[platform];
if (!tools) throw new Error(`Protected checks have no approved toolchain on ${platform}`);
return tools;
}
const TOOLS = toolchain();
const CACHE = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../.wishforge/poc-check-cache');
export function parseCheckMode(argv) {
@ -24,9 +41,9 @@ export function parseCheckMode(argv) {
return argv[0];
}
export function checkEnvironment(cacheRoot = CACHE, inherited = process.env, network = false) {
export function checkEnvironment(cacheRoot = CACHE, inherited = process.env, network = false, tools = TOOLS) {
return {
PATH: '/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin',
PATH: tools.path,
HOME: path.join(cacheRoot, 'home'),
TMPDIR: path.join(cacheRoot, 'tmp'),
LANG: 'C.UTF-8',

View File

@ -6,7 +6,25 @@ import { existsSync } from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { assertApprovedWorkspace, checkEnvironment, checkPlan, parseCheckMode } from './poc-project-check.mjs';
import {
assertApprovedWorkspace,
checkEnvironment,
checkPlan,
parseCheckMode,
TOOLCHAINS,
toolchain,
} from './poc-project-check.mjs';
test('each platform has one fixed absolute toolchain and its own PATH', () => {
for (const platform of ['darwin', 'linux']) {
const tools = toolchain(platform);
for (const name of ['git', 'node', 'npm', 'go']) assert.ok(path.isAbsolute(tools[name]), `${platform} ${name}`);
assert.equal(checkEnvironment('/private/cache', {}, false, tools).PATH, tools.path);
}
assert.equal(toolchain('linux').go, '/usr/local/go/bin/go');
assert.ok(!TOOLCHAINS.linux.path.includes('/opt/homebrew'));
assert.throws(() => toolchain('win32'), /no approved toolchain/);
});
test('only fixed install and verification modes are accepted', () => {
assert.equal(parseCheckMode(['install']), 'install');

View File

@ -1,7 +1,16 @@
import { mkdir, mkdtemp, rm } from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { afterEach, describe, expect, it, vi } from 'vitest';
import type { CommandExecutor, HostCheckSandbox } from '@wishforge/runtime';
import { hostCheckExecutor, hostCheckSandbox } from '../apps/worker/src/host-checks.js';
import { validateCheckPodConfig } from '@wishforge/runtime';
import {
closeHostChecks,
hostCheckExecutor,
hostCheckPods,
hostCheckSandbox,
type HostCheckExecutor,
} from '../apps/worker/src/host-checks.js';
import type { WorkerConfig } from '../apps/worker/src/common.js';
describe('operator opt-in to sandboxed host checks', () => {
@ -47,3 +56,153 @@ describe('operator opt-in to sandboxed host checks', () => {
expect(hostCheckExecutor({ sandboxMode: 'host', hostCheckSandbox } as WorkerConfig, execute)).not.toBe(execute);
});
});
describe('operator opt-in to check Pods on a cluster-hosted development host', () => {
const pods = {
WF_HOST_CHECK_POD_NAMESPACE: 'wishforge-checks',
WF_HOST_CHECK_POD_IMAGE: `registry.example/wishforge/cluster-poc@sha256:${'b'.repeat(64)}`,
WF_HOST_CHECK_POD_CLAIM: 'wishforge-exec',
WF_HOST_CHECK_POD_ROOT: '/var/lib/wishforge/exec',
WF_HOST_CHECK_KUBECONFIG: '/etc/wishforge/kube/checks.config',
WF_HOST_CHECK_WRITE_PATHS: '/var/lib/wishforge/exec/check-cache',
WF_WORKER_ID: 'verifier-1234',
WF_SANDBOX_RUN_ID: 'run-1',
};
it('reads the namespace, image, claim, volume root and kubeconfig, and runs as the worker user', () => {
expect(hostCheckPods({})).toBeUndefined();
expect(hostCheckPods(pods)).toMatchObject({
namespace: 'wishforge-checks',
claim: 'wishforge-exec',
mountRoot: '/var/lib/wishforge/exec',
kubectl: '/usr/local/bin/kubectl',
writable: ['/var/lib/wishforge/exec/check-cache'],
uid: process.getuid!(),
gid: process.getgid!(),
owner: 'verifier-1234:run-1',
});
});
it('refuses a missing setting, an image by tag, caches off the volume and a second sandbox', () => {
expect(() => hostCheckPods({ ...pods, WF_HOST_CHECK_POD_CLAIM: '' })).toThrow(/WF_HOST_CHECK_POD_CLAIM/);
expect(() => hostCheckPods({ ...pods, WF_HOST_CHECK_POD_IMAGE: 'check:latest' })).toThrow(/digest/);
expect(() => hostCheckPods({ ...pods, WF_HOST_CHECK_WRITE_PATHS: '/tmp/cache' })).toThrow(/run volume/);
expect(() => hostCheckPods({ ...pods, WF_HOST_CHECK_SANDBOX: 'true' })).toThrow(/alternatives/);
});
it('uses check Pods only in the development host mode', () => {
const execute: CommandExecutor = async () => ({ exitCode: 0, stdout: '', stderr: '' });
const hostCheckPodsConfig = hostCheckPods(pods)!;
expect(
hostCheckExecutor({ sandboxMode: 'kata', hostCheckPods: hostCheckPodsConfig } as WorkerConfig, execute),
).toBe(execute);
expect(
hostCheckExecutor({ sandboxMode: 'host', hostCheckPods: hostCheckPodsConfig } as WorkerConfig, execute),
).not.toBe(execute);
});
});
describe('hostCheckExecutor binds cancellation only at the command boundary', () => {
it('composes the activity signal with a command signal, and uses the activity signal alone otherwise', async () => {
const seen: (AbortSignal | undefined)[] = [];
const execute: CommandExecutor = async command => {
seen.push(command.signal);
return { exitCode: 0, stdout: '', stderr: '' };
};
const activity = new AbortController();
const bound = hostCheckExecutor({ sandboxMode: 'kata' } as WorkerConfig, execute, activity.signal);
await bound({ executable: 'true', args: [], cwd: '/work' });
expect(seen[0]).toBe(activity.signal);
const perCommand = new AbortController();
await bound({ executable: 'true', args: [], cwd: '/work', signal: perCommand.signal });
const composed = seen[1]!;
expect(composed).not.toBe(activity.signal);
expect(composed).not.toBe(perCommand.signal);
expect(composed.aborted).toBe(false);
perCommand.abort();
expect(composed.aborted).toBe(true);
});
it('returns the raw executor unchanged when no activity signal is given, even with check Pods configured', () => {
const execute: CommandExecutor = async () => ({ exitCode: 0, stdout: '', stderr: '' });
expect(hostCheckExecutor({ sandboxMode: 'kata' } as WorkerConfig, execute)).toBe(execute);
});
});
describe('check Pod cleanup never inherits the activity signal', () => {
const directories: string[] = [];
afterEach(async () => {
await Promise.all(directories.splice(0).map(directory => rm(directory, { recursive: true, force: true })));
});
async function checkPodsConfig(mountRoot: string) {
return validateCheckPodConfig({
kubectl: '/usr/bin/kubectl',
kubeconfig: '/etc/wishforge/kube/checks.config',
namespace: 'wishforge-checks',
image: `registry.example/wishforge/cluster-poc@sha256:${'d'.repeat(64)}`,
claim: 'wishforge-exec',
mountRoot,
writable: [],
uid: process.getuid!(),
gid: process.getgid!(),
owner: 'fixture:run',
});
}
function fakeKubectl(kubectl: string, onDelete: () => void): CommandExecutor {
return async command => {
// A raw transport must never see an already-canceled activity signal on its own calls.
if (command.signal?.aborted) throw new Error('kubectl invoked with an already-aborted signal');
if (command.executable !== kubectl) return { exitCode: 0, stdout: '', stderr: '' };
const verb = command.args[command.args.indexOf('-n') + 2];
if (verb === 'create') return { exitCode: 0, stdout: 'pod/wf-check-fixture', stderr: '' };
if (verb === 'wait') return { exitCode: 0, stdout: '', stderr: '' };
if (verb === 'exec') return { exitCode: 0, stdout: '', stderr: '\n__WISHFORGE_CHECK_EXIT__=0\n' };
if (verb === 'delete') {
onDelete();
return { exitCode: 0, stdout: 'pod/wf-check-fixture\n', stderr: '' };
}
throw new Error(`Unexpected kubectl verb in fixture: ${verb}`);
};
}
it('still deletes a check Pod through dispose once the activity signal that ran its command has aborted', async () => {
const root = await mkdtemp(path.join(os.tmpdir(), 'wishforge-host-checks-'));
directories.push(root);
const workspace = path.join(root, 'workspace');
await mkdir(workspace, { recursive: true });
const deleted = vi.fn();
const execute = fakeKubectl('/usr/bin/kubectl', deleted);
const config = { sandboxMode: 'host', hostCheckPods: await checkPodsConfig(root) } as WorkerConfig;
const activity = new AbortController();
const bound: HostCheckExecutor = hostCheckExecutor(config, execute, activity.signal);
await bound({
executable: 'true',
args: [],
cwd: workspace,
sandboxRoot: workspace,
env: {},
timeoutMs: 1000,
});
activity.abort();
await expect(bound.dispose!()).resolves.toBeUndefined();
expect(deleted).toHaveBeenCalledTimes(1);
});
});
describe('closeHostChecks reports whether cleanup is confirmed, without throwing', () => {
it('resolves true when there is nothing to close', async () => {
await expect(closeHostChecks(undefined)).resolves.toBe(true);
});
it('resolves true once dispose succeeds', async () => {
const dispose = vi.fn().mockResolvedValue(undefined);
const checks = Object.assign((async () => ({ exitCode: 0, stdout: '', stderr: '' })) as CommandExecutor, {
dispose,
});
await expect(closeHostChecks(checks)).resolves.toBe(true);
expect(dispose).toHaveBeenCalledTimes(1);
});
it('resolves false and warns, without throwing, when dispose cannot confirm cleanup', async () => {
const warning = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
const checks = Object.assign((async () => ({ exitCode: 0, stdout: '', stderr: '' })) as CommandExecutor, {
dispose: vi.fn().mockRejectedValue(new Error('Check Pod cleanup remains pending')),
});
await expect(closeHostChecks(checks)).resolves.toBe(false);
expect(warning).toHaveBeenCalled();
warning.mockRestore();
});
});