Public dry run dryrun-a43e907efd9d

Source commit: a43e907efd9d1561c23fe73499478e881f868355

Public tree identity: sha256:453dea30195485dd8939f575a69b39f4bb7acd84c4df23f8aa29b55d044f2673
This commit is contained in:
Clusterflux release dry run 2026-07-15 01:54:51 +02:00
commit 6f52bb46cd
210 changed files with 77158 additions and 0 deletions

25
scripts/acceptance-private.sh Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail
repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo"
scripts/check-old-name.sh
node scripts/check-docs.js
scripts/check-code-size.sh
cargo fmt --all --manifest-path private/hosted-policy/Cargo.toml --check
cargo clippy --manifest-path private/hosted-policy/Cargo.toml --all-targets -- -D warnings
cargo test --manifest-path private/hosted-policy/Cargo.toml --all-targets
node private/hosted-policy/scripts/prepare-public-release-dryrun-deployment.js
node private/hosted-policy/scripts/hosted-deployment-smoke.js
node private/hosted-policy/scripts/hosted-client-compat-smoke.js
if command -v podman >/dev/null 2>&1; then
node private/hosted-policy/scripts/postgres-durable-smoke.js
elif command -v nix >/dev/null 2>&1; then
nix shell nixpkgs#podman --command node private/hosted-policy/scripts/postgres-durable-smoke.js
else
node private/hosted-policy/scripts/postgres-durable-smoke.js
fi
if [[ -n "${CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_SERVICE_ADDR:-}" ]]; then
node private/hosted-policy/scripts/public-release-dryrun-service-smoke.js
fi

51
scripts/acceptance-public.sh Executable file
View file

@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -euo pipefail
repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo"
scripts/check-old-name.sh
node scripts/check-docs.js
scripts/check-code-size.sh
scripts/release-source-scan.sh
cargo fmt --all --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace --all-targets
cargo build --workspace --all-targets
cargo build -p launch-build-demo --target wasm32-unknown-unknown
node scripts/resource-metering-contract-smoke.js
node scripts/hostile-input-contract-smoke.js
node scripts/tenant-isolation-contract-smoke.js
node scripts/self-hosted-coordinator-smoke.js
node scripts/public-local-demo-matrix-smoke.js
node scripts/cli-output-mode-smoke.js
node scripts/cli-login-smoke.js
node scripts/cli-error-exit-smoke.js
node scripts/cli-browser-login-flow-smoke.js
node scripts/cli-install-smoke.js
node scripts/user-session-token-boundary-smoke.js
node scripts/sdk-spawn-runtime-smoke.js
node scripts/node-lifecycle-contract-smoke.js
node scripts/wasmtime-node-smoke.js
node scripts/wasmtime-assignment-smoke.js
if command -v podman >/dev/null 2>&1; then
node scripts/podman-backend-smoke.js
elif command -v nix >/dev/null 2>&1; then
nix shell nixpkgs#podman --command node scripts/podman-backend-smoke.js
else
node scripts/podman-backend-smoke.js
fi
node scripts/vscode-extension-smoke.js
node scripts/vscode-f5-smoke.js
node scripts/node-attach-smoke.js
node scripts/cli-local-run-smoke.js
node scripts/artifact-download-smoke.js
node scripts/artifact-export-smoke.js
node scripts/operator-panel-smoke.js
node scripts/source-preparation-smoke.js
node scripts/scheduler-placement-smoke.js
node scripts/windows-best-effort-smoke.js
node scripts/quic-smoke.js
node scripts/dap-smoke.js
node scripts/flagship-demo-smoke.js
scripts/verify-public-split.sh

99
scripts/agent-signing.js Normal file
View file

@ -0,0 +1,99 @@
const crypto = require("crypto");
const { nodeIdentity, signedRequestPayloadDigest } = require("./node-signing");
function agentIdentity(seedPrefix, agent) {
const identity = nodeIdentity(seedPrefix, agent);
return {
...identity,
publicKeyFingerprint: `sha256:${crypto
.createHash("sha256")
.update(identity.publicKey)
.digest("hex")}`,
};
}
function agentWorkflowSignatureMessage({
tenant,
project,
agent,
requestKind,
process: processId,
task = "",
payloadDigest,
nonce,
issuedAtEpochSeconds,
}) {
const parts = [
"clusterflux-agent-workflow-signature:v2",
tenant,
project,
agent,
requestKind,
processId,
task,
payloadDigest,
nonce,
String(issuedAtEpochSeconds),
];
return Buffer.concat(
parts.flatMap((part) => [
Buffer.from(`${Buffer.byteLength(part)}:`),
Buffer.from(part),
Buffer.from("\n"),
])
);
}
function signedAgentWorkflowProof(identity, request, options = {}) {
const nonce =
options.nonce ||
`${request.type}-${process.pid}-${Date.now()}-${crypto
.randomBytes(8)
.toString("hex")}`;
const issuedAtEpochSeconds =
options.issuedAtEpochSeconds || Math.floor(Date.now() / 1000);
const processId =
request.type === "launch_task" ? request.task_spec?.process : request.process;
const task =
request.type === "launch_task" ? request.task_spec?.task_instance : request.task || "";
const signature = crypto.sign(
null,
agentWorkflowSignatureMessage({
tenant: request.tenant,
project: request.project,
agent: request.actor_agent,
requestKind: request.type,
process: processId,
task,
payloadDigest: signedRequestPayloadDigest(request),
nonce,
issuedAtEpochSeconds,
}),
identity.privateKeyObject
);
return {
nonce,
issued_at_epoch_seconds: issuedAtEpochSeconds,
signature: `ed25519:${signature.toString("base64")}`,
};
}
function signedAgentWorkflowRequest(identity, request, options = {}) {
const unsignedRequest = {
...request,
agent_public_key_fingerprint:
options.publicKeyFingerprint || identity.publicKeyFingerprint,
};
return {
...unsignedRequest,
agent_signature: signedAgentWorkflowProof(identity, unsignedRequest, options),
};
}
module.exports = {
agentIdentity,
agentWorkflowSignatureMessage,
signedAgentWorkflowProof,
signedAgentWorkflowRequest,
};

View file

@ -0,0 +1,401 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const crypto = require("crypto");
const fs = require("fs");
const os = require("os");
const path = require("path");
const { nodeIdentity, signedNodeRequest } = require("./node-signing");
const {
ensureRootlessPodman,
flagshipNodeCapabilities,
launchFlagship,
repo,
runFlagshipWorker,
send,
waitForJsonLine,
} = require("./real-flagship-harness");
const downloadNode = "node-download";
const downloadNodeIdentity = nodeIdentity("artifact-download-smoke", downloadNode);
const delay = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
async function downloadRetainedBytes(addr, link, artifact, expectedSize) {
const chunks = [];
let offset = 0;
for (let attempt = 0; attempt < 500; attempt += 1) {
const response = await send(addr, {
type: "open_artifact_download_stream",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact,
max_bytes: 1024 * 1024,
token_digest: link.link.scoped_token_digest,
chunk_bytes: 256 * 1024,
});
assert.strictEqual(response.type, "artifact_download_stream");
if (!response.content_bytes_available) {
assert.strictEqual(response.content_source, "retaining_node_reverse_stream_pending");
await delay(10);
continue;
}
assert.strictEqual(response.content_source, "retaining_node_reverse_stream");
assert.strictEqual(response.content_offset, offset);
const bytes = Buffer.from(response.content_base64, "base64");
assert.strictEqual(response.streamed_bytes, bytes.length);
chunks.push(bytes);
offset += bytes.length;
if (response.content_eof) {
const content = Buffer.concat(chunks);
assert.strictEqual(content.length, expectedSize);
return { content, response };
}
}
throw new Error("timed out waiting for retained artifact reverse stream");
}
function downloadNodeCapabilities() {
return flagshipNodeCapabilities();
}
(async () => {
ensureRootlessPodman();
const coordinator = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"--",
"--listen",
"127.0.0.1:0",
"--allow-local-trusted-loopback",
],
{ cwd: repo }
);
let worker;
try {
const ready = await waitForJsonLine(coordinator);
const [host, portText] = ready.listen.split(":");
const addr = { host, port: Number(portText) };
assert.strictEqual((await send(addr, { type: "ping" })).type, "pong");
worker = await runFlagshipWorker(addr, downloadNode, downloadNodeIdentity);
const workerReady = await worker.ready;
assert.strictEqual(workerReady.node_status, "ready");
assert.strictEqual(workerReady.mode, "worker");
const { compileEvent, packageEvent, process: virtualProcess } = await launchFlagship(addr);
assert.strictEqual(compileEvent.status_code, 0);
assert.strictEqual(packageEvent.status_code, 0);
assert.deepStrictEqual(compileEvent.result, {
Artifact: {
id: compileEvent.artifact_path.slice("/vfs/artifacts/".length),
digest: compileEvent.artifact_digest,
size_bytes: compileEvent.artifact_size_bytes,
},
});
assert.deepStrictEqual(packageEvent.result, {
Artifact: {
id: packageEvent.artifact_path.slice("/vfs/artifacts/".length),
digest: packageEvent.artifact_digest,
size_bytes: packageEvent.artifact_size_bytes,
},
});
assert.ok(compileEvent.artifact_size_bytes > 0);
assert.ok(packageEvent.artifact_size_bytes > compileEvent.artifact_size_bytes);
assert.match(compileEvent.artifact_digest, /^sha256:[0-9a-f]{64}$/);
assert.match(packageEvent.artifact_digest, /^sha256:[0-9a-f]{64}$/);
const artifactPath = packageEvent.artifact_path;
assert.match(artifactPath, /^\/vfs\/artifacts\/release\.tar-[0-9a-f]{64}$/);
const artifact = artifactPath.slice("/vfs/artifacts/".length);
const disconnectedReport = await send(addr, signedNodeRequest(downloadNode, downloadNodeIdentity, "report_node_capabilities", {
type: "report_node_capabilities",
tenant: "tenant",
project: "project",
node: downloadNode,
capabilities: downloadNodeCapabilities(),
cached_environment_digests: [],
dependency_cache_digests: [],
source_snapshots: [],
artifact_locations: [artifact],
direct_connectivity: false,
online: true,
}));
assert.strictEqual(disconnectedReport.type, "node_capabilities_recorded");
const disconnectedLink = await send(addr, {
type: "create_artifact_download_link",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact,
max_bytes: 1024 * 1024,
ttl_seconds: 60,
});
assert.strictEqual(disconnectedLink.type, "artifact_download_link");
const connectedReport = await send(addr, signedNodeRequest(downloadNode, downloadNodeIdentity, "report_node_capabilities", {
type: "report_node_capabilities",
tenant: "tenant",
project: "project",
node: downloadNode,
capabilities: downloadNodeCapabilities(),
cached_environment_digests: [],
dependency_cache_digests: [],
source_snapshots: [],
artifact_locations: [artifact],
direct_connectivity: true,
online: true,
}));
assert.strictEqual(connectedReport.type, "node_capabilities_recorded");
const link = await send(addr, {
type: "create_artifact_download_link",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact,
max_bytes: 1024 * 1024,
ttl_seconds: 60,
});
assert.strictEqual(link.type, "artifact_download_link");
assert.strictEqual(link.link.tenant, "tenant");
assert.strictEqual(link.link.project, "project");
assert.strictEqual(link.link.process, virtualProcess);
assert.deepStrictEqual(link.link.actor, { User: "user" });
assert.match(link.link.policy_context_digest, /^sha256:[0-9a-f]{64}$/);
assert.ok(link.link.expires_at_epoch_seconds > Math.floor(Date.now() / 1000));
assert.ok(link.link.expires_at_epoch_seconds <= Math.floor(Date.now() / 1000) + 60);
assert.ok(
link.link.url_path.endsWith(
`/artifacts/tenant/project/${virtualProcess}/${artifact}`
)
);
assert.deepStrictEqual(link.link.source, { RetainedNode: "node-download" });
const crossTenant = await send(addr, {
type: "create_artifact_download_link",
tenant: "other",
project: "project",
actor_user: "user",
artifact,
max_bytes: 1024 * 1024,
ttl_seconds: 60,
});
assert.strictEqual(crossTenant.type, "error");
assert.match(crossTenant.message, /tenant mismatch/);
const crossProject = await send(addr, {
type: "create_artifact_download_link",
tenant: "tenant",
project: "other-project",
actor_user: "user",
artifact,
max_bytes: 1024 * 1024,
ttl_seconds: 60,
});
assert.strictEqual(crossProject.type, "error");
assert.match(crossProject.message, /project mismatch/);
const crossTenantOpen = await send(addr, {
type: "open_artifact_download_stream",
tenant: "other",
project: "project",
actor_user: "user",
artifact,
max_bytes: 1024 * 1024,
token_digest: link.link.scoped_token_digest,
chunk_bytes: 1,
});
assert.strictEqual(crossTenantOpen.type, "error");
assert.match(crossTenantOpen.message, /tenant mismatch/);
const crossProjectOpen = await send(addr, {
type: "open_artifact_download_stream",
tenant: "tenant",
project: "other-project",
actor_user: "user",
artifact,
max_bytes: 1024 * 1024,
token_digest: link.link.scoped_token_digest,
chunk_bytes: 1,
});
assert.strictEqual(crossProjectOpen.type, "error");
assert.match(crossProjectOpen.message, /project mismatch/);
const guessed = await send(addr, {
type: "open_artifact_download_stream",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact,
max_bytes: 1024 * 1024,
token_digest: "sha256:guessed",
chunk_bytes: 1,
});
assert.strictEqual(guessed.type, "error");
assert.match(guessed.message, /token is invalid/);
const crossActorOpen = await send(addr, {
type: "open_artifact_download_stream",
tenant: "tenant",
project: "project",
actor_user: "other-user",
artifact,
max_bytes: 1024 * 1024,
token_digest: link.link.scoped_token_digest,
chunk_bytes: 1,
});
assert.strictEqual(crossActorOpen.type, "error");
assert.match(crossActorOpen.message, /token is invalid/);
const downloaded = await downloadRetainedBytes(
addr,
link,
artifact,
packageEvent.artifact_size_bytes,
);
const downloadedDigest = `sha256:${crypto
.createHash("sha256")
.update(downloaded.content)
.digest("hex")}`;
assert.strictEqual(downloadedDigest, packageEvent.artifact_digest);
const inspect = fs.mkdtempSync(path.join(os.tmpdir(), "clusterflux-release-"));
try {
const archive = path.join(inspect, "release.tar");
fs.writeFileSync(archive, downloaded.content);
const listing = cp.execFileSync("tar", ["-tf", archive], { encoding: "utf8" });
assert.strictEqual(listing.trim(), "hello-clusterflux");
cp.execFileSync("tar", ["-xf", archive, "-C", inspect]);
fs.chmodSync(path.join(inspect, "hello-clusterflux"), 0o755);
assert.strictEqual(
cp.execFileSync(path.join(inspect, "hello-clusterflux"), { encoding: "utf8" }),
"hello from a real Clusterflux build\n"
);
} finally {
fs.rmSync(inspect, { recursive: true, force: true });
}
const cliDownloadDirectory = fs.mkdtempSync(
path.join(os.tmpdir(), "clusterflux-cli-download-")
);
try {
const cliDownloadPath = path.join(cliDownloadDirectory, "release.tar");
const cliDownload = JSON.parse(
cp.execFileSync(
"cargo",
[
"run", "-q", "-p", "clusterflux-cli", "--bin", "clusterflux", "--",
"artifact", "download", artifact,
"--to", cliDownloadPath,
"--max-bytes", "1048576",
"--coordinator", `clusterflux+tcp://${addr.host}:${addr.port}`,
"--tenant", "tenant",
"--project-id", "project",
"--user", "user",
"--json",
],
{ cwd: repo, env: process.env, encoding: "utf8" }
)
);
assert.strictEqual(cliDownload.command, "artifact download");
assert.strictEqual(cliDownload.local_download.status, "local_bytes_written");
assert.strictEqual(
cliDownload.local_download.verified_digest,
packageEvent.artifact_digest
);
assert.strictEqual(
`sha256:${crypto
.createHash("sha256")
.update(fs.readFileSync(cliDownloadPath))
.digest("hex")}`,
packageEvent.artifact_digest
);
} finally {
fs.rmSync(cliDownloadDirectory, { recursive: true, force: true });
}
assert.strictEqual(downloaded.response.content_eof, true);
assert.strictEqual(
downloaded.response.charged_download_bytes,
packageEvent.artifact_size_bytes
);
assert.strictEqual(downloaded.response.link.artifact, artifact);
const crossActorRevoke = await send(addr, {
type: "revoke_artifact_download_link",
tenant: "tenant",
project: "project",
actor_user: "other-user",
artifact,
token_digest: link.link.scoped_token_digest,
});
assert.strictEqual(crossActorRevoke.type, "error");
assert.match(crossActorRevoke.message, /token is invalid/);
const revoked = await send(addr, {
type: "revoke_artifact_download_link",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact,
token_digest: link.link.scoped_token_digest,
});
assert.strictEqual(revoked.type, "artifact_download_link_revoked");
assert.strictEqual(revoked.link.scoped_token_digest, link.link.scoped_token_digest);
const revokedOpen = await send(addr, {
type: "open_artifact_download_stream",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact,
max_bytes: 1024 * 1024,
token_digest: link.link.scoped_token_digest,
chunk_bytes: 1,
});
assert.strictEqual(revokedOpen.type, "error");
assert.match(revokedOpen.message, /revoked/);
const gcReport = await send(addr, signedNodeRequest(downloadNode, downloadNodeIdentity, "report_node_capabilities", {
type: "report_node_capabilities",
tenant: "tenant",
project: "project",
node: downloadNode,
capabilities: downloadNodeCapabilities(),
cached_environment_digests: [],
dependency_cache_digests: [],
source_snapshots: [],
artifact_locations: [],
direct_connectivity: false,
online: true,
}));
assert.strictEqual(gcReport.type, "node_capabilities_recorded");
const collectedLink = await send(addr, {
type: "create_artifact_download_link",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact,
max_bytes: 1024 * 1024,
ttl_seconds: 60,
});
assert.strictEqual(collectedLink.type, "error");
assert.match(collectedLink.message, /unavailable from current retention/);
} finally {
worker?.child.kill("SIGTERM");
coordinator.kill("SIGTERM");
}
console.log("Artifact download smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

View file

@ -0,0 +1,268 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const fs = require("fs");
const os = require("os");
const path = require("path");
const { nodeIdentity, signedNodeRequest } = require("./node-signing");
const {
ensureRootlessPodman,
flagshipNodeCapabilities,
launchFlagship,
repo,
runFlagshipWorker,
send,
waitForJsonLine,
} = require("./real-flagship-harness");
const sourceNode = "node-export-source";
const sourceIdentity = nodeIdentity("artifact-export-smoke", sourceNode);
function nodeCapabilities() {
return flagshipNodeCapabilities();
}
function runJson(command, args, options = {}) {
return new Promise((resolve, reject) => {
const child = cp.spawn(command, args, { cwd: repo, ...options });
let stdout = "";
let stderr = "";
child.stdout.on("data", (chunk) => {
stdout += chunk.toString();
});
child.stderr.on("data", (chunk) => {
stderr += chunk.toString();
});
child.once("error", reject);
child.once("exit", (code) => {
if (code !== 0) {
reject(
new Error(
`${command} ${args.join(" ")} failed with code ${code}\n${stderr}\n${stdout}`
)
);
return;
}
try {
resolve(JSON.parse(stdout));
} catch (error) {
reject(new Error(`${command} did not return JSON\n${stdout}\n${error.message}`));
}
});
});
}
async function reportNode(
addr,
node,
identity,
{ directConnectivity = true, online = true, artifacts = [] } = {}
) {
const response = await send(addr, signedNodeRequest(node, identity, "report_node_capabilities", {
type: "report_node_capabilities",
tenant: "tenant",
project: "project",
node,
capabilities: nodeCapabilities(),
cached_environment_digests: [],
dependency_cache_digests: [],
source_snapshots: [],
artifact_locations: artifacts,
direct_connectivity: directConnectivity,
online,
}));
assert.strictEqual(response.type, "node_capabilities_recorded");
assert.strictEqual(response.node, node);
}
(async () => {
ensureRootlessPodman();
const coordinator = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"--",
"--listen",
"127.0.0.1:0",
"--allow-local-trusted-loopback",
],
{
cwd: repo,
env: { ...process.env, CLUSTERFLUX_NODE_STALE_AFTER_SECONDS: "1" },
}
);
let worker;
try {
const ready = await waitForJsonLine(coordinator);
const [host, portText] = ready.listen.split(":");
const addr = { host, port: Number(portText) };
assert.strictEqual((await send(addr, { type: "ping" })).type, "pong");
worker = await runFlagshipWorker(addr, sourceNode, sourceIdentity);
const workerReady = await worker.ready;
assert.strictEqual(workerReady.node_status, "ready");
assert.strictEqual(workerReady.mode, "worker");
const firstNodeTaskCompletion = waitForJsonLine(worker.child);
const { compileEvent, process: virtualProcess } = await launchFlagship(addr);
const workerCompletion = await firstNodeTaskCompletion;
assert.strictEqual(workerCompletion.node_status, "completed");
assert.strictEqual(
workerCompletion.task_assignment_response.task_spec.task_definition,
"prepare_source"
);
assert.strictEqual(
workerCompletion.virtual_thread,
workerCompletion.task_assignment_response.task_spec.task_instance
);
assert.strictEqual(compileEvent.status_code, 0);
assert.match(
compileEvent.artifact_path,
/^\/vfs\/artifacts\/hello-clusterflux-[0-9a-f]{64}$/
);
const artifact = compileEvent.artifact_path.slice("/vfs/artifacts/".length);
await reportNode(addr, sourceNode, sourceIdentity, {
artifacts: [artifact],
});
const receiverIdentity = nodeIdentity("artifact-export-smoke", "node-export-receiver");
const attachedReceiver = await send(addr, {
type: "attach_node",
tenant: "tenant",
project: "project",
node: "node-export-receiver",
public_key: receiverIdentity.publicKey,
});
assert.strictEqual(attachedReceiver.type, "node_attached");
await reportNode(addr, "node-export-receiver", receiverIdentity);
const exportPlan = await send(addr, {
type: "export_artifact_to_node",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact,
receiver_node: "node-export-receiver",
direct_connectivity: true,
failure_reason: "",
});
assert.strictEqual(exportPlan.type, "artifact_export_plan");
assert.strictEqual(exportPlan.source_node, "node-export-source");
assert.strictEqual(exportPlan.receiver_node, "node-export-receiver");
assert.strictEqual(exportPlan.plan.transport, "NativeQuic");
assert.strictEqual(exportPlan.plan.scope.tenant, "tenant");
assert.strictEqual(exportPlan.plan.scope.project, "project");
assert.strictEqual(exportPlan.plan.scope.process, virtualProcess);
assert.deepStrictEqual(exportPlan.plan.scope.object, { Artifact: artifact });
assert.strictEqual(exportPlan.plan.source.node, "node-export-source");
assert.strictEqual(exportPlan.plan.destination.node, "node-export-receiver");
assert.strictEqual(exportPlan.plan.coordinator_assisted_rendezvous, true);
assert.strictEqual(exportPlan.plan.coordinator_bulk_relay_allowed, false);
assert.match(exportPlan.plan.authorization_digest, /^sha256:[0-9a-f]{64}$/);
assert.strictEqual(exportPlan.artifact_size_bytes, compileEvent.artifact_size_bytes);
const temp = fs.mkdtempSync(path.join(os.tmpdir(), "clusterflux-artifact-export-"));
const exportPath = path.join(temp, "hello-clusterflux");
const cliExport = await runJson("cargo", [
"run",
"-q",
"-p",
"clusterflux-cli",
"--bin",
"clusterflux",
"--",
"artifact",
"export",
"--coordinator",
`${addr.host}:${addr.port}`,
"--tenant",
"tenant",
"--project-id",
"project",
"--user",
"user",
"--json",
artifact,
"--receiver-node",
"node-export-receiver",
"--to",
exportPath,
]);
assert.strictEqual(cliExport.command, "artifact export");
assert.strictEqual(cliExport.export_plan.local_bytes_written_by_cli, true);
assert.strictEqual(cliExport.export_plan.local_export_status, "local_bytes_written");
assert.strictEqual(
cliExport.export_plan.bytes_written,
compileEvent.artifact_size_bytes
);
assert.strictEqual(cliExport.local_export.stream.content_material_returned_in_report, false);
assert.strictEqual(
cliExport.local_export.verified_digest,
compileEvent.artifact_digest
);
fs.chmodSync(exportPath, 0o755);
assert.strictEqual(
cp.execFileSync(exportPath, { encoding: "utf8" }),
"hello from a real Clusterflux build\n"
);
const crossTenant = await send(addr, {
type: "export_artifact_to_node",
tenant: "other",
project: "project",
actor_user: "user",
artifact,
receiver_node: "node-export-receiver",
direct_connectivity: true,
failure_reason: "",
});
assert.strictEqual(crossTenant.type, "error");
assert.match(crossTenant.message, /tenant mismatch/);
await reportNode(addr, sourceNode, sourceIdentity, { artifacts: [artifact] });
const failedDirect = await send(addr, {
type: "export_artifact_to_node",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact,
receiver_node: "node-export-receiver",
direct_connectivity: false,
failure_reason: "nat traversal failed",
});
assert.strictEqual(failedDirect.type, "error");
assert.match(failedDirect.message, /nat traversal failed/);
assert.match(failedDirect.message, /coordinator bulk relay is disabled/);
await reportNode(addr, "node-export-receiver", receiverIdentity, { online: false });
await new Promise((resolve) => setTimeout(resolve, 2100));
await reportNode(addr, sourceNode, sourceIdentity, { artifacts: [artifact] });
const offlineReceiver = await send(addr, {
type: "export_artifact_to_node",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact,
receiver_node: "node-export-receiver",
direct_connectivity: true,
failure_reason: "",
});
assert.strictEqual(offlineReceiver.type, "error");
assert.match(offlineReceiver.message, /offline/);
} finally {
worker?.child.kill("SIGTERM");
coordinator.kill("SIGTERM");
}
console.log("Artifact export smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

23
scripts/check-code-size.sh Executable file
View file

@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
maximum_lines=3000
failed=0
while IFS= read -r -d '' file; do
case "$file" in
*/tests.rs|*/tests/*) continue ;;
esac
lines="$(wc -l < "$file")"
if ((lines > maximum_lines)); then
printf '%s has %s lines; production file limit is %s\n' "$file" "$lines" "$maximum_lines" >&2
failed=1
fi
done < <(find crates private/hosted-policy/src -type f -name '*.rs' -print0)
if ((failed)); then
exit 1
fi
printf 'production source file size guard passed (%s lines maximum)\n' "$maximum_lines"

113
scripts/check-docs.js Normal file
View file

@ -0,0 +1,113 @@
#!/usr/bin/env node
const fs = require("node:fs");
const path = require("node:path");
const root = path.resolve(__dirname, "..");
const publicDocs = [
"README.md",
"docs/getting-started.md",
"docs/architecture.md",
"docs/nodes.md",
"docs/environments.md",
"docs/artifacts.md",
"docs/debugging.md",
"docs/task-abi.md",
"docs/self-hosting.md",
"docs/security.md",
];
const privateDocs = [
"private/docs/hosted-deployment.md",
"private/docs/authentik.md",
"private/docs/community-policy.md",
"private/docs/bandwidth-and-cost-controls.md",
"private/docs/moderation.md",
"private/docs/publishing.md",
];
const internalDocs = ["internal/finish_mvp.md", "internal/release-status.md"];
const filteredPublicTree =
process.env.CLUSTERFLUX_FILTERED_PUBLIC_TREE === "1" ||
fs.existsSync(path.join(root, "CLUSTERFLUX_PUBLIC_TREE.json"));
const failures = [];
const expectExactMarkdownSet = (directory, expected) => {
const actual = fs
.readdirSync(path.join(root, directory), { withFileTypes: true })
.filter((entry) => entry.isFile() && entry.name.endsWith(".md"))
.map((entry) => path.posix.join(directory, entry.name))
.sort();
const wanted = [...expected].sort();
if (JSON.stringify(actual) !== JSON.stringify(wanted)) {
failures.push(`${directory} markdown set is ${actual.join(", ")}; expected ${wanted.join(", ")}`);
}
};
const requiredDocs = filteredPublicTree
? publicDocs
: [...publicDocs, ...privateDocs, ...internalDocs];
for (const file of requiredDocs) {
if (!fs.existsSync(path.join(root, file))) failures.push(`missing canonical document: ${file}`);
}
expectExactMarkdownSet("docs", publicDocs.filter((file) => file.startsWith("docs/")));
if (filteredPublicTree) {
for (const directory of ["private", "internal"]) {
if (fs.existsSync(path.join(root, directory))) {
failures.push(`${directory}/ must not exist in the filtered public tree`);
}
}
} else {
expectExactMarkdownSet("private/docs", privateDocs);
expectExactMarkdownSet("internal", internalDocs);
}
const forbidden = [
[/\bmvp\b/i, "internal milestone term"],
[/acceptance criteria/i, "internal gate language"],
[/release verification/i, "internal release language"],
[/public\/private source split/i, "source split narrative"],
[/founder|business decisions/i, "business planning narrative"],
[/hacker news|\bHN\b/, "launch-channel narrative"],
[/\busers can\b/i, "indirect reader wording"],
[/node\s+scripts\//i, "developer script instruction"],
[/scripts\/[^\s)]*smoke/i, "smoke script instruction"],
[/internal\/[^\s)]*/i, "internal tooling reference"],
];
const topLevelCommands = new Set([
"doctor", "login", "logout", "auth", "agent", "key", "project", "inspect",
"build", "bundle", "run", "node", "process", "task", "logs", "artifact",
"dap", "debug", "quota", "admin",
]);
for (const file of publicDocs) {
const absolute = path.join(root, file);
const content = fs.readFileSync(absolute, "utf8");
for (const [pattern, description] of forbidden) {
if (pattern.test(content)) failures.push(`${file}: contains ${description}`);
}
for (const match of content.matchAll(/\]\(([^)#]+)(?:#[^)]+)?\)/g)) {
const target = match[1];
if (/^(?:https?:|mailto:)/.test(target)) continue;
const resolved = path.resolve(path.dirname(absolute), target);
if (!fs.existsSync(resolved)) failures.push(`${file}: broken link ${target}`);
}
for (const line of content.split(/\r?\n/)) {
const command = line.trim().match(/^clusterflux\s+([a-z][a-z-]*)\b/);
if (command && !topLevelCommands.has(command[1])) {
failures.push(`${file}: unknown top-level CLI command ${command[1]}`);
}
}
}
const rootMarkdown = fs
.readdirSync(root, { withFileTypes: true })
.filter((entry) => entry.isFile() && entry.name.endsWith(".md"))
.map((entry) => entry.name)
.sort();
if (JSON.stringify(rootMarkdown) !== JSON.stringify(["README.md"])) {
failures.push(`top-level markdown set is ${rootMarkdown.join(", ")}; expected README.md`);
}
if (failures.length) {
for (const failure of failures) console.error(failure);
process.exit(1);
}
console.log("documentation checks passed");

39
scripts/check-old-name.sh Executable file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
legacy_lower="$(printf '%s%s' 'disa' 'smer')"
legacy_title="$(printf '%s%s' 'Disa' 'smer')"
legacy_upper="$(printf '%s%s' 'DISA' 'SMER')"
pattern="${legacy_lower}|${legacy_title}|${legacy_upper}"
allowed_content='^\./(internal/finish_mvp\.md|scripts/rename-to-clusterflux\.sh|scripts/migrate-clusterflux-state\.sh):'
matches="$(
rg -n --hidden \
--glob '!**/.git/**' \
--glob '!**/target/**' \
--glob '!**/node_modules/**' \
--glob '!**/vendor/**' \
--glob '!**/.direnv/**' \
--glob '!**/.cache/**' \
--glob '!**/dist/**' \
--glob '!**/out/**' \
"$pattern" . 2>/dev/null | rg -v "$allowed_content" || true
)"
paths="$(
find . \
\( -type d \( -name .git -o -name target -o -name node_modules -o -name vendor -o -name .direnv -o -name .cache -o -name dist -o -name out \) -prune \) -o \
-iname "*${legacy_lower}*" -print | sort || true
)"
if [[ -n "$matches" || -n "$paths" ]]; then
[[ -z "$matches" ]] || printf '%s\n' "$matches" >&2
[[ -z "$paths" ]] || printf '%s\n' "$paths" >&2
printf 'unexpected legacy product name remains\n' >&2
exit 1
fi
printf 'old-name guard passed\n'

View file

@ -0,0 +1,223 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const fs = require("fs");
const net = require("net");
const path = require("path");
const repo = path.resolve(__dirname, "..");
const tmp = path.join(repo, "target", "acceptance", "tmp", "cli-browser-login-flow");
const project = path.join(tmp, "project");
fs.rmSync(tmp, { recursive: true, force: true });
fs.mkdirSync(project, { recursive: true });
function writeOpener() {
const opener = path.join(tmp, "browser-opener.js");
const trace = path.join(tmp, "browser-opener.log");
fs.writeFileSync(
opener,
`#!/usr/bin/env node
const fs = require("fs");
const trace = ${JSON.stringify(trace)};
const loginUrl = new URL(process.argv[2]);
const state = loginUrl.searchParams.get("state");
const nonce = loginUrl.searchParams.get("nonce");
const challenge = loginUrl.searchParams.get("code_challenge");
if (loginUrl.protocol !== "https:" || !state || !nonce || !challenge) {
fs.appendFileSync(trace, "missing server-owned OIDC parameters\\n");
process.exit(1);
}
fs.appendFileSync(trace, "server-owned browser transaction\\n");
// Model a real browser/opener that remains alive after the CLI transaction.
// Its descriptors must not keep the invoking CLI process open.
setTimeout(() => process.exit(0), 5000);
`
);
fs.chmodSync(opener, 0o755);
return opener;
}
function startCoordinator() {
return new Promise((resolve, reject) => {
const requests = [];
const server = net.createServer((socket) => {
let buffered = "";
socket.on("data", (chunk) => {
buffered += chunk.toString("utf8");
while (buffered.includes("\n")) {
const newline = buffered.indexOf("\n");
const line = buffered.slice(0, newline);
buffered = buffered.slice(newline + 1);
const envelope = JSON.parse(line);
requests.push(envelope);
assert.strictEqual(envelope.type, "coordinator_request");
assert.strictEqual(envelope.protocol_version, 1);
assert.strictEqual(envelope.authentication.kind, "none");
const request = envelope.payload;
if (requests.length === 1) {
assert.strictEqual(envelope.request_id, "cli-1");
assert.strictEqual(envelope.operation, "begin_oidc_browser_login");
assert.deepStrictEqual(request, {
type: "begin_oidc_browser_login",
requested_project: "project-smoke",
});
socket.write(
`${JSON.stringify({
type: "oidc_browser_login_started",
transaction_id: "login-transaction",
polling_secret: "opaque-polling-secret",
authorization_url:
"https://auth.michelpaulissen.com/application/o/authorize/?state=server-state&nonce=server-nonce&code_challenge=server-pkce&code_challenge_method=S256&redirect_uri=https%3A%2F%2Fclusterflux.michelpaulissen.com%2Fauth%2Fcallback",
expires_at_epoch_seconds: 1800000000,
})}\n`
);
continue;
}
assert.strictEqual(envelope.request_id, "cli-2");
assert.strictEqual(envelope.operation, "poll_oidc_browser_login");
assert.deepStrictEqual(request, {
type: "poll_oidc_browser_login",
transaction_id: "login-transaction",
polling_secret: "opaque-polling-secret",
});
socket.end(
`${JSON.stringify({
type: "oidc_browser_session",
session: {
tenant: "tenant-smoke",
project: "project-smoke",
user: "user-smoke",
cli_session_credential_kind: "CliDeviceSession",
cli_session_secret: "scoped-cli-session-secret",
expires_at_epoch_seconds: 1800000000,
provider_tokens_sent_to_nodes: false,
},
})}\n`
);
server.close();
}
});
});
server.once("error", reject);
server.listen(0, "127.0.0.1", () => {
const address = server.address();
resolve({
url: `${address.address}:${address.port}`,
requests,
close: () =>
new Promise((closeResolve) => {
if (!server.listening) closeResolve();
else server.close(() => closeResolve());
}),
});
});
});
}
function runClusterflux(args, env) {
return new Promise((resolve, reject) => {
const child = cp.spawn(
"cargo",
[
"run",
"-q",
"--manifest-path",
path.join(repo, "Cargo.toml"),
"-p",
"clusterflux-cli",
"--bin",
"clusterflux",
"--",
...args,
],
{ cwd: project, env, stdio: ["ignore", "pipe", "pipe"] }
);
let stdout = "";
let stderr = "";
child.stdout.on("data", (chunk) => (stdout += chunk.toString("utf8")));
child.stderr.on("data", (chunk) => (stderr += chunk.toString("utf8")));
child.once("error", reject);
child.once("close", (code) => {
if (code === 0) resolve(stdout);
else reject(new Error(`clusterflux exited ${code}\n${stderr}\n${stdout}`));
});
});
}
(async () => {
const opener = writeOpener();
const coordinator = await startCoordinator();
try {
const loginStarted = Date.now();
const report = JSON.parse(
await runClusterflux(
[
"login",
"--browser",
"--json",
"--coordinator",
coordinator.url,
"--project-id",
"project-smoke",
],
{
...process.env,
CLUSTERFLUX_BROWSER_OPEN_COMMAND: opener,
CLUSTERFLUX_BROWSER_LOGIN_TIMEOUT_SECONDS: "5",
}
)
);
assert(
Date.now() - loginStarted < 3000,
"a long-lived browser opener must not keep CLI output pipes or login completion open"
);
assert.strictEqual(report.plan.coordinator, coordinator.url);
assert.strictEqual(report.boundary.cli_contacted_coordinator, true);
assert.strictEqual(report.boundary.scoped_cli_session_received, true);
assert.strictEqual(report.boundary.local_cli_session_file_written, true);
assert.strictEqual(report.boundary.provider_tokens_persisted_locally, false);
assert.strictEqual(report.boundary.provider_tokens_exposed_to_cli, false);
assert.strictEqual(report.boundary.provider_tokens_sent_to_nodes, false);
assert.strictEqual(report.boundary.coordinator_session_requests, 2);
assert.strictEqual(coordinator.requests.length, 2);
const sessionFile = path.join(project, ".clusterflux", "session.json");
const sessionText = fs.readFileSync(sessionFile, "utf8");
const session = JSON.parse(sessionText);
assert.strictEqual(session.kind, "human");
assert.strictEqual(session.coordinator, coordinator.url);
assert.strictEqual(session.tenant, "tenant-smoke");
assert.strictEqual(session.project, "project-smoke");
assert.strictEqual(session.user, "user-smoke");
assert.strictEqual(session.cli_session_credential_kind, "CliDeviceSession");
assert.strictEqual(session.token_expiry_posture, "expires_at");
assert.strictEqual(session.expires_at, "1800000000");
assert.strictEqual(session.provider_tokens_exposed_to_cli, false);
assert.strictEqual(session.provider_tokens_sent_to_nodes, false);
assert.doesNotMatch(
sessionText,
/access_token|refresh_token|id_token|provider-secret|authorization_code|Bearer/
);
const authStatus = JSON.parse(
await runClusterflux(["auth", "status", "--json"], process.env)
);
assert.strictEqual(authStatus.active_coordinator, coordinator.url);
assert.strictEqual(authStatus.principal, "user-smoke");
assert.strictEqual(authStatus.tenant, "tenant-smoke");
assert.strictEqual(authStatus.project, "project-smoke");
assert.strictEqual(authStatus.session.kind, "human");
assert.strictEqual(authStatus.session.source, "session_file");
assert.strictEqual(authStatus.session.provider_tokens_exposed_to_cli, false);
assert.strictEqual(authStatus.session.provider_tokens_exposed_to_nodes, false);
} finally {
await coordinator.close();
}
console.log("CLI browser login flow smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

365
scripts/cli-error-exit-smoke.js Executable file
View file

@ -0,0 +1,365 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const fs = require("fs");
const http = require("http");
const os = require("os");
const path = require("path");
const repo = path.resolve(__dirname, "..");
const project = path.join(repo, "examples/launch-build-demo");
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "clusterflux-cli-error-"));
function runClusterflux(args) {
return new Promise((resolve) => {
const child = cp.spawn(
"cargo",
["run", "-q", "-p", "clusterflux-cli", "--bin", "clusterflux", "--", ...args],
{
cwd: repo,
stdio: ["ignore", "pipe", "pipe"],
}
);
let stdout = "";
let stderr = "";
child.stdout.setEncoding("utf8");
child.stderr.setEncoding("utf8");
child.stdout.on("data", (chunk) => {
stdout += chunk;
});
child.stderr.on("data", (chunk) => {
stderr += chunk;
});
child.on("close", (code, signal) => {
resolve({ code, signal, stdout, stderr });
});
});
}
async function runWithOneCoordinatorResponse(buildArgs, response) {
let request = "";
const server = http.createServer((incoming, outgoing) => {
incoming.setEncoding("utf8");
incoming.on("data", (chunk) => {
request += chunk;
});
incoming.on("end", () => {
outgoing.writeHead(200, { "content-type": "application/json" });
outgoing.end(JSON.stringify(response));
server.close();
});
});
const address = await new Promise((resolve) => {
server.listen(0, "127.0.0.1", () => resolve(server.address()));
});
const coordinator = `http://${address.address}:${address.port}`;
const result = await runClusterflux(buildArgs(coordinator));
return { request, result };
}
async function main() {
const environmentProject = path.join(tempRoot, "missing-env-project");
fs.mkdirSync(path.join(environmentProject, "src"), { recursive: true });
fs.writeFileSync(
path.join(environmentProject, "Cargo.toml"),
"[package]\nname = \"missing-env-project\"\nversion = \"0.1.0\"\nedition = \"2021\"\n"
);
fs.writeFileSync(
path.join(environmentProject, "src", "main.rs"),
"fn main() { let _target = env!(\"linux\"); }\n"
);
const environmentFailure = await runClusterflux([
"build",
"--project",
environmentProject,
"--json",
]);
assert.strictEqual(environmentFailure.signal, null, environmentFailure.stderr);
assert.strictEqual(environmentFailure.code, 26, environmentFailure.stderr);
const environmentReport = JSON.parse(environmentFailure.stdout);
assert.strictEqual(environmentReport.status, "blocked_before_schedule");
assert.strictEqual(environmentReport.scheduled_work, false);
assert.strictEqual(environmentReport.machine_error.category, "environment");
assert.strictEqual(
environmentReport.machine_error.process_exit_code_applied,
true
);
assert(
environmentReport.machine_error.next_actions.includes("clusterflux inspect")
);
assert.strictEqual(environmentReport.diagnostics[0].code, "missing_environment");
const nonInteractive = await runClusterflux([
"run",
"build",
"--project",
project,
"--non-interactive",
"--json",
]);
assert.strictEqual(nonInteractive.signal, null, nonInteractive.stderr);
assert.strictEqual(nonInteractive.code, 20, nonInteractive.stderr);
assert.doesNotMatch(nonInteractive.stderr, /Opening Clusterflux browser login/);
const nonInteractiveReport = JSON.parse(nonInteractive.stdout);
assert.strictEqual(nonInteractiveReport.status, "authentication_required");
assert.strictEqual(nonInteractiveReport.non_interactive, true);
assert.strictEqual(nonInteractiveReport.browser_opened, false);
assert.strictEqual(nonInteractiveReport.machine_error.category, "authentication");
assert.strictEqual(nonInteractiveReport.machine_error.stable_exit_code, 20);
assert.strictEqual(
nonInteractiveReport.machine_error.process_exit_code_applied,
true
);
assert(
nonInteractiveReport.machine_error.next_actions.includes(
"pass --local to run against local services"
)
);
let request = "";
const server = http.createServer((incoming, outgoing) => {
incoming.setEncoding("utf8");
incoming.on("data", (chunk) => {
request += chunk;
});
incoming.on("end", () => {
outgoing.writeHead(200, { "content-type": "application/json" });
outgoing.end(
JSON.stringify({
type: "error",
message: "quota unavailable: resource limit exceeded for api_calls",
})
);
server.close();
});
});
const address = await new Promise((resolve) => {
server.listen(0, "127.0.0.1", () => resolve(server.address()));
});
const coordinator = `http://${address.address}:${address.port}`;
const result = await runClusterflux([
"run",
"build",
"--project",
project,
"--coordinator",
coordinator,
"--json",
]);
assert.strictEqual(result.signal, null, result.stderr);
assert.strictEqual(result.code, 22, result.stderr);
assert.match(request, /"type":"start_process"/);
const report = JSON.parse(result.stdout);
assert.strictEqual(report.status, "coordinator_rejected");
assert.strictEqual(report.run_start.machine_error.category, "quota");
assert.strictEqual(report.run_start.machine_error.resource_category, "api_calls");
assert.strictEqual(report.run_start.machine_error.community_tier_language, true);
assert.strictEqual(
report.run_start.machine_error.community_tier_label,
"community tier"
);
assert.doesNotMatch(result.stdout, new RegExp(["free", "tier"].join(" "), "i"));
assert.strictEqual(
report.run_start.machine_error.private_abuse_heuristics_exposed,
false
);
assert.strictEqual(report.run_start.machine_error.stable_exit_code, 22);
assert.strictEqual(
report.run_start.machine_error.process_exit_code_applied,
true
);
assert(
report.run_start.machine_error.next_actions.includes("clusterflux quota status")
);
const capabilityFailure = await runWithOneCoordinatorResponse(
(coordinator) => [
"run",
"build",
"--project",
project,
"--coordinator",
coordinator,
"--json",
],
{
type: "error",
message:
"scheduler placement failed: no capable node for placement: missing capability Command",
}
);
assert.strictEqual(capabilityFailure.result.signal, null, capabilityFailure.result.stderr);
assert.strictEqual(capabilityFailure.result.code, 24, capabilityFailure.result.stderr);
assert.match(capabilityFailure.request, /"type":"start_process"/);
const capabilityReport = JSON.parse(capabilityFailure.result.stdout);
assert.strictEqual(
capabilityReport.run_start.machine_error.category,
"capability"
);
assert.strictEqual(
capabilityReport.run_start.machine_error.process_exit_code_applied,
true
);
assert(
capabilityReport.run_start.machine_error.next_actions.includes(
"attach a node with the required capabilities"
)
);
const nodePolicyFailure = await runWithOneCoordinatorResponse(
(coordinator) => [
"run",
"build",
"--project",
project,
"--coordinator",
coordinator,
"--json",
],
{
type: "error",
message: "node policy denied native command execution",
}
);
assert.strictEqual(nodePolicyFailure.result.signal, null, nodePolicyFailure.result.stderr);
assert.strictEqual(nodePolicyFailure.result.code, 23, nodePolicyFailure.result.stderr);
assert.match(nodePolicyFailure.request, /"type":"start_process"/);
const nodePolicyReport = JSON.parse(nodePolicyFailure.result.stdout);
assert.strictEqual(
nodePolicyReport.run_start.machine_error.category,
"policy"
);
assert.strictEqual(
nodePolicyReport.run_start.machine_error.process_exit_code_applied,
true
);
assert(
nodePolicyReport.run_start.machine_error.next_actions.includes(
"check coordinator policy for this action"
)
);
const programFailure = await runWithOneCoordinatorResponse(
(coordinator) => [
"task",
"list",
"--coordinator",
coordinator,
"--json",
],
{
type: "task_events",
events: [
{
process: "vp-current",
task: "compile",
terminal_state: "failed",
environment: "linux",
node: "node-linux",
status_code: 1,
stderr_tail: "task exited with status 1",
},
],
}
);
assert.strictEqual(programFailure.result.signal, null, programFailure.result.stderr);
assert.strictEqual(programFailure.result.code, 0, programFailure.result.stderr);
assert.match(programFailure.request, /"type":"list_task_events"/);
const programReport = JSON.parse(programFailure.result.stdout);
assert.strictEqual(programReport.tasks[0].machine_error.category, "program");
assert.strictEqual(programReport.tasks[0].machine_error.stable_exit_code, 27);
assert(
programReport.tasks[0].machine_error.next_actions.includes("clusterflux logs")
);
const artifactDownload = await runWithOneCoordinatorResponse(
(coordinator) => [
"artifact",
"download",
"app.txt",
"--coordinator",
coordinator,
"--json",
],
{
type: "artifact_download_denied",
message: "artifact download unauthorized for project",
}
);
assert.strictEqual(artifactDownload.result.signal, null, artifactDownload.result.stderr);
assert.strictEqual(artifactDownload.result.code, 21, artifactDownload.result.stderr);
assert.match(artifactDownload.request, /"type":"create_artifact_download_link"/);
const artifactDownloadReport = JSON.parse(artifactDownload.result.stdout);
assert.strictEqual(
artifactDownloadReport.download_session.machine_error.category,
"authorization"
);
assert.strictEqual(
artifactDownloadReport.download_session.machine_error.process_exit_code_applied,
true
);
const artifactExport = await runWithOneCoordinatorResponse(
(coordinator) => [
"artifact",
"export",
"app.txt",
"--to",
path.join(project, "target", "blocked-artifact.txt"),
"--coordinator",
coordinator,
"--json",
],
{
type: "artifact_export_unavailable",
message: "direct connectivity unavailable for artifact export",
}
);
assert.strictEqual(artifactExport.result.signal, null, artifactExport.result.stderr);
assert.strictEqual(artifactExport.result.code, 25, artifactExport.result.stderr);
assert.match(artifactExport.request, /"type":"export_artifact_to_node"/);
const artifactExportReport = JSON.parse(artifactExport.result.stdout);
assert.strictEqual(
artifactExportReport.export_plan.machine_error.category,
"connectivity"
);
assert.strictEqual(
artifactExportReport.export_plan.machine_error.process_exit_code_applied,
true
);
const confirmation = await runClusterflux([
"process",
"cancel",
"--coordinator",
"127.0.0.1:9",
"--json",
]);
assert.strictEqual(confirmation.signal, null, confirmation.stderr);
assert.strictEqual(confirmation.code, 23, confirmation.stderr);
const confirmationReport = JSON.parse(confirmation.stdout);
assert.strictEqual(confirmationReport.status, "confirmation_required");
assert.strictEqual(confirmationReport.coordinator_request_sent, false);
assert.strictEqual(confirmationReport.machine_error.category, "policy");
assert.strictEqual(
confirmationReport.machine_error.process_exit_code_applied,
true
);
assert(
confirmationReport.next_actions.some((action) => action.includes("--yes"))
);
}
main()
.then(() => {
console.log("CLI error exit smoke passed");
})
.catch((error) => {
console.error(error);
process.exit(1);
});

File diff suppressed because it is too large Load diff

61
scripts/cli-install-smoke.js Executable file
View file

@ -0,0 +1,61 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const fs = require("fs");
const os = require("os");
const path = require("path");
const repo = path.resolve(__dirname, "..");
const temp = fs.mkdtempSync(path.join(os.tmpdir(), "clusterflux-cli-install-"));
const installRoot = path.join(temp, "install");
const targetDir =
process.env.CLUSTERFLUX_CLI_INSTALL_CARGO_TARGET_DIR ||
process.env.CARGO_TARGET_DIR ||
path.join(repo, "target");
const project = path.join(repo, "examples/launch-build-demo");
const binName = process.platform === "win32" ? "clusterflux.exe" : "clusterflux";
const installedBin = path.join(installRoot, "bin", binName);
try {
cp.execFileSync(
"cargo",
[
"install",
"--path",
"crates/clusterflux-cli",
"--bin",
"clusterflux",
"--root",
installRoot,
"--debug"
],
{
cwd: repo,
env: {
...process.env,
CARGO_TARGET_DIR: targetDir
},
stdio: "inherit"
}
);
assert(fs.existsSync(installedBin), "installed clusterflux binary must exist");
const inspection = JSON.parse(
cp.execFileSync(
installedBin,
["bundle", "inspect", "--project", project, "--json"],
{ cwd: repo, encoding: "utf8" }
)
);
assert.strictEqual(inspection.project, project);
assert.strictEqual(inspection.metadata.embeds_full_container_images, false);
assert(inspection.metadata.environments.some((env) => env.name === "linux"));
assert(inspection.metadata.selected_inputs.some((input) => input.path === "src/build.rs"));
} finally {
fs.rmSync(temp, { recursive: true, force: true });
}
console.log("CLI install smoke passed");

269
scripts/cli-local-run-smoke.js Executable file
View file

@ -0,0 +1,269 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const net = require("net");
const path = require("path");
const { coordinatorWireRequest } = require("./coordinator-wire");
const { configurePodmanTestEnvironment } = require("./podman-test-env");
const repo = path.resolve(__dirname, "..");
configurePodmanTestEnvironment(repo);
if (
!process.env.CLUSTERFLUX_PODMAN_NIX_SHELL &&
cp.spawnSync("podman", ["--version"], { stdio: "ignore" }).status !== 0 &&
cp.spawnSync("nix", ["--version"], { stdio: "ignore" }).status === 0
) {
cp.execFileSync(
"nix",
["shell", "nixpkgs#podman", "--command", "node", __filename],
{
cwd: repo,
env: {
...process.env,
CLUSTERFLUX_PODMAN_NIX_SHELL: "1",
},
stdio: "inherit",
}
);
process.exit(0);
}
const project = path.join(repo, "examples/launch-build-demo");
cp.execFileSync(
"cargo",
["build", "-q", "-p", "clusterflux-node", "--bin", "clusterflux-node"],
{ cwd: repo, stdio: "inherit" }
);
function waitForJsonLine(child) {
return new Promise((resolve, reject) => {
let buffer = "";
child.stdout.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
try {
resolve(JSON.parse(buffer.slice(0, newline).trim()));
} catch (error) {
reject(error);
}
});
child.once("exit", (code) => {
reject(new Error(`process exited before JSON line with code ${code}`));
});
});
}
function send(addr, message) {
return new Promise((resolve, reject) => {
const socket = net.connect(addr.port, addr.host, () => {
socket.write(`${JSON.stringify(coordinatorWireRequest(message))}\n`);
});
let buffer = "";
socket.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
socket.end();
try {
resolve(JSON.parse(buffer.slice(0, newline)));
} catch (error) {
reject(error);
}
});
socket.on("error", reject);
});
}
function runCli(args, env = {}) {
return new Promise((resolve, reject) => {
const child = cp.spawn(
"cargo",
["run", "-q", "-p", "clusterflux-cli", "--bin", "clusterflux", "--", ...args],
{
cwd: repo,
env: {
...process.env,
...env
}
}
);
const cliPid = child.pid;
let stdout = "";
let stderr = "";
child.stdout.on("data", (chunk) => {
stdout += chunk.toString();
});
child.stderr.on("data", (chunk) => {
stderr += chunk.toString();
});
child.on("exit", (code) => {
if (code !== 0) {
reject(new Error(`CLI run failed with code ${code}\n${stderr}`));
return;
}
try {
resolve({ pid: cliPid, report: JSON.parse(stdout) });
} catch (error) {
reject(new Error(`CLI output was not JSON: ${stdout}\n${error.stack || error.message}`));
}
});
});
}
(async () => {
const coordinator = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"--",
"--listen",
"127.0.0.1:0",
"--allow-local-trusted-loopback"
],
{ cwd: repo }
);
assert(Number.isInteger(coordinator.pid));
try {
const ready = await waitForJsonLine(coordinator);
const [host, portText] = ready.listen.split(":");
const addr = { host, port: Number(portText) };
assert.strictEqual((await send(addr, { type: "ping" })).type, "pong");
const { pid: cliPid, report } = await runCli([
"run",
"--coordinator",
`${addr.host}:${addr.port}`,
"--project",
project,
"--json",
]);
assert(Number.isInteger(cliPid));
assert.notStrictEqual(cliPid, coordinator.pid);
assert.strictEqual(report.plan.entry, "build");
assert.deepStrictEqual(report.plan.session, "Anonymous");
assert.strictEqual(report.boundary.cli_process_started_node_process, true);
assert.strictEqual(report.boundary.cli_process_started_coordinator_process, false);
assert(Number.isInteger(report.boundary.spawned_node_process_id));
assert.notStrictEqual(report.boundary.spawned_node_process_id, cliPid);
assert.notStrictEqual(report.boundary.spawned_node_process_id, coordinator.pid);
assert.strictEqual(report.boundary.node_session_requests, 0);
assert.strictEqual(report.node_report.node_status, "completed");
assert.strictEqual(report.node_report.execution_substrate, "wasm");
assert.strictEqual(report.node_report.task_spawn_host_import, true);
assert.strictEqual(
report.node_report.pre_node_process_status.processes.length,
1
);
assert.deepStrictEqual(
report.node_report.pre_node_process_status.processes[0].connected_nodes,
[]
);
assert.strictEqual(
report.node_report.pre_node_process_status.processes[0].main_state,
"running"
);
assert.strictEqual(
report.node_report.pre_node_process_status.processes[0].main_wait_state,
"waiting_for_node",
"the coordinator must expose that the capless main is parked on placement before a node exists"
);
assert.strictEqual(
report.node_report.pre_node_process_status.processes[0].main_task_instance,
report.node_report.run.task_instance
);
assert.strictEqual(report.node_report.run.status, "main_launched");
assert.strictEqual(report.node_report.join.type, "task_joined");
const process = report.node_report.run.process;
assert.strictEqual(process, "vp-current");
const events = await send(addr, {
type: "list_task_events",
tenant: "tenant",
project: "project",
actor_user: "user",
process
});
assert.strictEqual(events.type, "task_events");
assert(events.events.length >= 4);
assert(
events.events
.filter((event) => event.executor === "node")
.every((event) => event.node === "node-cli-local")
);
assert(
events.events.some(
(event) =>
event.executor === "coordinator_main" &&
event.node === "coordinator-main"
)
);
assert(events.events.every((event) => event.process === process));
assert.deepStrictEqual(
new Set(events.events.map((event) => event.task_definition)),
new Set([
report.node_report.run.task_definition,
"prepare_source",
"compile_linux",
"package_release",
])
);
assert.strictEqual(
new Set(events.events.map((event) => event.task)).size,
events.events.length,
"every live task event must retain its unique instance identity"
);
assert(
events.events.some(
(event) => event.task === report.node_report.run.task_instance
)
);
assert(events.events.some((event) => event.task.endsWith(":child:1")));
assert(events.events.some((event) => event.task.endsWith(":child:2")));
assert(events.events.some((event) => event.task.endsWith(":child:3")));
assert(events.events.some((event) => event.artifact_path));
} finally {
coordinator.kill("SIGTERM");
}
const { pid: autoCliPid, report: autoReport } = await runCli([
"run",
"--local",
"--project",
project,
"--json",
]);
assert(Number.isInteger(autoCliPid));
assert.strictEqual(autoReport.plan.entry, "build");
assert.deepStrictEqual(autoReport.plan.coordinator, "LocalOnly");
assert.deepStrictEqual(autoReport.plan.session, "Anonymous");
assert.strictEqual(autoReport.boundary.cli_process_started_node_process, true);
assert.strictEqual(autoReport.boundary.cli_process_started_coordinator_process, true);
assert.match(autoReport.boundary.coordinator_address, /^127\.0\.0\.1:\d+$/);
assert(Number.isInteger(autoReport.boundary.coordinator_process_id));
assert(Number.isInteger(autoReport.boundary.spawned_node_process_id));
assert.notStrictEqual(autoReport.boundary.coordinator_process_id, autoCliPid);
assert.notStrictEqual(autoReport.boundary.spawned_node_process_id, autoCliPid);
assert.notStrictEqual(
autoReport.boundary.spawned_node_process_id,
autoReport.boundary.coordinator_process_id
);
assert.strictEqual(autoReport.boundary.node_session_requests, 0);
assert.strictEqual(autoReport.node_report.node_status, "completed");
assert.strictEqual(autoReport.node_report.execution_substrate, "wasm");
assert.strictEqual(autoReport.node_report.task_spawn_host_import, true);
assert.strictEqual(autoReport.node_report.run.status, "main_launched");
assert.strictEqual(autoReport.node_report.join.type, "task_joined");
console.log("CLI local run smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

View file

@ -0,0 +1,72 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const path = require("path");
const repo = path.resolve(__dirname, "..");
const coordinator = "https://coord.example.test";
const defaultHostedCoordinatorEndpoint = "https://clusterflux.michelpaulissen.com";
function clusterflux(args) {
return JSON.parse(
cp.execFileSync(
"cargo",
["run", "-q", "-p", "clusterflux-cli", "--bin", "clusterflux", "--", ...args],
{ cwd: repo, encoding: "utf8" }
)
);
}
function clusterfluxRaw(args, env = {}) {
return cp.spawnSync(
"cargo",
["run", "-q", "-p", "clusterflux-cli", "--bin", "clusterflux", "--", ...args],
{
cwd: repo,
encoding: "utf8",
env: {
...process.env,
...env,
},
}
);
}
const browser = clusterflux(["login", "--plan", "--coordinator", coordinator, "--json"]);
assert.strictEqual(browser.coordinator, coordinator);
assert(browser.human_flow.Browser, "browser login should be available for human users");
assert.strictEqual(browser.human_flow.Browser.authorization_url, null);
assert.strictEqual(browser.human_flow.Browser.server_owns_state, true);
assert.strictEqual(browser.human_flow.Browser.server_owns_nonce, true);
assert.strictEqual(browser.human_flow.Browser.pkce_required, true);
assert.strictEqual(browser.human_flow.Browser.hosted_callback, true);
assert.strictEqual(browser.human_flow.Browser.cli_receives_provider_authorization_code, false);
assert.strictEqual(browser.human_flow.Browser.cli_submits_identity_claims, false);
const defaultBrowser = clusterflux(["login", "--plan", "--json"]);
assert.strictEqual(defaultBrowser.coordinator, defaultHostedCoordinatorEndpoint);
assert(defaultBrowser.human_flow.Browser);
const nonInteractiveBrowser = clusterfluxRaw(
["login", "--browser", "--non-interactive", "--coordinator", coordinator, "--json"],
{
CLUSTERFLUX_BROWSER_OPEN_COMMAND:
"node -e 'require(\"fs\").writeFileSync(\"/tmp/clusterflux-browser-should-not-open\", \"opened\")'",
}
);
assert.strictEqual(nonInteractiveBrowser.status, 20, nonInteractiveBrowser.stderr);
assert.doesNotMatch(nonInteractiveBrowser.stderr, /Opening Clusterflux browser login/);
const nonInteractiveReport = JSON.parse(nonInteractiveBrowser.stdout);
assert.strictEqual(nonInteractiveReport.status, "authentication_required");
assert.strictEqual(nonInteractiveReport.non_interactive, true);
assert.strictEqual(nonInteractiveReport.browser_opened, false);
assert.strictEqual(nonInteractiveReport.machine_error.category, "authentication");
assert.strictEqual(nonInteractiveReport.machine_error.stable_exit_code, 20);
assert(
nonInteractiveReport.machine_error.next_actions.includes(
"rerun without --non-interactive to open the browser"
)
);
console.log("CLI login smoke passed");

View file

@ -0,0 +1,183 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const fs = require("fs");
const os = require("os");
const path = require("path");
const repo = path.resolve(__dirname, "..");
const project = path.join(repo, "examples/launch-build-demo");
const isolatedCwd = fs.mkdtempSync(path.join(os.tmpdir(), "clusterflux-cli-output-"));
function clusterflux(args, env = {}, cwd = repo) {
return cp.execFileSync(
"cargo",
[
"run",
"-q",
"--manifest-path",
path.join(repo, "Cargo.toml"),
"-p",
"clusterflux-cli",
"--bin",
"clusterflux",
"--",
...args,
],
{
cwd,
encoding: "utf8",
env: {
...process.env,
...env,
},
}
);
}
function json(args, env, cwd) {
return JSON.parse(clusterflux(args, env, cwd));
}
function assertHuman(name, output, requiredPatterns) {
assert(
!output.trimStart().startsWith("{"),
`${name} default output should be human-readable text, not JSON`
);
for (const pattern of requiredPatterns) {
assert.match(output, pattern, `${name} human output missing ${pattern}`);
}
}
const helpHuman = clusterflux(["help"]);
assertHuman("help", helpHuman, [
/Primary workflow:/,
/clusterflux login --browser/,
/clusterflux project init/,
/clusterflux node attach; clusterflux-node --worker/,
/Clusterflux: Launch Virtual Process/,
/Hosted account creation happens in the browser login flow/,
/--json/,
]);
const loginHuman = clusterflux([
"login",
"--plan",
"--coordinator",
"https://coord.example.test",
]);
assertHuman("login", loginHuman, [
/Clusterflux login/,
/flow: browser/,
]);
const loginJson = json([
"login",
"--plan",
"--coordinator",
"https://coord.example.test",
"--json",
]);
assert.strictEqual(loginJson.coordinator, "https://coord.example.test");
assert(loginJson.human_flow.Browser);
assert.strictEqual(loginJson.human_flow.Browser.hosted_callback, true);
assert.strictEqual(loginJson.human_flow.Browser.cli_submits_identity_claims, false);
const doctorHuman = clusterflux(["doctor"]);
assertHuman("doctor", doctorHuman, [
/Clusterflux doctor/,
/coordinator reachability: not_configured/,
/dependencies:/,
/auth:/,
/node capabilities:/,
/node readiness: (ready_to_attach|local_dependencies_missing|limited_capabilities)/,
/node next:/,
]);
const doctorJson = json(["doctor", "--json"]);
assert.strictEqual(doctorJson.coordinator_reachability.checked, false);
assert.strictEqual(doctorJson.coordinator_reachability.status, "not_configured");
assert(
["ready_to_attach", "local_dependencies_missing", "limited_capabilities"].includes(
doctorJson.node_readiness_summary.status
)
);
assert.strictEqual(doctorJson.node_readiness_summary.explicit_attach_required, true);
assert.strictEqual(
doctorJson.node_readiness_summary.command_execution_capability,
true
);
assert(Array.isArray(doctorJson.node_readiness_summary.missing_local_dependencies));
assert(doctorJson.node_readiness_summary.next_actions.length >= 2);
const authJson = json(["auth", "status", "--json"], {
CLUSTERFLUX_TOKEN: "token",
CLUSTERFLUX_TOKEN_EXPIRES_AT: "2026-07-04T00:00:00Z",
}, isolatedCwd);
assert.strictEqual(authJson.session.kind, "human");
assert.strictEqual(authJson.session.token_expiry_posture, "expires_at");
assert.strictEqual(authJson.session.expires_at, "2026-07-04T00:00:00Z");
assert.strictEqual(authJson.coordinator_account_status.checked, false);
assert.strictEqual(authJson.coordinator_account_status.account_status, "unknown");
assert.strictEqual(
authJson.coordinator_account_status.private_moderation_details_exposed,
false
);
const inspectHuman = clusterflux(["bundle", "inspect", "--project", project]);
assertHuman("bundle inspect", inspectHuman, [
/Clusterflux bundle inspect/,
/bundle: sha256:/,
/environments:/,
]);
const inspectJson = json(["bundle", "inspect", "--project", project, "--json"]);
assert.strictEqual(inspectJson.project, project);
assert.match(inspectJson.metadata.identity, /^sha256:/);
assert.match(inspectJson.metadata.wasm_code, /^sha256:/);
assert.strictEqual(inspectJson.metadata.task_metadata.default_entrypoint, "build");
assert.deepStrictEqual(inspectJson.metadata.task_metadata.entrypoints, [
"build",
"fail",
"park-wake",
"restart",
]);
assert.strictEqual(
inspectJson.metadata.source_metadata.transfer_policy.coordinator_receives_source_bytes_by_default,
false
);
assert.strictEqual(
inspectJson.metadata.source_metadata.transfer_policy.default_full_repo_tarball,
false
);
assert.strictEqual(inspectJson.metadata.debug_metadata.dap_virtual_process, true);
assert.strictEqual(
inspectJson.metadata.large_input_policy.selected_inputs_are_content_digests,
true
);
assert.strictEqual(inspectJson.metadata.large_input_policy.selected_input_bytes_included, false);
assert.strictEqual(inspectJson.metadata.large_input_policy.full_repository_bytes_included, false);
assert.strictEqual(
inspectJson.metadata.large_input_policy.silent_task_argument_serialization,
false
);
assert(inspectJson.metadata.large_input_policy.supported_handle_types.includes("SourceSnapshot"));
assert.strictEqual(
inspectJson.metadata.restart_compatibility.source_edits_can_restart_from_clean_task_boundary,
true
);
assert.strictEqual(
inspectJson.metadata.restart_compatibility.requires_clean_checkpoint_boundary,
true
);
assert.strictEqual(
inspectJson.metadata.restart_compatibility.compares_task_abi,
inspectJson.metadata.task_metadata.task_abi
);
assert.strictEqual(
inspectJson.metadata.restart_compatibility.incompatible_changes_require_whole_process_restart,
true
);
console.log("CLI output mode smoke passed");

View file

@ -0,0 +1,43 @@
let requestId = 0;
function coordinatorWireRequest(payload, prefix = "acceptance") {
if (payload && payload.type === "coordinator_request") return payload;
if (!payload || typeof payload.type !== "string" || !payload.type.trim()) {
throw new Error("coordinator payload must have a non-empty type");
}
requestId += 1;
return {
type: "coordinator_request",
protocol_version: 1,
request_id: `${prefix}-${process.pid}-${requestId}`,
operation: payload.type,
authentication: authenticationMetadata(payload),
payload,
};
}
function authenticationMetadata(payload) {
if (payload.type === "authenticated") {
return {
kind: "cli_session",
session: true,
request_operation: payload.request?.type || "unknown",
};
}
if (payload.type === "signed_node" || payload.node_signature) {
return { kind: "node_signature", node: payload.node || null };
}
if (payload.agent_signature) {
return {
kind: "agent_signature",
agent: payload.actor_agent || null,
fingerprint: payload.agent_public_key_fingerprint || null,
};
}
if (payload.admin_token) {
return { kind: "admin_credential" };
}
return { kind: "none" };
}
module.exports = { coordinatorWireRequest };

132
scripts/dap-client.js Normal file
View file

@ -0,0 +1,132 @@
const cp = require("child_process");
class DapClient {
constructor({
cwd = process.cwd(),
env = process.env,
command = "cargo",
args = [
"run",
"-q",
"-p",
"clusterflux-dap",
"--bin",
"clusterflux-debug-dap",
],
} = {}) {
this.child = cp.spawn(
command,
args,
{ cwd, env }
);
this.seq = 1;
this.buffer = Buffer.alloc(0);
this.messages = [];
this.waiters = [];
this.stderr = "";
this.child.stdout.on("data", (chunk) => {
this.buffer = Buffer.concat([this.buffer, chunk]);
this.parse();
});
this.child.stderr.on("data", (chunk) => {
this.stderr += chunk.toString();
});
this.child.on("exit", () => this.flushWaiters());
}
send(command, args = {}) {
const seq = this.seq++;
const message = { seq, type: "request", command, arguments: args };
const payload = Buffer.from(JSON.stringify(message));
this.child.stdin.write(`Content-Length: ${payload.length}\r\n\r\n`);
this.child.stdin.write(payload);
return seq;
}
async response(seq, command) {
const message = await this.waitFor(
(item) =>
item.type === "response" &&
item.request_seq === seq &&
item.command === command
);
if (!message.success) {
throw new Error(
`DAP ${command} failed: ${message.message || JSON.stringify(message)}\nAdapter stderr:\n${this.stderr}`
);
}
return message;
}
async failure(seq, command) {
const message = await this.waitFor(
(item) =>
item.type === "response" &&
item.request_seq === seq &&
item.command === command
);
if (message.success) {
throw new Error(`DAP ${command} unexpectedly succeeded`);
}
return message;
}
waitFor(predicate, timeoutMs = 120000) {
const existing = this.messages.find(predicate);
if (existing) return Promise.resolve(existing);
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
this.child.kill("SIGKILL");
const recent = this.messages
.slice(-10)
.map((message) => JSON.stringify(message))
.join("\n");
reject(
new Error(
`timed out waiting for DAP message\nRecent DAP messages:\n${recent}\nAdapter stderr:\n${this.stderr}`
)
);
}, timeoutMs);
this.waiters.push({ predicate, resolve, timer });
});
}
parse() {
while (true) {
const headerEnd = this.buffer.indexOf("\r\n\r\n");
if (headerEnd < 0) return;
const header = this.buffer.slice(0, headerEnd).toString();
const match = header.match(/Content-Length: (\d+)/i);
if (!match) throw new Error(`bad DAP header: ${header}`);
const length = Number(match[1]);
const start = headerEnd + 4;
const end = start + length;
if (this.buffer.length < end) return;
const payload = this.buffer.slice(start, end).toString();
this.buffer = this.buffer.slice(end);
this.messages.push(JSON.parse(payload));
this.flushWaiters();
}
}
flushWaiters() {
for (const waiter of [...this.waiters]) {
const message = this.messages.find(waiter.predicate);
if (!message) continue;
clearTimeout(waiter.timer);
this.waiters.splice(this.waiters.indexOf(waiter), 1);
waiter.resolve(message);
}
}
async close() {
if (this.child.exitCode !== null) return;
const seq = this.send("disconnect");
await this.response(seq, "disconnect");
this.child.stdin.end();
}
}
module.exports = { DapClient };

363
scripts/dap-smoke.js Normal file
View file

@ -0,0 +1,363 @@
#!/usr/bin/env node
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const { DapClient } = require("./dap-client");
(async () => {
const repo = path.resolve(__dirname, "..");
const project = path.join(repo, "examples/launch-build-demo");
const sourcePath = fs.realpathSync(path.join(project, "src/build.rs"));
const sourceLines = fs.readFileSync(sourcePath, "utf8").split(/\r?\n/);
const buildMainLine =
sourceLines.findIndex((line) => line.includes("pub async fn build_main()")) + 1;
assert(buildMainLine > 0, "flagship source must contain build_main");
const client = new DapClient();
try {
const initialize = client.send("initialize", {
adapterID: "clusterflux",
linesStartAt1: true,
columnsStartAt1: true,
});
await client.response(initialize, "initialize");
const launch = client.send("launch", {
entry: "build",
project,
runtimeBackend: "local-services",
});
await client.response(launch, "launch");
await client.waitFor(
(message) => message.type === "event" && message.event === "initialized"
);
const breakpoints = client.send("setBreakpoints", {
source: { path: sourcePath },
breakpoints: [{ line: buildMainLine }],
});
const breakpointResponse = await client.response(
breakpoints,
"setBreakpoints"
);
assert.strictEqual(breakpointResponse.body.breakpoints.length, 1);
assert.strictEqual(breakpointResponse.body.breakpoints[0].verified, true);
const configurationDone = client.send("configurationDone");
await client.response(configurationDone, "configurationDone");
const stopped = await client.waitFor(
(message) =>
message.type === "event" &&
message.event === "stopped" &&
message.body.reason === "breakpoint"
);
assert.strictEqual(stopped.body.allThreadsStopped, true);
assert.match(stopped.body.description, /confirmed by every active participant/i);
const threadsRequest = client.send("threads");
const threads = (await client.response(threadsRequest, "threads")).body
.threads;
const mainThread = threads.find((thread) =>
thread.name.includes("build coordinator main")
);
assert(mainThread, "the running Wasm entrypoint must be the DAP coordinator-main thread");
assert.strictEqual(stopped.body.threadId, mainThread.id);
const stackRequest = client.send("stackTrace", {
threadId: mainThread.id,
startFrame: 0,
levels: 1,
});
const stack = (await client.response(stackRequest, "stackTrace")).body
.stackFrames;
assert.strictEqual(stack.length, 1);
assert.strictEqual(stack[0].line, buildMainLine);
assert.strictEqual(stack[0].source.path, sourcePath);
assert.match(stack[0].name, /build_main::wasm/);
assert.doesNotMatch(stack[0].name, /podman|cmd\.exe|powershell|pid|native child/i);
const sourceRequest = client.send("source", { source: stack[0].source });
const source = (await client.response(sourceRequest, "source")).body;
assert.match(source.content, /build_main/);
assert.match(source.mimeType, /rust/);
const scopesRequest = client.send("scopes", { frameId: stack[0].id });
const scopes = (await client.response(scopesRequest, "scopes")).body.scopes;
const localsScope = scopes.find((scope) => scope.name === "Source Locals");
const wasmScope = scopes.find((scope) => scope.name === "Wasm Frame Locals");
const argsScope = scopes.find(
(scope) => scope.name === "Task Args and Handles"
);
const runtimeScope = scopes.find(
(scope) => scope.name === "Clusterflux Runtime"
);
assert(localsScope && wasmScope && argsScope && runtimeScope);
const localsRequest = client.send("variables", {
variablesReference: localsScope.variablesReference,
});
const locals = (await client.response(localsRequest, "variables")).body
.variables;
assert(
locals.some(
(variable) =>
variable.name === "unavailable-local-diagnostic" &&
String(variable.value).includes("cannot be inspected")
)
);
const wasmRequest = client.send("variables", {
variablesReference: wasmScope.variablesReference,
});
const wasmLocals = (await client.response(wasmRequest, "variables")).body
.variables;
assert.deepStrictEqual(
wasmLocals.map((variable) => variable.name),
["wasm-local-diagnostic"]
);
assert.match(wasmLocals[0].value, /did not report inspectable Wasm frame locals/);
const argsRequest = client.send("variables", {
variablesReference: argsScope.variablesReference,
});
const args = (await client.response(argsRequest, "variables")).body.variables;
assert.deepStrictEqual(
args.map((variable) => variable.name),
["runtime-boundary-diagnostic"]
);
assert.match(args[0].value, /reported no task arguments or handles/);
const runtimeRequest = client.send("variables", {
variablesReference: runtimeScope.variablesReference,
});
const runtime = (await client.response(runtimeRequest, "variables")).body
.variables;
const value = (name) => runtime.find((variable) => variable.name === name)?.value;
assert.strictEqual(value("runtime_backend"), "LocalServices");
assert.strictEqual(value("state"), "Frozen");
assert.strictEqual(value("debug_epoch"), 1);
assert.strictEqual(value("coordinator_task_events"), 0);
assert.match(
String(value("command_status")),
/frozen through local services at executing Wasm probe/
);
const step = client.send("next", { threadId: mainThread.id });
const stepFailure = await client.failure(step, "next");
assert.match(stepFailure.message, /source stepping is not yet available/i);
assert.match(stepFailure.message, /synthetic step/i);
const restart = client.send("restartFrame", { frameId: stack[0].id });
const restartFailure = await client.failure(restart, "restartFrame");
assert.match(restartFailure.message, /checkpoint boundary|still active/i);
const incompatibleRestart = client.send("restartFrame", {
frameId: stack[0].id,
sourceCompatibility: "incompatible",
});
const incompatibleFailure = await client.failure(
incompatibleRestart,
"restartFrame"
);
assert.match(incompatibleFailure.message, /incompatible source edit/i);
assert.match(incompatibleFailure.message, /whole virtual-process restart/i);
await client.close();
} catch (error) {
if (client.child.exitCode === null) client.child.kill("SIGKILL");
throw error;
}
const failMainLine =
sourceLines.findIndex((line) => line.includes("pub async fn fail_main()")) + 1;
assert(failMainLine > 0, "flagship source must contain fail_main");
const taskTrapLine =
sourceLines.findIndex((line) => line.includes("fn task_trap(")) + 1;
assert(taskTrapLine > 0, "flagship source must contain task_trap");
const restartClient = new DapClient();
try {
const initialize = restartClient.send("initialize", {
adapterID: "clusterflux",
linesStartAt1: true,
columnsStartAt1: true,
});
await restartClient.response(initialize, "initialize");
const launch = restartClient.send("launch", {
entry: "fail",
project,
runtimeBackend: "local-services",
});
await restartClient.response(launch, "launch");
await restartClient.waitFor(
(message) => message.type === "event" && message.event === "initialized"
);
const breakpoints = restartClient.send("setBreakpoints", {
source: { path: sourcePath },
breakpoints: [{ line: failMainLine }, { line: taskTrapLine }],
});
const breakpointResponse = await restartClient.response(
breakpoints,
"setBreakpoints"
);
assert.deepStrictEqual(
breakpointResponse.body.breakpoints.map((breakpoint) => breakpoint.verified),
[true, true]
);
const configurationDone = restartClient.send("configurationDone");
await restartClient.response(configurationDone, "configurationDone");
const initialStop = await restartClient.waitFor(
(message) =>
message.type === "event" &&
message.event === "stopped" &&
message.body.reason === "breakpoint"
);
assert.strictEqual(initialStop.body.allThreadsStopped, true);
const threadsRequest = restartClient.send("threads");
const threads = (
await restartClient.response(threadsRequest, "threads")
).body.threads;
const failThread = threads.find(
(thread) => thread.id === initialStop.body.threadId
);
assert(failThread, "failed entrypoint must remain a virtual task thread");
const stackRequest = restartClient.send("stackTrace", {
threadId: failThread.id,
startFrame: 0,
levels: 1,
});
const failedStack = (
await restartClient.response(stackRequest, "stackTrace")
).body.stackFrames;
assert.strictEqual(failedStack[0].line, failMainLine);
const continueRequest = restartClient.send("continue", {
threadId: failThread.id,
});
await restartClient.response(continueRequest, "continue");
const childStop = await restartClient.waitFor(
(message) =>
message.seq > initialStop.seq &&
message.type === "event" &&
message.event === "stopped" &&
message.body.reason === "breakpoint",
70000
);
assert.strictEqual(childStop.body.allThreadsStopped, true);
const childThreadsRequest = restartClient.send("threads");
const childThreads = (
await restartClient.response(childThreadsRequest, "threads")
).body.threads;
const childThread = childThreads.find(
(thread) => thread.id === childStop.body.threadId
);
assert(childThread, "executing child task must become a DAP virtual thread");
assert.notStrictEqual(childThread.id, failThread.id);
assert.match(childThread.name, /task trap/i);
const childStackRequest = restartClient.send("stackTrace", {
threadId: childThread.id,
startFrame: 0,
levels: 1,
});
const childStack = (
await restartClient.response(childStackRequest, "stackTrace")
).body.stackFrames;
assert.strictEqual(childStack[0].line, taskTrapLine);
assert.match(childStack[0].name, /task_trap::wasm/);
const childScopesRequest = restartClient.send("scopes", {
frameId: childStack[0].id,
});
const childScopes = (
await restartClient.response(childScopesRequest, "scopes")
).body.scopes;
const childArgsScope = childScopes.find(
(scope) => scope.name === "Task Args and Handles"
);
assert(childArgsScope, "child task argument scope must be present");
const childArgsRequest = restartClient.send("variables", {
variablesReference: childArgsScope.variablesReference,
});
const childArgs = (
await restartClient.response(childArgsRequest, "variables")
).body.variables;
assert(
childArgs.some(
(variable) =>
variable.name === "arg_0" &&
/SmallJson\(Number\(0\)\)/.test(String(variable.value))
),
"child task argument must come from the frozen node participant"
);
const parentScopesRequest = restartClient.send("scopes", {
frameId: failedStack[0].id,
});
const parentScopes = (
await restartClient.response(parentScopesRequest, "scopes")
).body.scopes;
const parentArgsScope = parentScopes.find(
(scope) => scope.name === "Task Args and Handles"
);
const parentArgsRequest = restartClient.send("variables", {
variablesReference: parentArgsScope.variablesReference,
});
const parentArgs = (
await restartClient.response(parentArgsRequest, "variables")
).body.variables;
assert(
parentArgs.some(
(variable) =>
/^task_handle_\d+$/.test(variable.name) &&
/definition=task_trap instance=ti:.*:child:\d+ state=active/.test(
variable.value
) &&
variable.type === "runtime-handle"
),
"parent task handle must come from its live Wasm host registry"
);
const continueChildRequest = restartClient.send("continue", {
threadId: childThread.id,
});
await restartClient.response(continueChildRequest, "continue");
await restartClient.waitFor(
(message) =>
message.seq > childStop.seq &&
message.type === "event" &&
message.event === "terminated"
);
const restartRequest = restartClient.send("restartFrame", {
frameId: failedStack[0].id,
});
await restartClient.response(restartRequest, "restartFrame");
const restartedStop = await restartClient.waitFor(
(message) =>
message.type === "event" &&
message.event === "stopped" &&
/Restarted main from the rebuilt bundle/.test(message.body.description)
);
assert.strictEqual(restartedStop.body.allThreadsStopped, true);
const restartedStackRequest = restartClient.send("stackTrace", {
threadId: restartedStop.body.threadId,
startFrame: 0,
levels: 1,
});
const restartedStack = (
await restartClient.response(restartedStackRequest, "stackTrace")
).body.stackFrames;
assert.strictEqual(restartedStack[0].line, failMainLine);
await restartClient.close();
} catch (error) {
if (restartClient.child.exitCode === null) restartClient.child.kill("SIGKILL");
throw error;
}
console.log("DAP smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

View file

@ -0,0 +1,148 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const crypto = require("crypto");
const fs = require("fs");
const path = require("path");
const extension = require("../vscode-extension/extension");
const repo = path.resolve(__dirname, "..");
const project = path.join(repo, "examples/launch-build-demo");
const source = fs.readFileSync(path.join(project, "src/build.rs"), "utf8");
const forbiddenSourceAssumptions =
/\b(?:std::fs|std::process|git|podman|docker|localhost|127\.0\.0\.1)|\/home\/|\/Users\/|C:\\Users\\/i;
const envs = extension.discoverEnvironmentNames(project);
assert.deepStrictEqual(envs, ["linux", "windows"]);
assert.deepStrictEqual(extension.diagnoseEnvReferences(source, envs), []);
assert.doesNotMatch(
source,
forbiddenSourceAssumptions,
"flagship build source must not bypass Clusterflux host capabilities or rely on coordinator-side filesystem, Git, container, or machine-local assumptions"
);
const inspection = JSON.parse(
cp.execFileSync(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-cli",
"--bin",
"clusterflux",
"--",
"bundle",
"inspect",
"--project",
project,
"--json"
],
{ cwd: repo, encoding: "utf8" }
)
);
assert.strictEqual(inspection.project, project);
assert.strictEqual(
inspection.source_provider_manifest.coordinator_requires_checkout_access,
false
);
assert.strictEqual(
inspection.source_provider_manifest.transfer_policy.local_source_bytes_remain_node_local,
true
);
assert.strictEqual(
inspection.source_provider_manifest.transfer_policy.coordinator_receives_source_bytes_by_default,
false
);
assert.strictEqual(
inspection.source_provider_manifest.transfer_policy.default_full_repo_tarball,
false
);
assert.deepStrictEqual(
inspection.source_provider_manifest.transfer_policy.allowed_remote_transfer.sort(),
["ExplicitSnapshotChunks", "RequiredContent"]
);
assert.strictEqual(inspection.metadata.embeds_full_container_images, false);
assert(inspection.metadata.environments.some((env) => env.name === "linux"));
assert(inspection.metadata.environments.some((env) => env.name === "windows"));
assert(inspection.metadata.selected_inputs.some((input) => input.path === "src/build.rs"));
const bundleDirectory = path.join(repo, "target/acceptance/flagship-bundle");
const build = JSON.parse(
cp.execFileSync(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-cli",
"--bin",
"clusterflux",
"--",
"build",
"--project",
project,
"--output",
bundleDirectory,
"--json",
],
{ cwd: repo, encoding: "utf8" }
)
);
assert.strictEqual(build.status, "built");
assert.strictEqual(build.bundle_artifact.task_descriptor_count, 9);
assert.strictEqual(build.bundle_artifact.entrypoint_count, 4);
assert.deepStrictEqual(build.bundle_artifact.files.sort(), [
"debug-metadata.json",
"entrypoints.json",
"environments.json",
"manifest.json",
"module.wasm",
"source-provider.json",
"task-descriptors.json",
"vfs-seed.json",
]);
const bundleManifest = JSON.parse(
fs.readFileSync(path.join(bundleDirectory, "manifest.json"), "utf8")
);
const bundleEntrypoints = JSON.parse(
fs.readFileSync(path.join(bundleDirectory, "entrypoints.json"), "utf8")
);
assert.deepStrictEqual(
bundleEntrypoints.map((entrypoint) => entrypoint.name).sort(),
["build", "fail", "park-wake", "restart"]
);
const bundleModule = fs.readFileSync(path.join(bundleDirectory, "module.wasm"));
assert.strictEqual(bundleManifest.kind, "clusterflux-bundle");
assert.strictEqual(
bundleManifest.bundle_digest,
`sha256:${crypto.createHash("sha256").update(bundleModule).digest("hex")}`
);
assert.strictEqual(bundleManifest.embeds_full_repository, false);
assert.strictEqual(
bundleManifest.coordinator_receives_source_bytes_by_default,
false
);
const taskDescriptors = JSON.parse(
fs.readFileSync(path.join(bundleDirectory, "task-descriptors.json"), "utf8")
);
assert(
taskDescriptors.some(
(task) =>
task.name === "task_add_one" &&
task.argument_schema === "input : i32" &&
task.result_schema === "i32" &&
task.restart_compatibility_hash.startsWith("sha256:") &&
task.probe_symbol === "clusterflux.probe.task_add_one"
)
);
cp.execFileSync("cargo", ["test", "-p", "launch-build-demo"], {
cwd: repo,
stdio: "inherit"
});
console.log("Flagship demo smoke passed");

View file

@ -0,0 +1,184 @@
#!/usr/bin/env node
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const repo = path.resolve(__dirname, "..");
function read(relativePath) {
return fs.readFileSync(path.join(repo, relativePath), "utf8");
}
function maybeRead(segments) {
const fullPath = path.join(repo, ...segments);
if (!fs.existsSync(fullPath)) return null;
return fs.readFileSync(fullPath, "utf8");
}
function expect(source, name, pattern) {
assert.match(source, pattern, `missing hostile-input evidence: ${name}`);
}
const coreSource = read("crates/clusterflux-core/src/source.rs");
const coreCapabilities = read("crates/clusterflux-core/src/capability.rs");
const coordinatorService = [
read("crates/clusterflux-coordinator/src/service.rs"),
read("crates/clusterflux-coordinator/src/service/routing.rs"),
read("crates/clusterflux-coordinator/src/service/signed_nodes.rs"),
read("crates/clusterflux-coordinator/src/service/logs.rs"),
read("crates/clusterflux-coordinator/src/service/tests.rs"),
].join("\n");
const artifactDownloadSmoke = read("scripts/artifact-download-smoke.js");
const operatorPanelSmoke = read("scripts/operator-panel-smoke.js");
const schedulerSmoke = read("scripts/scheduler-placement-smoke.js");
const sourcePreparationSmoke = read("scripts/source-preparation-smoke.js");
for (const [name, pattern] of [
["source manifests validate shape", /pub fn validate_public_mvp\(&self\)[\s\S]*self\.validate_shape\(\)\?/],
["source manifests reject invalid digests", /SourceManifestError::InvalidDigest/],
["source manifests reject invalid custom providers", /SourceManifestError::InvalidProviderId/],
["source manifests reject control characters", /DescriptionControlCharacter/],
["source manifests reject coordinator checkout access", /CoordinatorCheckoutAccess/],
["source manifests reject default source-byte upload", /CoordinatorReceivesSourceBytes/],
]) {
expect(coreSource, name, pattern);
}
for (const [name, pattern] of [
["capability reports validate public shape", /pub fn validate_public_report\(&self\)/],
["capability reports validate architecture labels", /InvalidArchitecture/],
["capability reports validate OS labels", /InvalidOsLabel/],
["capability reports validate source providers", /InvalidSourceProvider/],
["source provider ids reject path traversal", /valid_source_provider_id/],
]) {
expect(coreCapabilities, name, pattern);
}
for (const [name, pattern] of [
["coordinator task log tails are bounded", /MAX_TASK_LOG_TAIL_BYTES: usize = 256 \* 1024/],
["coordinator validates reported stdout tails", /ReportTaskLog[\s\S]*validate_task_log_tail\("stdout_tail", &stdout_tail\)\?/],
["coordinator validates completed task stdout tails", /TaskCompleted[\s\S]*validate_task_log_tail\("stdout_tail", &stdout_tail\)\?/],
["coordinator rejects oversized log tail in unit coverage", /"x"\.repeat\(MAX_TASK_LOG_TAIL_BYTES \+ 1\)/],
]) {
expect(coordinatorService, name, pattern);
}
for (const [name, pattern] of [
["service rejects malformed node capability report", /fn service_rejects_malformed_node_capability_report\(\)/],
["capability report rejection leaves descriptors empty", /assert!\(service\.node_descriptors\.is_empty\(\)\)/],
["node capability report rejects cross-scope writes", /fn service_rejects_node_capability_report_outside_enrollment_scope\(\)/],
["task completion rejects cross-scope writes", /task completion outside node scope|outside/],
]) {
expect(coordinatorService, name, pattern);
}
for (const [name, source, patterns] of [
[
"artifact download smoke",
artifactDownloadSmoke,
[
/const crossTenant = await send/,
/const crossProject = await send/,
/const guessed = await send/,
/const crossActorOpen = await send/,
/token is invalid/,
/tenant mismatch/,
/project mismatch/,
],
],
[
"operator panel smoke",
operatorPanelSmoke,
[
/render_operator_panel/,
/submit_panel_event/,
/assert\(!JSON\.stringify\(panel\)\.includes\("<script"\)\)/,
/assert\(!JSON\.stringify\(panel\)\.toLowerCase\(\)\.includes\("oauth"\)\)/,
/rate limit/i,
/exceeds download limit/,
],
],
[
"scheduler smoke",
schedulerSmoke,
[/const crossTenantReport = await send/, /report_node_capabilities/, /tenant\\\/project scope/],
],
[
"source preparation smoke",
sourcePreparationSmoke,
[/const crossTenantCompletion = await send/, /complete_source_preparation/, /tenant\\\/project scope/i],
],
]) {
for (const pattern of patterns) {
expect(source, name, pattern);
}
}
const hostedServiceMain = maybeRead([
"private",
"hosted-policy",
"src",
"bin",
"clusterflux-hosted-service.rs",
]);
const hostedValidation = maybeRead([
"private",
"hosted-policy",
"src",
"bin",
"clusterflux-hosted-service",
"validation.rs",
]);
const hostedWire = maybeRead([
"private",
"hosted-policy",
"src",
"bin",
"clusterflux-hosted-service",
"wire.rs",
]);
const hostedProtocol = maybeRead([
"private",
"hosted-policy",
"src",
"bin",
"clusterflux-hosted-service",
"hosted_service_protocol.rs",
]);
const hostedService =
hostedServiceMain && hostedValidation && hostedWire && hostedProtocol
? [hostedServiceMain, hostedValidation, hostedWire, hostedProtocol].join("\n")
: null;
const hostedTests = [
maybeRead(["private", "hosted-policy", "src", "bin", "clusterflux-hosted-service", "tests.rs"]),
maybeRead(["private", "hosted-policy", "scripts", "hosted-deployment-smoke.js"]),
maybeRead(["private", "hosted-policy", "scripts", "hosted-client-compat-smoke.js"]),
].filter(Boolean).join("\n");
if (hostedService && hostedTests) {
for (const [name, pattern] of [
["hosted service turns malformed JSON into error responses", /decode_incoming_request[\s\S]*HostedServiceResponse::Error/],
["tenant ids are validated", /fn tenant_id\(value: String\)[\s\S]*validate_identifier\("tenant", &value\)\?/],
["node ids are validated", /fn node_id\(value: String\)[\s\S]*validate_identifier\("node", &value\)\?/],
["process ids are validated", /fn process_id\(value: String\)[\s\S]*validate_identifier\("process", &value\)\?/],
["identifiers reject empty and control/path characters", /fn validate_identifier[\s\S]*trim\(\)\.is_empty\(\)[\s\S]*ch\.is_control\(\) \|\| ch == '\/' \|\| ch == '\\\\'/],
["OIDC text fields are bounded", /fn validate_text[\s\S]*value\.len\(\) > max_bytes[\s\S]*contains unsupported characters/],
["tokens are bounded", /fn validate_token[\s\S]*value\.len\(\) > max_bytes[\s\S]*contains unsupported characters/],
["control request bodies are bounded", /MAX_CONTROL_FRAME_BYTES[\s\S]*control request too large/],
["identity protocol rejects unknown authority fields", /deny_unknown_fields/],
]) {
expect(hostedService, name, pattern);
}
for (const [name, pattern] of [
["old client identity protocol is rejected", /hosted_login_protocol_rejects_client_identity_and_provider_configuration/],
["raw operator action is rejected", /rawOperatorDenied[\s\S]*hosted_operator_request envelope/],
["unsigned client identity is rejected", /const forged = await sendHostedControl[\s\S]*authenticated CLI session/],
["cross-tenant process inspection is rejected", /crossTenantTaskEventsDenied[\s\S]*scope\|denied\|unauthorized/],
]) {
expect(hostedTests, name, pattern);
}
}
console.log("Hostile input contract smoke passed");

View file

@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail
migrate_path() {
local source="$1"
local destination="$2"
if [[ ! -e "$source" ]]; then
return
fi
if [[ -e "$destination" ]]; then
printf 'refusing to overwrite existing destination: %s\n' "$destination" >&2
exit 1
fi
mv -- "$source" "$destination"
printf 'migrated %s -> %s\n' "$source" "$destination"
}
migrate_path "${HOME}/.disasmer" "${HOME}/.clusterflux"
migrate_path "${XDG_CONFIG_HOME:-${HOME}/.config}/disasmer" \
"${XDG_CONFIG_HOME:-${HOME}/.config}/clusterflux"
migrate_path "${PWD}/.disasmer" "${PWD}/.clusterflux"
migrate_path "${PWD}/disasmer.toml" "${PWD}/clusterflux.toml"

300
scripts/node-attach-smoke.js Executable file
View file

@ -0,0 +1,300 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const crypto = require("crypto");
const net = require("net");
const path = require("path");
const { coordinatorWireRequest } = require("./coordinator-wire");
const repo = path.resolve(__dirname, "..");
const identities = new Map();
function waitForJsonLine(child) {
return new Promise((resolve, reject) => {
let buffer = "";
child.stdout.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
try {
resolve(JSON.parse(buffer.slice(0, newline).trim()));
} catch (error) {
reject(error);
}
});
child.once("exit", (code) => {
reject(new Error(`process exited before JSON line with code ${code}`));
});
});
}
function send(addr, message) {
return new Promise((resolve, reject) => {
const socket = net.connect(addr.port, addr.host, () => {
socket.write(`${JSON.stringify(coordinatorWireRequest(message))}\n`);
});
let buffer = "";
socket.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
socket.end();
try {
resolve(JSON.parse(buffer.slice(0, newline)));
} catch (error) {
reject(error);
}
});
socket.on("error", reject);
});
}
function nodeIdentity(node) {
const existing = identities.get(node);
if (existing) return existing;
const { privateKey: privateKeyObject, publicKey } =
crypto.generateKeyPairSync("ed25519");
const privateDer = privateKeyObject.export({ format: "der", type: "pkcs8" });
const publicDer = publicKey.export({
format: "der",
type: "spki",
});
const privateSeed = Buffer.from(privateDer).subarray(-32);
const identity = {
privateKey: `ed25519:${privateSeed.toString("base64")}`,
publicKey: `ed25519:${Buffer.from(publicDer).subarray(-32).toString("base64")}`,
privateKeyObject,
};
identities.set(node, identity);
return identity;
}
function nodeSignatureMessage(
node,
requestKind,
payloadDigest,
nonce,
issuedAtEpochSeconds
) {
const parts = [
"clusterflux-node-request-signature:v2",
node,
requestKind,
payloadDigest,
nonce,
String(issuedAtEpochSeconds),
];
return Buffer.concat(
parts.flatMap((part) => [
Buffer.from(`${Buffer.byteLength(part)}:`),
Buffer.from(part),
Buffer.from("\n"),
])
);
}
function signedNodeHeartbeat(node, identity) {
const nonce = `node-attach-heartbeat-${process.pid}-${Date.now()}`;
const issuedAt = Math.floor(Date.now() / 1000);
const payloadDigest = `sha256:${crypto
.createHash("sha256")
.update(JSON.stringify({ node, type: "node_heartbeat" }))
.digest("hex")}`;
const signature = crypto.sign(
null,
nodeSignatureMessage(node, "node_heartbeat", payloadDigest, nonce, issuedAt),
identity.privateKeyObject
);
return {
nonce,
issued_at_epoch_seconds: issuedAt,
signature: `ed25519:${signature.toString("base64")}`,
};
}
function runAttach(addr, grant) {
const identity = nodeIdentity("node-attach");
return new Promise((resolve, reject) => {
const child = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-cli",
"--bin",
"clusterflux",
"--",
"node",
"attach",
"--coordinator",
`${addr.host}:${addr.port}`,
"--tenant",
"tenant",
"--project-id",
"project",
"--node",
"node-attach",
"--public-key",
identity.publicKey,
"--enrollment-grant",
grant,
"--cap",
"quic-direct",
"--json",
],
{
cwd: repo,
env: {
...process.env,
CLUSTERFLUX_NODE_PRIVATE_KEY: identity.privateKey,
},
}
);
let stdout = "";
let stderr = "";
child.stdout.on("data", (chunk) => {
stdout += chunk.toString();
});
child.stderr.on("data", (chunk) => {
stderr += chunk.toString();
});
child.on("exit", (code) => {
if (code !== 0) {
reject(new Error(`node attach failed with code ${code}\n${stderr}`));
return;
}
try {
resolve(JSON.parse(stdout));
} catch (error) {
reject(
new Error(`node attach output was not JSON: ${stdout}\n${error.stack || error.message}`)
);
}
});
});
}
(async () => {
const coordinator = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"--",
"--listen",
"127.0.0.1:0",
"--allow-local-trusted-loopback",
],
{ cwd: repo }
);
try {
const ready = await waitForJsonLine(coordinator);
const [host, portText] = ready.listen.split(":");
const addr = { host, port: Number(portText) };
assert.strictEqual((await send(addr, { type: "ping" })).type, "pong");
const grant = await send(addr, {
type: "create_node_enrollment_grant",
tenant: "tenant",
project: "project",
actor_user: "operator",
ttl_seconds: 900
});
assert.strictEqual(grant.type, "node_enrollment_grant_created");
assert.strictEqual(grant.tenant, "tenant");
assert.strictEqual(grant.project, "project");
assert.match(grant.grant, /^node_grant_[A-Za-z0-9_-]+$/);
assert.strictEqual(grant.scope, "node:attach");
assert(grant.expires_at_epoch_seconds > Math.floor(Date.now() / 1000));
assert(grant.expires_at_epoch_seconds <= Math.floor(Date.now() / 1000) + 900);
const report = await runAttach(addr, grant.grant);
assert.strictEqual(report.plan.node, "node-attach");
assert.strictEqual(report.plan.coordinator, `${addr.host}:${addr.port}`);
assert.strictEqual(report.plan.enrollment.grant, grant.grant);
assert.match(report.plan.enrollment.public_key_fingerprint, /^sha256:[0-9a-f]{64}$/);
assert.strictEqual(
report.plan.enrollment.exchanges_short_lived_grant_for_long_lived_node_identity,
true
);
assert.ok(report.plan.capabilities.arch.length > 0);
assert.ok(report.plan.capabilities.source_providers.includes("filesystem"));
assert.ok(report.plan.capabilities.capabilities.includes("QuicDirect"));
assert.strictEqual(report.plan.detection.auto_detected, true);
assert.strictEqual(report.plan.detection.arch, report.plan.capabilities.arch);
assert.deepStrictEqual(report.plan.detection.manual_capability_overrides, ["quic-direct"]);
assert(
report.plan.detection.recognized_capability_overrides.includes("QuicDirect")
);
assert.strictEqual(
report.plan.detection.os_arch_capabilities_require_manual_flags,
false
);
assert.strictEqual(report.plan.detection.command_backend, "native-command");
assert.strictEqual(report.plan.detection.command_backend_available, true);
assert(
report.plan.detection.source_provider_backends.some(
(provider) => provider.provider === "filesystem" && provider.detected
)
);
assert(
report.grant_disclosures.length > 0,
"node attach should disclose capability grants before reporting capabilities"
);
assert(
report.grant_disclosures.every(
(disclosure) => disclosure.coordinator_policy_limited === true
),
"node attach should mark all capability grants as coordinator-policy-limited"
);
assert(
report.grant_disclosures.some(
(disclosure) => disclosure.grant === "native_command_execution"
),
"node attach should disclose native command execution when detected"
);
assert(
report.grant_disclosures.some(
(disclosure) => disclosure.grant === "source_access"
),
"node attach should disclose source access when detected"
);
assert.strictEqual(report.boundary.cli_contacted_coordinator, true);
assert.strictEqual(report.boundary.used_enrollment_exchange, true);
assert.strictEqual(report.boundary.coordinator_session_requests, 3);
assert.strictEqual(report.coordinator_response.type, "node_enrollment_exchanged");
assert.strictEqual(report.coordinator_response.node, "node-attach");
assert.strictEqual(report.coordinator_response.credential.node, "node-attach");
assert.strictEqual(report.coordinator_response.credential.scope, "node:attach");
assert.strictEqual(report.coordinator_response.credential.credential_kind, "NodeCredential");
assert.match(
report.coordinator_response.credential.capability_policy_digest,
/^sha256:[0-9a-f]{64}$/
);
assert.strictEqual(report.heartbeat_response.type, "node_heartbeat");
assert.strictEqual(report.capability_response.type, "node_capabilities_recorded");
const heartbeat = await send(addr, {
type: "node_heartbeat",
node: "node-attach",
node_signature: signedNodeHeartbeat("node-attach", nodeIdentity("node-attach")),
});
assert.strictEqual(heartbeat.type, "node_heartbeat");
assert.strictEqual(heartbeat.node, "node-attach");
} finally {
coordinator.kill("SIGTERM");
}
console.log("Node attach smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

View file

@ -0,0 +1,155 @@
#!/usr/bin/env node
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const repo = path.resolve(__dirname, "..");
function read(relativePath) {
return fs.readFileSync(path.join(repo, relativePath), "utf8");
}
function expect(source, name, pattern) {
assert.match(source, pattern, `missing node lifecycle evidence: ${name}`);
}
const nodeMain = read("crates/clusterflux-node/src/daemon.rs");
const nodeIdentity = read("crates/clusterflux-node/src/node_identity.rs");
const cliNode = read("crates/clusterflux-cli/src/node.rs");
const nodeTaskReports = read("crates/clusterflux-node/src/task_reports.rs");
const nodeDebugAgent = read("crates/clusterflux-node/src/debug_agent.rs");
const nodeLib = read("crates/clusterflux-node/src/lib.rs");
const sharedWasmtimeRuntime = `${read("crates/clusterflux-wasm-runtime/src/lib.rs")}\n${read("crates/clusterflux-wasm-runtime/src/task_host_linker.rs")}`;
const nodeRuntimeSurface = `${nodeLib}\n${sharedWasmtimeRuntime}`;
const nodeLifecycleSurface = `${nodeMain}\n${nodeIdentity}\n${nodeTaskReports}\n${nodeDebugAgent}`;
const nodeAssignmentRunner = `${read("crates/clusterflux-node/src/assignment_runner.rs")}\n${read("crates/clusterflux-node/src/assignment_runner/control_watcher.rs")}\n${read("crates/clusterflux-node/src/assignment_runner/process_runner.rs")}\n${read("crates/clusterflux-node/src/assignment_runner/validation.rs")}`;
const coordinatorCore = read("crates/clusterflux-coordinator/src/lib.rs");
const coordinatorService = `${read("crates/clusterflux-coordinator/src/service.rs")}\n${read("crates/clusterflux-coordinator/src/service/routing.rs")}`;
const coordinatorServiceTests = read("crates/clusterflux-coordinator/src/service/tests.rs");
const coordinatorServiceSurface = `${coordinatorService}\n${coordinatorServiceTests}`;
const wasmtimeAssignmentSmoke = read("scripts/wasmtime-assignment-smoke.js");
const wasmtimeSmoke = read("scripts/wasmtime-node-smoke.js");
const debugCore = read("crates/clusterflux-core/src/debug.rs");
assert.strictEqual(
(nodeMain.match(/CoordinatorSession::connect/g) || []).length,
1,
"node runtime should open one coordinator session in the local process-boundary runtime"
);
for (const [name, pattern] of [
["enrollment exchange over session", /"type": "exchange_node_enrollment_grant"/],
["persisted node identity is reused locally", /"type": "node_identity_reused"/],
["heartbeat over session", /"type": "node_heartbeat"/],
["node-originated requests use signed envelope", /"type": "signed_node"/],
["capability report over session", /"type": "report_node_capabilities"/],
["task assignment polling over session", /"type": "poll_task_assignment"/],
["process start over session", /"type": "start_process"/],
["reconnect over session", /"type": "reconnect_node"/],
["debug command polling over session", /"type": "poll_debug_command"/],
["log event over session", /"type": "report_task_log"/],
["VFS metadata over session", /"type": "report_vfs_metadata"/],
["task control polling over session", /"type": "poll_task_control"/],
["completion over session", /"type": "task_completed"/],
["cancellation uses same session", /poll_task_cancellation\(session, args, &task, node_private_key\)/],
["request count is reported", /session\.requests\(\)/],
]) {
expect(nodeLifecycleSurface, name, pattern);
}
expect(cliNode, "user-authorized node attach over Client session", /"type": "attach_node"/);
assert.doesNotMatch(
nodeIdentity,
/"type": "attach_node"/,
"a persisted node must authenticate with its signed identity instead of replaying Client attach"
);
for (const [name, pattern] of [
["worker uses enrollment exchange", /workerReady\.node_status, "ready"/],
["worker receives the task instance selected by the SDK runtime", /nodeRun\.task_assignment_response\.task,[\s\S]*sdkRun\.task_spec\.task_instance/],
["worker verifies task ABI", /task_assignment_response\.task_spec\.dispatch\.abi/],
["worker records task completion", /nodeRun\.coordinator_response\.type, "task_recorded"/],
["worker exposes task result", /events\.events\[0\]\.result, \{ SmallJson: 42 \}/],
["Wasm task observes cooperative cancellation", /task_definition: "cooperative_cancellation_probe"[\s\S]*type: "cancel_process"/],
["cooperative cancellation returns under task control", /cancellationNodeRun\.terminal_state, "completed"/],
["running command abort is exercised", /task_definition: "abort_probe"[\s\S]*type: "abort_process"/],
["running command abort reaches terminal state", /abortedNodeRun\.terminal_state, "cancelled"/],
["running native command receives a real Debug Epoch freeze", /waitForNativeSleep[\s\S]*type: "create_debug_epoch"[\s\S]*fully_frozen/],
["native Linux process is observed stopped and resumed", /assert\.match\(procState\(nativeSleepPid\)[\s\S]*stopped[\s\S]*resume_debug_epoch[\s\S]*fully_resumed[\s\S]*assert\.doesNotMatch\(procState\(nativeSleepPid\)/],
["parent and child Wasm tasks are frozen as one process", /task_definition: "debug_parent_probe"[\s\S]*debugChildInstance = "debug_parent_probe-1:child:1"[\s\S]*all-stop across active parent and child Wasm participants[\s\S]*affected_tasks\.length, 2[\s\S]*acknowledgements\.length, 2[\s\S]*\[debugChildInstance, "debug_parent_probe-1"\]/],
["parent and child Wasm tasks both acknowledge resume", /multiParticipantResume[\s\S]*fully_resumed[\s\S]*acknowledgements\.length, 2/],
["abort releases process slot", /afterAbort\.processes, \[\]/],
]) {
expect(wasmtimeAssignmentSmoke, name, pattern);
}
for (const [name, pattern] of [
["cooperative cancellation and abort are distinct", /cancel_requested: false,[\s\S]*abort_requested: true/],
["controlled runner polls abort while command runs", /fn abort_requested[\s\S]*poll_task_control/],
["controlled runner creates a process group", /process\.process_group\(0\)/],
["controlled runner freezes the native process group", /libc::kill\(process_group, libc::SIGSTOP\)/],
["controlled runner resumes the native process group", /libc::kill\(process_group, libc::SIGCONT\)/],
["controlled runner kills the process group", /libc::kill\(process_group, libc::SIGKILL\)/],
["Wasm code can poll cooperative cancellation", /task_control_v1/],
["matched Wasm probes remain at a quiescent boundary", /TaskHostOperation::DebugProbe[\s\S]*enter_quiescent_host_boundary[\s\S]*leave_quiescent_host_boundary/],
["debug snapshots use the live Wasm task handle registry", /debug_handle_snapshot[\s\S]*task_handle_\{handle_id\}[\s\S]*state=active/],
["native command status comes from the controlled runner", /set_command_status[\s\S]*frozen native command pid[\s\S]*native command exited with status/],
]) {
expect(`${coordinatorServiceSurface}\n${nodeLifecycleSurface}\n${sharedWasmtimeRuntime}\n${nodeAssignmentRunner}`, name, pattern);
}
for (const [name, pattern] of [
["coordinator rejects stale process ownership", /fn node_reconnect_rejects_stale_process_epoch_after_restart\(\)/],
["reconnect preserves enrolled node identity", /reconnect_node\(&NodeId::from\("node"\), None\)/],
["stale process epoch is rejected", /CoordinatorError::StaleProcessEpoch/],
]) {
expect(coordinatorCore, name, pattern);
}
for (const [name, pattern] of [
["coordinator delivers cancellation to connected node", /fn service_delivers_cancellation_to_connected_node_and_records_terminal_state\(\)/],
["node polls task control", /CoordinatorRequest::PollTaskControl/],
["cancelled terminal state is recorded", /TaskTerminalState::Cancelled/],
]) {
expect(coordinatorServiceSurface, name, pattern);
}
for (const [name, pattern] of [
["native lifecycle test exists", /fn linux_task_lifecycle_supports_cancel_and_all_stop_freeze_resume\(\)/],
["native freeze succeeds when supported", /lifecycle\.freeze_for_debug_epoch\(\)\.unwrap\(\)/],
["native resume succeeds", /lifecycle\.resume_after_debug_epoch\(\)/],
["native cancel reaches lifecycle", /lifecycle\.cancel\(\)/],
["unsupported freeze errors", /BackendError::DebugFreezeUnsupported/],
["wasmtime runtime exposes freeze resume probe", /pub fn freeze_resume_i32_export_probe/],
["wasmtime runtime captures Wasm frame locals", /debug_i32_export_snapshot[\s\S]*local_values/],
["wasmtime runtime creates Wasm debug participant", /kind: DebugParticipantKind::WasmTask/],
["wasmtime debug participant carries local values", /local_values: snapshot\.local_values\.clone\(\)/],
["wasmtime runtime resumes after freeze", /epoch\.continue_all\(\)/],
]) {
expect(nodeRuntimeSurface, name, pattern);
}
for (const [name, pattern] of [
["wasmtime smoke runs debug freeze resume mode", /--debug-freeze-resume/],
["wasmtime smoke verifies frozen state", /debugReport\.frozen_state, "Frozen"/],
["wasmtime smoke verifies resumed state", /debugReport\.resumed_state, "Running"/],
["wasmtime smoke verifies frame local values", /debugReport\.local_values[\s\S]*wasm_local_0/],
["wasmtime smoke proves node runtime reached wasm task", /node_runtime_reached_wasm_task/],
["wasmtime smoke proves node captured locals", /node_runtime_captured_wasm_locals/],
]) {
expect(wasmtimeSmoke, name, pattern);
}
for (const [name, pattern] of [
["debug model freezes wasm and command participants", /fn breakpoint_creates_all_stop_debug_epoch_for_wasm_and_command_tasks\(\)/],
["debug model rejects unsupported freeze", /fn debug_epoch_reports_failure_when_no_participant_can_freeze\(\)/],
["debug model resumes frozen participants", /fn continue_resumes_every_frozen_participant\(\)/],
["debug model includes captured locals", /local_values/],
["wasm participants are modeled", /DebugParticipantKind::WasmTask/],
["controlled native command participants are modeled", /DebugParticipantKind::ControlledNativeCommand/],
]) {
expect(debugCore, name, pattern);
}
console.log("Node lifecycle contract smoke passed");

181
scripts/node-signing.js Normal file
View file

@ -0,0 +1,181 @@
const crypto = require("crypto");
const identities = new Map();
function nodeIdentity(identityPurpose, node) {
const identityKey = `${identityPurpose}:${node}`;
const existing = identities.get(identityKey);
if (existing) return existing;
const { privateKey: privateKeyObject, publicKey } =
crypto.generateKeyPairSync("ed25519");
const privateDer = privateKeyObject.export({ format: "der", type: "pkcs8" });
const publicDer = publicKey.export({
format: "der",
type: "spki",
});
const privateSeed = Buffer.from(privateDer).subarray(-32);
const identity = {
privateKey: `ed25519:${privateSeed.toString("base64")}`,
publicKey: `ed25519:${Buffer.from(publicDer).subarray(-32).toString("base64")}`,
privateKeyObject,
};
identities.set(identityKey, identity);
return identity;
}
function nodeIdentityFromPrivateKey(privateKey) {
if (typeof privateKey !== "string" || !privateKey.startsWith("ed25519:")) {
throw new Error("node private key must use ed25519:<base64> encoding");
}
const seed = Buffer.from(privateKey.slice("ed25519:".length), "base64");
if (seed.length !== 32) throw new Error("node private key must contain 32 bytes");
const privateKeyObject = crypto.createPrivateKey({
key: Buffer.concat([
Buffer.from("302e020100300506032b657004220420", "hex"),
seed,
]),
format: "der",
type: "pkcs8",
});
const publicKeyObject = crypto.createPublicKey(privateKeyObject);
const publicDer = publicKeyObject.export({ format: "der", type: "spki" });
return {
privateKey,
publicKey: `ed25519:${Buffer.from(publicDer).subarray(-32).toString("base64")}`,
privateKeyObject,
};
}
function canonicalSignedRequest(value, topLevel = true) {
if (Array.isArray(value)) {
return value.map((entry) => canonicalSignedRequest(entry, false));
}
if (value && typeof value === "object") {
return Object.fromEntries(
Object.entries(value)
.filter(
([key, entry]) =>
entry !== null &&
(!topLevel || !["agent_signature", "node_signature"].includes(key))
)
.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
.map(([key, entry]) => [key, canonicalSignedRequest(entry, false)])
);
}
return value;
}
function withWireDefaults(request) {
const value = { ...request };
if (value.type === "report_node_capabilities") {
value.dependency_cache_digests ??= [];
} else if (value.type === "launch_task" || value.type === "launch_child_task") {
value.wait_for_node ??= false;
if (value.task_spec && typeof value.task_spec === "object") {
value.task_spec = { ...value.task_spec };
value.task_spec.failure_policy ??= "fail_fast";
}
} else if (value.type === "start_process") {
value.restart ??= false;
} else if (value.type === "report_debug_state") {
value.stack_frames ??= [];
value.local_values ??= [];
value.task_args ??= [];
value.handles ??= [];
value.recent_output ??= [];
} else if (value.type === "report_task_log") {
value.stdout_tail ??= "";
value.stderr_tail ??= "";
} else if (value.type === "task_completed") {
value.stdout_tail ??= "";
value.stderr_tail ??= "";
value.stdout_truncated ??= false;
value.stderr_truncated ??= false;
}
return value;
}
function signedRequestPayloadDigest(request) {
return `sha256:${crypto
.createHash("sha256")
.update(JSON.stringify(canonicalSignedRequest(withWireDefaults(request))))
.digest("hex")}`;
}
function nodeSignatureMessage(
node,
requestKind,
payloadDigest,
nonce,
issuedAtEpochSeconds
) {
const parts = [
"clusterflux-node-request-signature:v2",
node,
requestKind,
payloadDigest,
nonce,
String(issuedAtEpochSeconds),
];
return Buffer.concat(
parts.flatMap((part) => [
Buffer.from(`${Buffer.byteLength(part)}:`),
Buffer.from(part),
Buffer.from("\n"),
])
);
}
function signedNodeProof(node, identity, requestKind, request, options = {}) {
const nonce =
options.nonce ||
`${requestKind}-${process.pid}-${Date.now()}-${crypto
.randomBytes(8)
.toString("hex")}`;
const issuedAt =
options.issuedAtEpochSeconds ?? Math.floor(Date.now() / 1000);
const signature = crypto.sign(
null,
nodeSignatureMessage(
node,
requestKind,
signedRequestPayloadDigest(request),
nonce,
issuedAt
),
identity.privateKeyObject
);
return {
nonce,
issued_at_epoch_seconds: issuedAt,
signature: `ed25519:${signature.toString("base64")}`,
};
}
function signedNodeHeartbeat(node, identity, options = {}) {
const request = { type: "node_heartbeat", node };
return signedNodeProof(node, identity, "node_heartbeat", request, options);
}
function signedNodeRequest(node, identity, requestKind, request, options = {}) {
return {
type: "signed_node",
node,
node_signature: signedNodeProof(
node,
identity,
requestKind,
request,
options
),
request,
};
}
module.exports = {
nodeIdentity,
nodeIdentityFromPrivateKey,
signedNodeProof,
signedRequestPayloadDigest,
signedNodeHeartbeat,
signedNodeRequest,
};

366
scripts/operator-panel-smoke.js Executable file
View file

@ -0,0 +1,366 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const { nodeIdentity } = require("./node-signing");
const {
ensureRootlessPodman,
repo,
runFlagshipWorker,
send,
startFlagship,
waitForTaskEvent,
waitForJsonLine,
} = require("./real-flagship-harness");
const panelNode = "panel-node";
const panelNodeIdentity = nodeIdentity("operator-panel-smoke", panelNode);
function widget(panel, id) {
const item = panel.widgets[id];
assert(item, `missing panel widget ${id}`);
return item;
}
const delay = (milliseconds) =>
new Promise((resolve) => setTimeout(resolve, milliseconds));
async function waitForBreakpointHit(addr, process) {
for (let attempt = 0; attempt < 2400; attempt += 1) {
const status = await send(addr, {
type: "inspect_debug_breakpoints",
tenant: "tenant",
project: "project",
actor_user: "user",
process,
});
assert.strictEqual(status.type, "debug_breakpoints", JSON.stringify(status));
if (status.hit_epoch != null) return status;
await delay(25);
}
throw new Error(`timed out waiting for package breakpoint in ${process}`);
}
async function waitForDebugEpochFrozen(addr, process, epoch) {
for (let attempt = 0; attempt < 2400; attempt += 1) {
const status = await send(addr, {
type: "inspect_debug_epoch",
tenant: "tenant",
project: "project",
actor_user: "user",
process,
epoch,
});
assert.strictEqual(status.type, "debug_epoch_status", JSON.stringify(status));
if (status.failed) {
throw new Error(status.failure_messages.join("; "));
}
if (status.fully_frozen) return status;
await delay(25);
}
throw new Error(`timed out waiting for debug epoch ${epoch} to freeze`);
}
(async () => {
ensureRootlessPodman();
const coordinator = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"--",
"--listen",
"127.0.0.1:0",
"--allow-local-trusted-loopback"
],
{ cwd: repo }
);
let coordinatorStderr = "";
let worker;
coordinator.stderr.on("data", (chunk) => {
coordinatorStderr += chunk.toString();
});
try {
const ready = await waitForJsonLine(coordinator);
const [host, portText] = ready.listen.split(":");
const addr = { host, port: Number(portText) };
assert.strictEqual((await send(addr, { type: "ping" })).type, "pong");
const projectCreated = await send(addr, {
type: "create_project",
tenant: "tenant",
actor_user: "user",
project: "project",
name: "Operator panel smoke",
});
assert.strictEqual(projectCreated.type, "project_created");
worker = await runFlagshipWorker(addr, panelNode, panelNodeIdentity);
const workerReady = await worker.ready;
assert.strictEqual(workerReady.node_status, "ready");
const workerCompletion = waitForJsonLine(worker.child);
const flagship = startFlagship(addr);
await waitForTaskEvent(
addr,
flagship.process,
(event) => event.task_definition === "prepare_source",
"prepare_source before breakpoint configuration"
);
const configuredBreakpoints = await send(addr, {
type: "set_debug_breakpoints",
tenant: "tenant",
project: "project",
actor_user: "user",
process: flagship.process,
probe_symbols: ["clusterflux.probe.package_release"],
});
assert.strictEqual(configuredBreakpoints.type, "debug_breakpoints");
const breakpointHit = await waitForBreakpointHit(addr, flagship.process);
assert.strictEqual(
breakpointHit.hit_probe_symbol,
"clusterflux.probe.package_release"
);
const frozenEpoch = await waitForDebugEpochFrozen(
addr,
flagship.process,
breakpointHit.hit_epoch
);
assert(frozenEpoch.acknowledgements.length >= 2);
const compileEvent = await waitForTaskEvent(
addr,
flagship.process,
(event) => event.task_definition === "compile_linux",
"compile_linux before the package breakpoint"
);
const report = await workerCompletion;
assert.strictEqual(report.node_status, "completed");
assert.strictEqual(report.coordinator_response.type, "task_recorded");
const process = flagship.process;
const rendered = await send(addr, {
type: "render_operator_panel",
tenant: "tenant",
project: "project",
process,
actor_user: "user",
max_download_bytes: 1024 * 1024,
stopped: false
});
assert.strictEqual(rendered.type, "operator_panel");
const panel = rendered.panel;
assert.strictEqual(panel.tenant, "tenant");
assert.strictEqual(panel.project, "project");
assert.strictEqual(panel.process, process);
assert.strictEqual(panel.program_ui_events_enabled, true);
assert.deepStrictEqual(widget(panel, "process-status").kind, {
Text: { value: "running" }
});
const taskProgress = widget(panel, "task-progress").kind.Progress;
assert(taskProgress.current >= 2);
assert.strictEqual(taskProgress.current, taskProgress.total);
const taskSummary = widget(panel, "task-summary").kind.Text.value;
assert.match(
taskSummary,
new RegExp(`compile_linux \\[${compileEvent.task}\\]:Some\\(0\\):panel-node`)
);
assert.match(widget(panel, "recent-logs").kind.Text.value, /stdout=\d+ stderr=\d+/);
const downloadWidget = widget(panel, "download-artifact").kind;
const artifact = downloadWidget.ArtifactDownload.artifact;
assert(
artifact === compileEvent.artifact_path.slice("/vfs/artifacts/".length),
"panel download must point at a real flagship artifact"
);
assert(!JSON.stringify(downloadWidget).includes("url_path"));
assert(!JSON.stringify(downloadWidget).includes("scoped_token_digest"));
assert.deepStrictEqual(widget(panel, "debug-process").kind, {
Button: { action: "debug-process" }
});
assert.deepStrictEqual(widget(panel, "cancel-process").kind, {
Button: { action: "cancel-process" }
});
assert.deepStrictEqual(widget(panel, "restart-selected-task").kind, {
Button: { action: "restart-task" }
});
assert(panel.control_plane_actions.includes("DebugProcess"));
assert(panel.control_plane_actions.includes("CancelProcess"));
const restartTarget = panel.control_plane_actions.find(
(action) => action.RestartTask
)?.RestartTask;
assert(
restartTarget && taskSummary.includes(`[${restartTarget}]`),
"panel restart must target the real flagship task instance"
);
assert(
panel.control_plane_actions.some(
(action) => action.DownloadArtifact === artifact
)
);
assert(!JSON.stringify(panel).includes("<script"));
assert(!JSON.stringify(panel).toLowerCase().includes("oauth"));
const panelLink = await send(addr, {
type: "create_artifact_download_link",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact: downloadWidget.ArtifactDownload.artifact,
max_bytes: 1024 * 1024,
ttl_seconds: 60
});
assert.strictEqual(panelLink.type, "artifact_download_link");
assert.strictEqual(panelLink.link.artifact, downloadWidget.ArtifactDownload.artifact);
assert.match(panelLink.link.policy_context_digest, /^sha256:[0-9a-f]{64}$/);
assert.deepStrictEqual(panelLink.link.source, { RetainedNode: "panel-node" });
assert(panelLink.link.url_path.endsWith(`/artifacts/tenant/project/${process}/${artifact}`));
const apiTooLarge = await send(addr, {
type: "create_artifact_download_link",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact: downloadWidget.ArtifactDownload.artifact,
max_bytes: 1,
ttl_seconds: 60
});
assert.strictEqual(apiTooLarge.type, "error");
assert.match(apiTooLarge.message, /exceeds download limit/);
const panelTooLarge = await send(addr, {
type: "render_operator_panel",
tenant: "tenant",
project: "project",
process,
actor_user: "user",
max_download_bytes: 1,
stopped: false
});
assert.strictEqual(panelTooLarge.type, "error");
assert.match(panelTooLarge.message, /exceeds download limit/);
const accepted = await send(addr, {
type: "submit_panel_event",
tenant: "tenant",
project: "project",
process,
widget_id: "debug-process",
kind: "ButtonClicked",
max_events: 1
});
assert.strictEqual(accepted.type, "panel_event_accepted");
assert.strictEqual(accepted.used_events, 1);
assert.strictEqual(accepted.max_events, 1);
const rateLimited = await send(addr, {
type: "submit_panel_event",
tenant: "tenant",
project: "project",
process,
widget_id: "debug-process",
kind: "ButtonClicked",
max_events: 1
});
assert.strictEqual(rateLimited.type, "error");
assert.match(rateLimited.message, /rate limit/i);
const stopped = await send(addr, {
type: "render_operator_panel",
tenant: "tenant",
project: "project",
process,
actor_user: "user",
max_download_bytes: 1024 * 1024,
stopped: true
});
assert.strictEqual(stopped.type, "operator_panel");
assert.strictEqual(stopped.panel.program_ui_events_enabled, false);
assert.deepStrictEqual(widget(stopped.panel, "process-status").kind, {
Text: { value: "stopped" }
});
assert.deepStrictEqual(
widget(stopped.panel, "task-progress").kind,
widget(panel, "task-progress").kind
);
assert.deepStrictEqual(
widget(stopped.panel, "task-summary").kind,
widget(panel, "task-summary").kind
);
assert.deepStrictEqual(
widget(stopped.panel, "recent-logs").kind,
widget(panel, "recent-logs").kind
);
assert.deepStrictEqual(
widget(stopped.panel, "download-artifact").kind,
widget(panel, "download-artifact").kind
);
assert(stopped.panel.control_plane_actions.includes("DebugProcess"));
assert(
stopped.panel.control_plane_actions.some(
(action) => action.DownloadArtifact === artifact
)
);
const frozenEvent = await send(addr, {
type: "submit_panel_event",
tenant: "tenant",
project: "project",
process,
widget_id: "debug-process",
kind: "ButtonClicked",
max_events: 10
});
assert.strictEqual(frozenEvent.type, "error");
assert.match(frozenEvent.message, /program UI events are disabled/i);
const crossTenant = await send(addr, {
type: "render_operator_panel",
tenant: "other",
project: "project",
process,
actor_user: "user",
max_download_bytes: 1024 * 1024,
stopped: false
});
assert.strictEqual(crossTenant.type, "error");
assert.match(
crossTenant.message,
/scope|tenant|project|requires an active virtual process/i
);
assert(!crossTenant.message.includes(process));
const resumed = await send(addr, {
type: "resume_debug_epoch",
tenant: "tenant",
project: "project",
actor_user: "user",
process,
epoch: breakpointHit.hit_epoch,
});
assert.strictEqual(resumed.type, "debug_epoch");
const cleanup = await send(addr, {
type: "abort_process",
tenant: "tenant",
project: "project",
actor_user: "user",
process,
});
assert.strictEqual(cleanup.type, "process_aborted");
} catch (error) {
if (coordinatorStderr) {
error.message = `${error.message}\ncoordinator stderr:\n${coordinatorStderr}`;
}
throw error;
} finally {
worker?.child.kill("SIGTERM");
coordinator.kill("SIGTERM");
}
console.log("Operator panel smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

86
scripts/podman-backend-smoke.js Executable file
View file

@ -0,0 +1,86 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const path = require("path");
const { configurePodmanTestEnvironment } = require("./podman-test-env");
const repo = path.resolve(__dirname, "..");
const baseImage = "docker.io/library/alpine:3.20";
// Nix's standalone Podman package may not install the distribution-level
// containers/image policy normally found under /etc. Use an isolated test HOME
// without replacing a policy supplied by the host.
configurePodmanTestEnvironment(repo);
function run(command, args, options = {}) {
return cp.execFileSync(command, args, {
cwd: repo,
encoding: "utf8",
stdio: options.stdio || ["ignore", "pipe", "pipe"],
});
}
function incomplete(reason) {
const error = new Error(`Linux Podman backend incomplete: ${reason}`);
error.code = "CLUSTERFLUX_PODMAN_INCOMPLETE";
throw error;
}
function ensurePodmanBaseImage() {
try {
run("podman", ["--version"]);
} catch (error) {
incomplete(`podman command is unavailable (${error.message})`);
}
let rootless;
try {
rootless = run("podman", ["info", "--format", "{{.Host.Security.Rootless}}"]).trim();
} catch (error) {
incomplete(`podman info did not report rootless status (${error.message})`);
}
if (rootless !== "true") {
incomplete(`podman is not running in rootless mode (reported ${JSON.stringify(rootless)})`);
}
try {
run("podman", ["image", "exists", baseImage]);
} catch (_) {
try {
run("podman", ["pull", baseImage], { stdio: "inherit" });
} catch (error) {
incomplete(`unable to make ${baseImage} available (${error.message})`);
}
}
}
try {
ensurePodmanBaseImage();
const stdout = run("cargo", [
"run",
"-q",
"-p",
"clusterflux-node",
"--bin",
"clusterflux-podman-smoke"
]);
const report = JSON.parse(stdout.trim().split("\n").at(-1));
assert.strictEqual(report.podman_status, "completed");
assert.strictEqual(report.status_code, 0);
assert.strictEqual(report.stdout, "podman-ok:node-local source\n");
assert.strictEqual(report.large_bytes_uploaded, false);
assert.strictEqual(report.uses_full_repo_tarball, false);
assert.strictEqual(report.coordinator_routed_file_reads, false);
assert.strictEqual(report.staged_artifact.path, "/vfs/artifacts/podman-smoke.txt");
console.log("Podman backend smoke passed");
} catch (error) {
if (error.code === "CLUSTERFLUX_PODMAN_INCOMPLETE") {
console.error(error.message);
process.exit(2);
}
throw error;
}

View file

@ -0,0 +1,41 @@
const fs = require("fs");
const os = require("os");
const path = require("path");
function configurePodmanTestEnvironment(repo) {
const originalHome = os.homedir();
if (
fs.existsSync(path.join(originalHome, ".config/containers/policy.json")) ||
fs.existsSync("/etc/containers/policy.json")
) {
return;
}
const isolatedHome = path.join(repo, "scripts/containers-home");
const policy = path.join(isolatedHome, ".config/containers/policy.json");
fs.mkdirSync(path.dirname(policy), { recursive: true });
if (!fs.existsSync(policy)) {
fs.writeFileSync(
policy,
`${JSON.stringify(
{ default: [{ type: "insecureAcceptAnything" }] },
null,
2
)}\n`
);
}
process.env.CARGO_HOME ||= path.join(originalHome, ".cargo");
process.env.RUSTUP_HOME ||= path.join(originalHome, ".rustup");
process.env.HOME = isolatedHome;
process.env.XDG_DATA_HOME = path.join(
os.tmpdir(),
`clusterflux-containers-data-${process.getuid?.() ?? "user"}`
);
process.env.XDG_CACHE_HOME = path.join(
os.tmpdir(),
`clusterflux-containers-cache-${process.getuid?.() ?? "user"}`
);
}
module.exports = { configurePodmanTestEnvironment };

View file

@ -0,0 +1,758 @@
#!/usr/bin/env node
const crypto = require("crypto");
const cp = require("child_process");
const fs = require("fs");
const os = require("os");
const path = require("path");
const repo = path.resolve(__dirname, "..");
const outputRoot = path.resolve(
process.env.CLUSTERFLUX_PUBLIC_RELEASE_DIR ||
path.join(repo, "target/public-release-dryrun")
);
const publicTree = path.join(outputRoot, "public-tree");
const assetsDir = path.join(outputRoot, "assets");
const stagingDir = path.join(outputRoot, "staging");
const publicBuildTarget = path.join(outputRoot, "cargo-target");
const defaultHostedCoordinatorEndpoint = "https://clusterflux.michelpaulissen.com";
const forgejoHost = "git.michelpaulissen.com";
const args = new Set(process.argv.slice(2));
const includeForgejoWorkflows =
args.has("--include-forgejo-workflows") ||
/^(1|true|yes)$/i.test(process.env.CLUSTERFLUX_INCLUDE_FORGEJO_WORKFLOWS || "");
const filteredTopLevel = ["private", "internal", "experiments", ".git", "target"];
const filteredDirectoryNames = [".clusterflux"];
const archiveIgnoredPathFallbacks = [
"target",
".clusterflux",
"vscode-extension/node_modules",
"scripts/containers-home",
];
const publicRepoBranch = process.env.CLUSTERFLUX_PUBLIC_REPO_BRANCH || "main";
const publicBinaries = [
"clusterflux",
"clusterflux-coordinator",
"clusterflux-node",
"clusterflux-debug-dap",
];
function commandOutput(command, args, options = {}) {
try {
const execOptions = {
cwd: repo,
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
...options,
};
execOptions.env = commandEnv(command, options.env);
return cp
.execFileSync(command, args, execOptions)
.trim();
} catch (_) {
return null;
}
}
function run(command, args, options = {}) {
const execOptions = {
cwd: repo,
stdio: "inherit",
...options,
};
execOptions.env = commandEnv(command, options.env);
cp.execFileSync(command, args, execOptions);
}
function nonInteractiveGitEnv(extra = {}) {
return {
...process.env,
GIT_TERMINAL_PROMPT: "0",
GIT_ASKPASS: process.env.GIT_ASKPASS || "/bin/false",
SSH_ASKPASS: process.env.SSH_ASKPASS || "/bin/false",
GIT_SSH_COMMAND:
process.env.GIT_SSH_COMMAND ||
"ssh -o BatchMode=yes -o NumberOfPasswordPrompts=0",
...extra,
};
}
function commandEnv(command, env) {
if (command !== "git") {
return env;
}
return nonInteractiveGitEnv(env);
}
function ensureDir(dir) {
fs.mkdirSync(dir, { recursive: true });
}
function filteredOutPatterns() {
return [
"private/**",
"internal/**",
"experiments/**",
".git",
"target",
"git-ignored source paths",
"root/*.md except README.md",
"**/.clusterflux/**",
...(includeForgejoWorkflows ? [] : [".forgejo/**"]),
];
}
function gitIgnoredSourcePaths() {
const output = commandOutput("git", [
"ls-files",
"--others",
"--ignored",
"--exclude-standard",
"--directory",
"-z",
]);
if (output === null) {
return archiveIgnoredPathFallbacks;
}
return [
...new Set([
...archiveIgnoredPathFallbacks,
...output
.split("\0")
.filter(Boolean)
.map((relativePath) =>
relativePath.replaceAll("\\", "/").replace(/\/$/, "")
),
]),
];
}
function isGitIgnored(relativePath, ignoredSourcePaths) {
const normalized = relativePath.replaceAll(path.sep, "/");
return ignoredSourcePaths.some(
(ignored) => normalized === ignored || normalized.startsWith(`${ignored}/`)
);
}
function isFilteredRootMarkdown(relativePath, entry) {
return (
!relativePath.includes(path.sep) &&
(entry.isFile() || entry.isSymbolicLink()) &&
path.extname(entry.name).toLowerCase() === ".md" &&
!["README.md", "SECURITY.md"].includes(entry.name)
);
}
function shouldFilter(entry, relativePath) {
const parts = relativePath.split(path.sep).filter(Boolean);
const topLevel = parts[0];
if (filteredTopLevel.includes(topLevel)) return true;
if (parts.some((part) => filteredDirectoryNames.includes(part))) return true;
if (topLevel === ".forgejo" && !includeForgejoWorkflows) return true;
if (isFilteredRootMarkdown(relativePath, entry)) return true;
return false;
}
function copyFilteredTree(src, dest, ignoredSourcePaths, relative = "") {
ensureDir(dest);
const entries = fs
.readdirSync(src, { withFileTypes: true })
.sort((left, right) => left.name.localeCompare(right.name));
for (const entry of entries) {
const childRelative = relative ? path.join(relative, entry.name) : entry.name;
if (
shouldFilter(entry, childRelative) ||
isGitIgnored(childRelative, ignoredSourcePaths)
) {
continue;
}
const from = path.join(src, entry.name);
const to = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyFilteredTree(from, to, ignoredSourcePaths, childRelative);
} else if (entry.isSymbolicLink()) {
fs.symlinkSync(fs.readlinkSync(from), to);
} else if (entry.isFile()) {
fs.copyFileSync(from, to);
fs.chmodSync(to, fs.statSync(from).mode & 0o777);
}
}
}
function assertFilteredTree(ignoredSourcePaths) {
for (const excluded of ["private", "internal", "experiments"]) {
if (fs.existsSync(path.join(publicTree, excluded))) {
throw new Error(`${excluded}/ leaked into the dry-run public tree`);
}
}
for (const file of walkFiles(publicTree)) {
if (file.split(path.sep).includes(".clusterflux")) {
throw new Error(`generated .clusterflux view state leaked into the dry-run public tree: ${file}`);
}
}
if (!includeForgejoWorkflows && fs.existsSync(path.join(publicTree, ".forgejo"))) {
throw new Error(".forgejo/ leaked into the host-neutral dry-run public tree");
}
if (!fs.existsSync(path.join(publicTree, "README.md"))) {
throw new Error("product README.md is missing from the dry-run public tree");
}
for (const ignored of ignoredSourcePaths) {
if (fs.existsSync(path.join(publicTree, ...ignored.split("/")))) {
throw new Error(`Git-ignored source path leaked into the dry-run public tree: ${ignored}`);
}
}
for (const entry of fs.readdirSync(publicTree, { withFileTypes: true })) {
if (isFilteredRootMarkdown(entry.name, entry)) {
throw new Error(`internal root Markdown file leaked into the dry-run public tree: ${entry.name}`);
}
}
}
function walkFiles(root, relative = "") {
const dir = path.join(root, relative);
const entries = fs
.readdirSync(dir, { withFileTypes: true })
.sort((left, right) => left.name.localeCompare(right.name));
const files = [];
for (const entry of entries) {
const childRelative = relative ? path.join(relative, entry.name) : entry.name;
if (entry.isDirectory()) {
files.push(...walkFiles(root, childRelative));
} else if (entry.isFile()) {
files.push(childRelative);
} else if (entry.isSymbolicLink()) {
files.push(childRelative);
}
}
return files;
}
function hashTree(root) {
const hash = crypto.createHash("sha256");
for (const file of walkFiles(root)) {
const absolute = path.join(root, file);
const stat = fs.lstatSync(absolute);
hash.update(file.replaceAll(path.sep, "/"));
hash.update("\0");
hash.update(String(stat.mode & 0o777));
hash.update("\0");
if (stat.isSymbolicLink()) {
hash.update("symlink");
hash.update("\0");
hash.update(fs.readlinkSync(absolute));
} else {
hash.update(fs.readFileSync(absolute));
}
hash.update("\0");
}
return `sha256:${hash.digest("hex")}`;
}
function sha256File(file) {
return crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
}
function tarGz(output, cwd, inputs) {
run("tar", ["-czf", output, "-C", cwd, ...inputs]);
}
function platformName() {
return `${os.platform()}-${os.arch()}`;
}
function binaryName(name) {
return process.platform === "win32" ? `${name}.exe` : name;
}
function buildPublicBinaries() {
run("cargo", ["build", "--workspace", "--bins", "--release", "--jobs", "2"], {
cwd: publicTree,
env: { ...process.env, CARGO_TARGET_DIR: publicBuildTarget },
});
}
function stageBinaryAssets(releaseName) {
const stageRoot = path.join(stagingDir, "binaries");
const binDir = path.join(stageRoot, "bin");
fs.rmSync(stageRoot, { recursive: true, force: true });
ensureDir(binDir);
for (const binary of publicBinaries) {
const fileName = binaryName(binary);
const built = path.join(publicBuildTarget, "release", fileName);
if (!fs.existsSync(built)) {
throw new Error(`expected release binary ${built}`);
}
const staged = path.join(binDir, fileName);
fs.copyFileSync(built, staged);
fs.chmodSync(staged, 0o755);
}
const archive = path.join(
assetsDir,
`clusterflux-public-binaries-${releaseName}-${platformName()}.tar.gz`
);
tarGz(archive, stageRoot, ["."]);
return archive;
}
function publicBinaryDigests() {
return Object.fromEntries(
publicBinaries.map((binary) => {
const fileName = binaryName(binary);
const file = path.join(publicBuildTarget, "release", fileName);
if (!fs.existsSync(file)) throw new Error(`missing built release binary ${file}`);
return [fileName, `sha256:${sha256File(file)}`];
})
);
}
function stageEvidenceAsset(
releaseName,
sourceCommit,
publicTreeIdentity,
binaryDigests
) {
const stage = path.join(stagingDir, "evidence");
fs.rmSync(stage, { recursive: true, force: true });
ensureDir(stage);
const evidenceRoot = path.join(repo, "target/acceptance");
const included = [];
for (const name of ["public-environment.json", "wasmtime-assignment.json"]) {
const source = path.join(evidenceRoot, name);
if (!fs.existsSync(source)) continue;
fs.copyFileSync(source, path.join(stage, name));
included.push(name);
}
const binding = {
kind: "clusterflux-release-evidence-binding",
source_commit: sourceCommit,
public_tree_identity: publicTreeIdentity,
binary_digests: binaryDigests,
configuration_generation:
process.env.CLUSTERFLUX_DEPLOYMENT_SYSTEM_GENERATION || null,
included_evidence: included,
};
fs.writeFileSync(
path.join(stage, "EVIDENCE_BINDING.json"),
`${JSON.stringify(binding, null, 2)}\n`
);
const archive = path.join(
assetsDir,
`clusterflux-public-evidence-${releaseName}.tar.gz`
);
tarGz(archive, stage, ["."]);
return archive;
}
function stageSourceAsset(releaseName) {
const archive = path.join(assetsDir, `clusterflux-public-source-${releaseName}.tar.gz`);
tarGz(archive, publicTree, ["."]);
return archive;
}
function stageExtensionAsset() {
const packageJson = JSON.parse(
fs.readFileSync(path.join(publicTree, "vscode-extension/package.json"), "utf8")
);
const archive = path.join(
assetsDir,
`${packageJson.name}-${packageJson.version}.vsix`
);
run(
"npx",
[
"--yes",
"@vscode/vsce",
"package",
"--allow-missing-repository",
"--skip-license",
"--out",
archive,
],
{ cwd: path.join(publicTree, "vscode-extension") }
);
return archive;
}
function resolverInstructions() {
if (process.env.CLUSTERFLUX_PUBLIC_DRYRUN_RESOLVER_INSTRUCTIONS) {
return process.env.CLUSTERFLUX_PUBLIC_DRYRUN_RESOLVER_INSTRUCTIONS.trim();
}
if (process.env.CLUSTERFLUX_PUBLIC_DRYRUN_HOSTS_ENTRY) {
return [
"Add the controlled hosts entry supplied for this dry run:",
"",
"```",
process.env.CLUSTERFLUX_PUBLIC_DRYRUN_HOSTS_ENTRY.trim(),
"```",
].join("\n");
}
if (process.env.CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_IP) {
return [
"Add this controlled hosts entry for the dry run:",
"",
"```",
`${process.env.CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_IP} clusterflux.michelpaulissen.com`,
"```",
].join("\n");
}
return [
"`clusterflux.michelpaulissen.com` should resolve through public DNS. If it",
"does not resolve yet, wait for DNS propagation or use the fallback hosts",
"entry supplied with the invitation.",
].join("\n");
}
function writeGettingStartedAsset(releaseName, publicTreeIdentity, resolution) {
const file = path.join(assetsDir, `CLUSTERFLUX_PUBLIC_DRYRUN_GETTING_STARTED-${releaseName}.md`);
fs.writeFileSync(
file,
`# Clusterflux Public Dry Run
This dry run is a real Clusterflux deployment for selected external users. If
public DNS has not propagated yet, use the fallback resolution instructions
below.
The default hosted coordinator is the deployment at
\`https://clusterflux.michelpaulissen.com\`. The word \`public\` in this dry run
refers to the public Forgejo repository, release downloads, selected-user
network access, and public client protocol compatibility. It does not mean the
server is the standalone open-source Core coordinator.
## DNS
${resolution}
## Install
1. Download the binary archive for your platform from the Forgejo Release at
\`git.michelpaulissen.com\`.
2. Verify it against \`SHA256SUMS\`.
3. Extract the archive and put the \`bin/\` directory on your \`PATH\`.
4. Download \`clusterflux-vscode-*.vsix\` if you want the debugger and Clusterflux
side views, then install it:
\`\`\`bash
code --install-extension clusterflux-vscode-*.vsix
\`\`\`
## Connect
Use the default hosted coordinator endpoint:
\`\`\`bash
clusterflux login --browser
clusterflux bundle inspect --project examples/launch-build-demo
\`\`\`
\`clusterflux login --browser\` opens the server-provided Authentik authorization
URL and polls the hosted transaction. The provider callback terminates on the
hosted service; provider codes and tokens do not pass through the CLI.
Enroll a node identity with the grant supplied by the invitation:
\`\`\`bash
clusterflux node attach --coordinator https://clusterflux.michelpaulissen.com --enrollment-grant <grant> --public-key <public-key>
\`\`\`
That command proves the identity/enrollment path and then exits. To actually run
work for the flagship workflow, leave a worker process running in another
terminal. Use a fresh enrollment grant, or skip the attach command above and use
the worker command directly:
\`\`\`bash
clusterflux-node --coordinator https://clusterflux.michelpaulissen.com --tenant <tenant> --project-id <project> --node <node-id> --public-key <public-key> --enrollment-grant <grant> --worker --emit-ready
\`\`\`
Then run the flagship workflow from the filtered public repository while that
worker is still running:
\`\`\`bash
clusterflux run --project examples/launch-build-demo build
\`\`\`
The dry-run public tree identity is \`${publicTreeIdentity}\`.
The release name is \`${releaseName}\`.
`,
"utf8"
);
return file;
}
function writeInviteAsset(releaseName, publicTreeIdentity, resolution) {
const file = path.join(assetsDir, `CLUSTERFLUX_PUBLIC_DRYRUN_INVITE-${releaseName}.md`);
const publicRepo =
process.env.CLUSTERFLUX_PUBLIC_REPO_URL ||
"https://git.michelpaulissen.com/<owner>/<public-repo>";
const releaseUrl =
process.env.CLUSTERFLUX_FORGEJO_RELEASE_URL ||
"the Forgejo Release attached to the public repository";
fs.writeFileSync(
file,
`# Clusterflux Public Dry Run Invite
This invite is for selected external users, such as friends helping test the
MVP release experience. The deployment is real and externally reachable, but it
is intentionally not broadly advertised yet.
The hosted coordinator behind this invite is the deployment at
\`https://clusterflux.michelpaulissen.com\`. The public part is the Forgejo
repository, release downloads, network-reachable dry run, and public client
protocol used by the binaries; the hosted server is not the standalone Core
coordinator.
If public DNS has not propagated yet, make sure \`clusterflux.michelpaulissen.com\`
resolves to the deployment host before running the CLI.
## Links
- Public repository: ${publicRepo}
- Release downloads: ${releaseUrl}
- Default hosted coordinator endpoint: ${defaultHostedCoordinatorEndpoint}
- Public tree identity: ${publicTreeIdentity}
- Release name: ${releaseName}
## DNS
${resolution}
## First run
1. Download the binary archive for your platform and \`SHA256SUMS\` from the
Forgejo Release.
2. Extract the archive and put \`bin/\` on your \`PATH\`.
3. Optionally install \`clusterflux-vscode-*.vsix\` with
\`code --install-extension clusterflux-vscode-*.vsix\`.
4. Run \`clusterflux login --browser\`; it opens the server-provided Authentik
authorization URL and polls the hosted transaction for a scoped CLI session.
5. Enroll a node identity with the enrollment grant supplied out of band.
6. Start a long-lived worker with a fresh enrollment grant, or use the worker
command directly instead of step 5:
\`clusterflux-node --coordinator https://clusterflux.michelpaulissen.com --tenant <tenant> --project-id <project> --node <node-id> --public-key <public-key> --enrollment-grant <grant> --worker --emit-ready\`.
7. Run \`clusterflux run --project examples/launch-build-demo build\` from the
public repository checkout while the worker process is still running.
`,
"utf8"
);
return file;
}
function writeSha256Sums(assets) {
const sumsPath = path.join(assetsDir, "SHA256SUMS");
const lines = assets
.map((asset) => `${sha256File(asset)} ${path.basename(asset)}`)
.sort()
.join("\n");
fs.writeFileSync(sumsPath, `${lines}\n`);
return sumsPath;
}
function boolEnv(name) {
return /^(1|true|yes)$/i.test(process.env[name] || "");
}
function writePublicTreeProvenance(sourceCommit, releaseName) {
const provenance = {
kind: "clusterflux-filtered-public-tree",
source_commit: sourceCommit,
release_name: releaseName,
filtered_out: filteredOutPatterns(),
public_export: {
host_neutral: !includeForgejoWorkflows,
include_forgejo_workflows: includeForgejoWorkflows,
},
forgejo_host: forgejoHost,
default_hosted_coordinator_endpoint: defaultHostedCoordinatorEndpoint,
};
fs.writeFileSync(
path.join(publicTree, "CLUSTERFLUX_PUBLIC_TREE.json"),
`${JSON.stringify(provenance, null, 2)}\n`
);
}
function publishPublicTree(releaseName, sourceCommit, publicTreeIdentity) {
const remote =
process.env.CLUSTERFLUX_PUBLIC_REPO_REMOTE ||
process.env.CLUSTERFLUX_PUBLIC_REPO_URL ||
null;
const enabled = boolEnv("CLUSTERFLUX_PUBLISH_PUBLIC_TREE");
const result = {
enabled,
remote,
branch: publicRepoBranch,
commit: null,
pushed: false,
};
if (!enabled) {
return result;
}
if (!remote) {
throw new Error(
"CLUSTERFLUX_PUBLISH_PUBLIC_TREE requires CLUSTERFLUX_PUBLIC_REPO_REMOTE or CLUSTERFLUX_PUBLIC_REPO_URL"
);
}
if (!remote.includes(forgejoHost)) {
throw new Error(`public repo remote must point at ${forgejoHost}: ${remote}`);
}
run("git", ["init"], { cwd: publicTree });
run("git", ["checkout", "-B", publicRepoBranch], { cwd: publicTree });
run("git", ["config", "user.name", "Clusterflux release dry run"], {
cwd: publicTree,
});
run("git", ["config", "user.email", "release-dryrun@clusterflux.invalid"], {
cwd: publicTree,
});
run("git", ["add", "."], { cwd: publicTree });
run(
"git",
[
"commit",
"-m",
`Public dry run ${releaseName}`,
"-m",
`Source commit: ${sourceCommit}`,
"-m",
`Public tree identity: ${publicTreeIdentity}`,
],
{ cwd: publicTree }
);
result.commit = commandOutput("git", ["rev-parse", "HEAD"], { cwd: publicTree });
run("git", ["remote", "add", "public", remote], { cwd: publicTree });
const pushArgs = ["push", "public", `HEAD:${publicRepoBranch}`];
if (boolEnv("CLUSTERFLUX_PUBLIC_REPO_PUSH_FORCE_WITH_LEASE")) {
run(
"git",
[
"fetch",
"public",
`refs/heads/${publicRepoBranch}:refs/remotes/public/${publicRepoBranch}`,
],
{ cwd: publicTree }
);
pushArgs.splice(1, 0, "--force-with-lease");
}
run("git", pushArgs, { cwd: publicTree });
result.pushed = true;
return result;
}
function main() {
const sourceCommit =
process.env.CLUSTERFLUX_ACCEPTANCE_COMMIT ||
commandOutput("git", ["rev-parse", "HEAD"]) ||
"unknown";
const shortCommit = sourceCommit === "unknown" ? "unknown" : sourceCommit.slice(0, 12);
const releaseName = process.env.CLUSTERFLUX_PUBLIC_RELEASE_NAME || `dryrun-${shortCommit}`;
const sourceStatus = commandOutput("git", ["status", "--short"]);
const sourceTreeClean = sourceStatus === null ? null : sourceStatus === "";
fs.rmSync(outputRoot, { recursive: true, force: true });
ensureDir(publicTree);
ensureDir(assetsDir);
ensureDir(stagingDir);
const ignoredSourcePaths = gitIgnoredSourcePaths();
copyFilteredTree(repo, publicTree, ignoredSourcePaths);
assertFilteredTree(ignoredSourcePaths);
writePublicTreeProvenance(sourceCommit, releaseName);
const publicTreeIdentity = hashTree(publicTree);
const sourceArchive = stageSourceAsset(releaseName);
run("scripts/check-old-name.sh", [], { cwd: publicTree });
run("node", ["scripts/check-docs.js"], { cwd: publicTree });
run("scripts/check-code-size.sh", [], { cwd: publicTree });
const publicTreePublish = publishPublicTree(
releaseName,
sourceCommit,
publicTreeIdentity
);
buildPublicBinaries();
const binaryArchive = stageBinaryAssets(releaseName);
const binaryDigests = publicBinaryDigests();
const evidenceArchive = stageEvidenceAsset(
releaseName,
sourceCommit,
publicTreeIdentity,
binaryDigests
);
const extensionArchive = stageExtensionAsset();
const resolution = resolverInstructions();
const gettingStarted = writeGettingStartedAsset(
releaseName,
publicTreeIdentity,
resolution
);
const invite = writeInviteAsset(releaseName, publicTreeIdentity, resolution);
const assets = [
sourceArchive,
binaryArchive,
evidenceArchive,
extensionArchive,
gettingStarted,
invite,
];
const sha256Sums = writeSha256Sums(assets);
const manifest = {
kind: "clusterflux-public-release-dryrun",
release_name: releaseName,
source_commit: sourceCommit,
source_tree_clean: sourceTreeClean,
public_tree_identity: publicTreeIdentity,
public_tree: publicTree,
filtered_out: filteredOutPatterns(),
public_export: {
host_neutral: !includeForgejoWorkflows,
include_forgejo_workflows: includeForgejoWorkflows,
},
forgejo_host: forgejoHost,
public_repo_url: process.env.CLUSTERFLUX_PUBLIC_REPO_URL || publicTreePublish.remote,
public_repo_remote: process.env.CLUSTERFLUX_PUBLIC_REPO_REMOTE || null,
public_tree_publish: publicTreePublish,
forgejo_release_url: process.env.CLUSTERFLUX_FORGEJO_RELEASE_URL || null,
default_hosted_coordinator_endpoint: defaultHostedCoordinatorEndpoint,
dns_publication_state:
process.env.CLUSTERFLUX_DNS_PUBLICATION_STATE || "published",
resolver_override:
process.env.CLUSTERFLUX_RESOLVER_OVERRIDE || "none-required-public-dns",
platform: platformName(),
binary_digests: binaryDigests,
configuration_generation:
process.env.CLUSTERFLUX_DEPLOYMENT_SYSTEM_GENERATION || null,
tool_versions: {
node: process.version,
rustc: commandOutput("rustc", ["--version"]) || null,
cargo: commandOutput("cargo", ["--version"]) || null,
tar: commandOutput("tar", ["--version"]) || null,
},
commands: [
"scripts/check-old-name.sh",
"node scripts/check-docs.js",
"scripts/check-code-size.sh",
...(publicTreePublish.enabled
? [`git push public HEAD:${publicRepoBranch}`]
: []),
"cargo build --workspace --bins --release --jobs 2",
],
assets: [...assets, sha256Sums].map((asset) => ({
file: asset,
name: path.basename(asset),
sha256: sha256File(asset),
})),
notes: [
"Upload the assets to the Forgejo Release for the filtered public repository.",
"The real service deployment and full e2e dry run remain separate acceptance evidence.",
],
};
const manifestPath = path.join(outputRoot, "public-release-manifest.json");
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
console.log(JSON.stringify({ manifest: manifestPath, assets: assetsDir }, null, 2));
}
main();

View file

@ -0,0 +1,69 @@
#!/usr/bin/env node
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const repo = path.resolve(__dirname, "..");
function read(relativePath) {
return fs.readFileSync(path.join(repo, relativePath), "utf8");
}
function expect(source, name, pattern) {
assert.match(source, pattern, `missing public local demo evidence: ${name}`);
}
const publicAcceptance = read("scripts/acceptance-public.sh");
const publicSplit = read("scripts/verify-public-split.sh");
const cliInstall = read("scripts/cli-install-smoke.js");
const flagship = read("scripts/flagship-demo-smoke.js");
const cliLocalRun = read("scripts/cli-local-run-smoke.js");
const nodeAttach = read("scripts/node-attach-smoke.js");
const vscodeExtension = read("scripts/vscode-extension-smoke.js");
const vscodeF5 = read("scripts/vscode-f5-smoke.js");
const artifactDownload = read("scripts/artifact-download-smoke.js");
const artifactExport = read("scripts/artifact-export-smoke.js");
for (const script of [publicAcceptance, publicSplit]) {
for (const smoke of [
"scripts/cli-install-smoke.js",
"scripts/flagship-demo-smoke.js",
"scripts/cli-local-run-smoke.js",
"scripts/node-attach-smoke.js",
"scripts/vscode-extension-smoke.js",
"scripts/vscode-f5-smoke.js",
"scripts/artifact-download-smoke.js",
"scripts/artifact-export-smoke.js",
]) {
assert(script.includes(`node ${smoke}`), `public demo gate must run ${smoke}`);
}
}
expect(cliInstall, "CLI install from project path", /cargo[\s\S]*install[\s\S]*crates\/clusterflux-cli/);
expect(cliInstall, "CLI install smoke targets flagship project", /const project = path\.join\(repo, "examples\/launch-build-demo"\)/);
expect(cliInstall, "installed CLI inspects flagship project", /installedBin[\s\S]*\["bundle", "inspect", "--project", project, "--json"\]/);
expect(flagship, "flagship project source is Rust workflow", /examples\/launch-build-demo[\s\S]*src\/build\.rs/);
expect(flagship, "flagship source avoids local machine assumptions", /forbiddenSourceAssumptions/);
expect(flagship, "flagship cargo test runs", /cargo[\s\S]*test[\s\S]*launch-build-demo/);
expect(cliLocalRun, "local run starts node process", /cli_process_started_node_process[\s\S]*true/);
expect(cliLocalRun, "local run records real task events", /events\.events\.length >= 4[\s\S]*prepare_source[\s\S]*compile_linux[\s\S]*package_release/);
expect(cliLocalRun, "local run records artifact metadata", /events\.events\.some\(\(event\) => event\.artifact_path\)/);
expect(nodeAttach, "Linux node attach creates enrollment grant", /create_node_enrollment_grant/);
expect(nodeAttach, "Linux node attach uses enrollment exchange", /used_enrollment_exchange[\s\S]*true/);
expect(nodeAttach, "attached Linux node proves signed enrollment", /used_enrollment_exchange[\s\S]*signedNodeHeartbeat/);
expect(vscodeExtension, "extension contributes debugger", /contributes\.debuggers[\s\S]*type === "clusterflux"/);
expect(vscodeF5, "F5 uses local-services backend", /runtimeBackend[\s\S]*local-services/);
expect(vscodeF5, "F5 exposes real coordinator main thread", /threads\.find\(\(thread\) => thread\.name\.includes\("build coordinator main"\)\)[\s\S]*real coordinator-main entrypoint thread/);
expect(vscodeF5, "F5 does not fabricate a terminal event at the entry probe", /coordinator_task_events[\s\S]*value === 0[\s\S]*must not fabricate a terminal task event/);
expect(artifactDownload, "artifact download creates scoped link", /create_artifact_download_link/);
expect(artifactDownload, "artifact download opens stream", /open_artifact_download_stream/);
expect(artifactExport, "artifact export targets receiver node", /export_artifact_to_node[\s\S]*node-export-receiver/);
expect(artifactExport, "artifact export rejects coordinator bulk relay", /coordinator_bulk_relay_allowed[\s\S]*false/);
console.log("Public local demo matrix smoke passed");

View file

@ -0,0 +1,292 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const crypto = require("crypto");
const fs = require("fs");
const path = require("path");
const repo = path.resolve(__dirname, "..");
const releaseRoot = path.resolve(
process.env.CLUSTERFLUX_PUBLIC_RELEASE_DIR ||
path.join(repo, "target/public-release-dryrun")
);
const acceptanceRoot = path.join(repo, "target/acceptance");
const manifestPath =
process.env.CLUSTERFLUX_PUBLIC_RELEASE_MANIFEST ||
path.join(releaseRoot, "public-release-manifest.json");
const reportPath =
process.env.CLUSTERFLUX_PUBLIC_RELEASE_PREFLIGHT_REPORT ||
path.join(acceptanceRoot, "public-release-dryrun-preflight.json");
function commandOutput(command, args, options = {}) {
try {
return cp
.execFileSync(command, args, {
cwd: repo,
encoding: "utf8",
stdio: ["ignore", "pipe", "pipe"],
...options,
})
.trim();
} catch (_) {
return null;
}
}
function nonInteractiveEnv(extra = {}) {
return {
...process.env,
GIT_TERMINAL_PROMPT: "0",
GIT_ASKPASS: process.env.GIT_ASKPASS || "/bin/false",
SSH_ASKPASS: process.env.SSH_ASKPASS || "/bin/false",
GIT_SSH_COMMAND:
process.env.GIT_SSH_COMMAND ||
"ssh -o BatchMode=yes -o NumberOfPasswordPrompts=0",
...extra,
};
}
function expectedSourceCommit() {
return (
process.env.CLUSTERFLUX_ACCEPTANCE_COMMIT ||
commandOutput("git", ["rev-parse", "HEAD"]) ||
"unknown"
);
}
function readJson(file) {
return JSON.parse(fs.readFileSync(file, "utf8"));
}
function sha256File(file) {
return crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
}
function parseSha256Sums(file) {
const sums = new Map();
for (const line of fs.readFileSync(file, "utf8").split(/\r?\n/)) {
if (!line.trim()) continue;
const match = /^([0-9a-f]{64})\s+(.+)$/.exec(line.trim());
assert(match, `malformed SHA256SUMS line: ${line}`);
sums.set(path.basename(match[2]), match[1]);
}
return sums;
}
function remoteHead(remote) {
const output = commandOutput("git", ["ls-remote", remote, "HEAD", "refs/heads/main"], {
env: nonInteractiveEnv(),
timeout: Number(process.env.CLUSTERFLUX_PUBLIC_REPO_REMOTE_TIMEOUT_MS || 30000),
});
if (!output) return null;
const lines = output.split(/\r?\n/).filter(Boolean);
const head = lines.find((line) => line.endsWith("\tHEAD")) || lines[0];
return head && head.split(/\s+/)[0];
}
function publicTreeAlreadyPushed(manifest) {
return (
(manifest.public_tree_publish && manifest.public_tree_publish.pushed === true) ||
process.env.CLUSTERFLUX_PUBLIC_TREE_ALREADY_PUSHED === "1"
);
}
function publicTreePushSource(manifest) {
return manifest.public_tree_publish && manifest.public_tree_publish.pushed === true
? "manifest"
: "external-env";
}
function publicRepoRemoteForManifest(manifest) {
return (
manifest.public_repo_url ||
manifest.public_repo_remote ||
process.env.CLUSTERFLUX_PUBLIC_REPO_REMOTE ||
process.env.CLUSTERFLUX_PUBLIC_REPO_URL ||
null
);
}
function publicTreeCommitForManifest(manifest) {
return (
(manifest.public_tree_publish && manifest.public_tree_publish.commit) ||
process.env.CLUSTERFLUX_PUBLIC_TREE_COMMIT ||
process.env.CLUSTERFLUX_PUBLIC_RELEASE_TARGET ||
null
);
}
function envState(name) {
return process.env[name] ? "set" : "unset";
}
function staleEvidence(file, currentSourceCommit) {
if (!fs.existsSync(file)) {
return { file, status: "missing", source_commit: null, release_name: null };
}
const evidence = readJson(file);
if (!evidence.source_commit) {
return {
file,
status: "unversioned",
source_commit: null,
release_name: evidence.release_name || null,
};
}
return {
file,
status: evidence.source_commit === currentSourceCommit ? "current" : "stale",
source_commit: evidence.source_commit,
release_name: evidence.release_name || null,
};
}
assert(fs.existsSync(manifestPath), `missing public release manifest: ${manifestPath}`);
const manifest = readJson(manifestPath);
const currentSourceCommit = expectedSourceCommit();
const currentTreeStatus = commandOutput("git", ["status", "--short"]) || "";
assert.strictEqual(
currentTreeStatus,
"",
"public release preflight requires a clean source tree"
);
assert.strictEqual(manifest.kind, "clusterflux-public-release-dryrun");
assert.strictEqual(
manifest.source_commit,
currentSourceCommit,
"public release manifest must be regenerated for the current acceptance commit"
);
assert.strictEqual(manifest.source_tree_clean, true, "public release prep must start clean");
assert.strictEqual(
publicTreeAlreadyPushed(manifest),
true,
"filtered public tree must be pushed to Forgejo before release publication"
);
const publicRepoRemote = publicRepoRemoteForManifest(manifest);
assert(publicRepoRemote, "manifest must record public repository URL or remote");
const publicTreeCommit = publicTreeCommitForManifest(manifest);
const remoteMain = remoteHead(publicRepoRemote);
assert(remoteMain, "Forgejo public repository main branch must be readable");
if (publicTreeCommit) {
assert.strictEqual(
remoteMain,
publicTreeCommit,
"Forgejo public repository main branch must match the prepared public tree commit"
);
}
assert(Array.isArray(manifest.assets) && manifest.assets.length > 0, "manifest assets missing");
const checksumAsset = manifest.assets.find((asset) => asset.name === "SHA256SUMS");
assert(checksumAsset, "manifest must include SHA256SUMS");
assert(fs.existsSync(checksumAsset.file), `missing checksum asset: ${checksumAsset.file}`);
const checksums = parseSha256Sums(checksumAsset.file);
const assets = manifest.assets.map((asset) => {
assert(fs.existsSync(asset.file), `missing release asset: ${asset.file}`);
const actual = sha256File(asset.file);
const expected = checksums.get(asset.name);
if (asset.name !== "SHA256SUMS") {
assert.strictEqual(actual, expected, `checksum mismatch for ${asset.name}`);
}
return {
name: asset.name,
file: asset.file,
bytes: fs.statSync(asset.file).size,
sha256: actual,
};
});
const evidence = [
staleEvidence(
path.join(acceptanceRoot, "public-release-dryrun-forgejo-release.json"),
currentSourceCommit
),
staleEvidence(
path.join(acceptanceRoot, "public-release-dryrun-service.json"),
currentSourceCommit
),
staleEvidence(
path.join(acceptanceRoot, "hosted-client-compat.json"),
currentSourceCommit
),
staleEvidence(
path.join(acceptanceRoot, "core-coordinator-compat.json"),
currentSourceCommit
),
staleEvidence(
path.join(acceptanceRoot, "public-release-dryrun-e2e.json"),
currentSourceCommit
),
staleEvidence(
path.join(acceptanceRoot, "public-release-dryrun-final.json"),
currentSourceCommit
),
];
const report = {
kind: "clusterflux-public-release-dryrun-preflight",
source_commit: currentSourceCommit,
release_name: manifest.release_name,
public_tree_commit: publicTreeCommit || remoteMain,
public_tree_push_source: publicTreePushSource(manifest),
public_repo_url: publicRepoRemote,
public_repo_remote_head: remoteMain,
source_tree_clean: currentTreeStatus === "",
local_assets_ready: true,
assets,
evidence,
external_gates: {
forgejo_release_publication: {
status: envState("CLUSTERFLUX_FORGEJO_TOKEN") === "set" ? "ready" : "pending",
env: {
CLUSTERFLUX_FORGEJO_TOKEN: envState("CLUSTERFLUX_FORGEJO_TOKEN"),
},
},
live_service_smoke: {
status:
envState("CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_SERVICE_ADDR") === "set" &&
envState("CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_BROWSER_OPEN_COMMAND") === "set"
? "ready"
: "pending",
env: {
CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_SERVICE_ADDR: envState(
"CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_SERVICE_ADDR"
),
CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_BROWSER_OPEN_COMMAND: envState(
"CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_BROWSER_OPEN_COMMAND"
),
},
},
public_release_e2e: {
status:
envState("CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_E2E") === "set" &&
process.env.CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_E2E === "1" &&
envState("CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_BROWSER_OPEN_COMMAND") === "set"
? "ready"
: "pending",
env: {
CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_E2E:
process.env.CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_E2E || "unset",
CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_BROWSER_OPEN_COMMAND: envState(
"CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_BROWSER_OPEN_COMMAND"
),
},
},
final_evidence: {
status:
envState("CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_FINAL") === "set" &&
process.env.CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_FINAL === "1"
? "ready"
: "pending",
env: {
CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_FINAL:
process.env.CLUSTERFLUX_PUBLIC_RELEASE_DRYRUN_FINAL || "unset",
},
},
},
};
fs.mkdirSync(path.dirname(reportPath), { recursive: true });
fs.writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`);
console.log(JSON.stringify({ report: reportPath, release_name: report.release_name }, null, 2));

View file

@ -0,0 +1,349 @@
#!/usr/bin/env node
const fs = require("fs");
const https = require("https");
const path = require("path");
const cp = require("child_process");
const repo = path.resolve(__dirname, "..");
const releaseRoot = path.resolve(
process.env.CLUSTERFLUX_PUBLIC_RELEASE_DIR ||
path.join(repo, "target/public-release-dryrun")
);
const manifestPath = path.join(releaseRoot, "public-release-manifest.json");
const reportPath = path.join(
repo,
"target/acceptance/public-release-dryrun-forgejo-release.json"
);
const forgejoUrl = (
process.env.CLUSTERFLUX_FORGEJO_URL || "https://git.michelpaulissen.com"
).replace(/\/+$/, "");
const token = process.env.CLUSTERFLUX_FORGEJO_TOKEN;
let owner = process.env.CLUSTERFLUX_PUBLIC_REPO_OWNER;
let repoName = process.env.CLUSTERFLUX_PUBLIC_REPO_NAME;
function requireEnv(name, value) {
if (!value) {
throw new Error(`${name} is required`);
}
}
function commandOutput(command, args) {
try {
return cp
.execFileSync(command, args, {
cwd: repo,
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
})
.trim();
} catch (_) {
return null;
}
}
function expectedSourceCommit() {
return (
process.env.CLUSTERFLUX_ACCEPTANCE_COMMIT ||
commandOutput("git", ["rev-parse", "HEAD"]) ||
"unknown"
);
}
function parseForgejoRepoIdentity(remote) {
if (!remote) {
return null;
}
let pathname = remote;
try {
pathname = new URL(remote).pathname;
} catch (_) {
const scpLike = /^[^@/]+@[^:]+:(.+)$/.exec(remote);
if (scpLike) {
pathname = scpLike[1];
}
}
const parts = pathname
.replace(/^\/+/, "")
.replace(/\.git$/, "")
.split("/")
.filter(Boolean);
if (parts.length < 2) {
return null;
}
return {
owner: parts[parts.length - 2],
repoName: parts[parts.length - 1],
};
}
function resolveRepoIdentity(manifest) {
if (owner && repoName) {
return;
}
const inferred = parseForgejoRepoIdentity(
manifest.public_repo_url ||
manifest.public_repo_remote ||
process.env.CLUSTERFLUX_PUBLIC_REPO_REMOTE
);
owner = owner || (inferred && inferred.owner);
repoName = repoName || (inferred && inferred.repoName);
if (!owner || !repoName) {
throw new Error(
"CLUSTERFLUX_PUBLIC_REPO_OWNER and CLUSTERFLUX_PUBLIC_REPO_NAME are required when the manifest does not contain a parseable Forgejo repository URL"
);
}
}
function publicTreeAlreadyPushed(manifest) {
return (
(manifest.public_tree_publish && manifest.public_tree_publish.pushed === true) ||
process.env.CLUSTERFLUX_PUBLIC_TREE_ALREADY_PUSHED === "1"
);
}
function publicTreeCommit(manifest) {
return (
(manifest.public_tree_publish && manifest.public_tree_publish.commit) ||
process.env.CLUSTERFLUX_PUBLIC_TREE_COMMIT ||
process.env.CLUSTERFLUX_PUBLIC_RELEASE_TARGET ||
null
);
}
function apiPath(pathname) {
return `/api/v1${pathname}`;
}
function request(method, pathname, { body, headers = {} } = {}) {
const url = new URL(apiPath(pathname), forgejoUrl);
const payload =
body === undefined
? null
: Buffer.isBuffer(body)
? body
: Buffer.from(JSON.stringify(body));
const requestHeaders = {
Accept: "application/json",
Authorization: `token ${token}`,
...headers,
};
if (payload) {
requestHeaders["Content-Length"] = payload.length;
if (!requestHeaders["Content-Type"]) {
requestHeaders["Content-Type"] = "application/json";
}
}
return new Promise((resolve, reject) => {
const req = https.request(
url,
{
method,
headers: requestHeaders,
},
(res) => {
const chunks = [];
res.on("data", (chunk) => chunks.push(chunk));
res.on("end", () => {
const text = Buffer.concat(chunks).toString("utf8");
let parsed = null;
if (text.trim()) {
try {
parsed = JSON.parse(text);
} catch (_) {
parsed = text;
}
}
if (res.statusCode < 200 || res.statusCode >= 300) {
reject(
new Error(
`${method} ${url.pathname} failed with ${res.statusCode}: ${text}`
)
);
return;
}
resolve({ status: res.statusCode, body: parsed });
});
}
);
req.on("error", reject);
if (payload) req.write(payload);
req.end();
});
}
function multipartFile(fieldName, file) {
const boundary = `clusterflux-${Date.now()}-${Math.random().toString(16).slice(2)}`;
const name = path.basename(file);
const header = Buffer.from(
`--${boundary}\r\n` +
`Content-Disposition: form-data; name="${fieldName}"; filename="${name}"\r\n` +
"Content-Type: application/octet-stream\r\n\r\n"
);
const footer = Buffer.from(`\r\n--${boundary}--\r\n`);
return {
body: Buffer.concat([header, fs.readFileSync(file), footer]),
contentType: `multipart/form-data; boundary=${boundary}`,
};
}
async function existingRelease(tagName) {
const releases = await request(
"GET",
`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repoName)}/releases?limit=100`
);
return (releases.body || []).find((release) => release.tag_name === tagName) || null;
}
async function createOrReuseRelease(manifest) {
const tagName = manifest.release_name;
const found = await existingRelease(tagName);
if (found) {
return { release: found, created: false };
}
const targetCommitish =
publicTreeCommit(manifest) ||
"main";
const body = [
"Clusterflux public release dry run.",
"",
`Default hosted coordinator endpoint: ${manifest.default_hosted_coordinator_endpoint}`,
`DNS publication state: ${manifest.dns_publication_state}`,
`Resolver override: ${manifest.resolver_override}`,
`Public tree identity: ${manifest.public_tree_identity}`,
`Source commit: ${manifest.source_commit}`,
].join("\n");
const created = await request(
"POST",
`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repoName)}/releases`,
{
body: {
tag_name: tagName,
target_commitish: targetCommitish,
name: tagName,
body,
draft: false,
prerelease: true,
},
}
);
return { release: created.body, created: true };
}
async function loadRelease(releaseId) {
const response = await request(
"GET",
`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repoName)}/releases/${releaseId}`
);
return response.body;
}
async function uploadAsset(release, asset) {
const { body, contentType } = multipartFile("attachment", asset.file);
const response = await request(
"POST",
`/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repoName)}/releases/${release.id}/assets?name=${encodeURIComponent(asset.name)}`,
{
body,
headers: {
"Content-Type": contentType,
},
}
);
return response.body;
}
function existingAssetByName(release, name) {
return Array.isArray(release.assets)
? release.assets.find((asset) => asset.name === name) || null
: null;
}
async function main() {
requireEnv("CLUSTERFLUX_FORGEJO_TOKEN", token);
if (!fs.existsSync(manifestPath)) {
throw new Error(`missing public release manifest: ${manifestPath}`);
}
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
resolveRepoIdentity(manifest);
if (manifest.kind !== "clusterflux-public-release-dryrun") {
throw new Error(`unexpected public release manifest kind: ${manifest.kind}`);
}
if (manifest.source_commit !== expectedSourceCommit()) {
throw new Error(
"public release manifest is stale; regenerate it for the current acceptance commit before publishing the Forgejo Release"
);
}
if (
!publicTreeAlreadyPushed(manifest)
) {
throw new Error(
"public tree must be pushed before publishing the Forgejo Release; run prepare-public-release-dryrun.js with CLUSTERFLUX_PUBLISH_PUBLIC_TREE=1"
);
}
if (!Array.isArray(manifest.assets) || manifest.assets.length === 0) {
throw new Error("public release manifest has no assets");
}
const { release: releaseResult, created } = await createOrReuseRelease(manifest);
const release = await loadRelease(releaseResult.id);
const uploaded = [];
const reused = [];
for (const asset of manifest.assets) {
if (!fs.existsSync(asset.file)) {
throw new Error(`missing release asset: ${asset.file}`);
}
const existing = existingAssetByName(release, asset.name);
if (existing) {
reused.push(existing);
continue;
}
uploaded.push(await uploadAsset(release, asset));
}
fs.mkdirSync(path.dirname(reportPath), { recursive: true });
const report = {
kind: "clusterflux-public-release-dryrun-forgejo-release",
forgejo_url: forgejoUrl,
owner,
repo: repoName,
release_id: release.id,
release_name: release.name || manifest.release_name,
tag_name: release.tag_name || manifest.release_name,
release_created: created,
default_hosted_coordinator_endpoint: manifest.default_hosted_coordinator_endpoint,
public_tree_identity: manifest.public_tree_identity,
public_tree_commit: publicTreeCommit(manifest),
source_commit: manifest.source_commit,
uploaded_assets: uploaded.map((asset) => ({
id: asset.id,
name: asset.name,
size: asset.size,
browser_download_url: asset.browser_download_url,
})),
reused_assets: reused.map((asset) => ({
id: asset.id,
name: asset.name,
size: asset.size,
browser_download_url: asset.browser_download_url,
})),
};
fs.writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`);
console.log(
JSON.stringify(
{ report: reportPath, uploaded: uploaded.length, reused: reused.length },
null,
2
)
);
}
main().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

154
scripts/quic-smoke.js Executable file
View file

@ -0,0 +1,154 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const net = require("net");
const path = require("path");
const { coordinatorWireRequest } = require("./coordinator-wire");
const repo = path.resolve(__dirname, "..");
function waitForJsonLine(child) {
return new Promise((resolve, reject) => {
let buffer = "";
child.stdout.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
try {
resolve(JSON.parse(buffer.slice(0, newline).trim()));
} catch (error) {
reject(error);
}
});
child.once("exit", (code) => {
reject(new Error(`process exited before JSON line with code ${code}`));
});
});
}
function send(addr, message) {
return new Promise((resolve, reject) => {
const socket = net.connect(addr.port, addr.host, () => {
socket.write(`${JSON.stringify(coordinatorWireRequest(message))}\n`);
});
let buffer = "";
socket.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
socket.end();
try {
resolve(JSON.parse(buffer.slice(0, newline)));
} catch (error) {
reject(error);
}
});
socket.on("error", reject);
});
}
function rendezvousRequest(overrides = {}) {
return {
type: "request_rendezvous",
scope: {
tenant: "tenant",
project: "project",
process: "vp-quic",
object: { Artifact: "quic-artifact" },
authorization_subject: "node-a-to-node-b",
},
source: {
node: "node-a",
advertised_addr: "node-a.mesh.invalid:4433",
public_key_fingerprint: "sha256:node-a-public-key",
},
destination: {
node: "node-b",
advertised_addr: "node-b.mesh.invalid:4433",
public_key_fingerprint: "sha256:node-b-public-key",
},
direct_connectivity: true,
failure_reason: "",
...overrides,
};
}
(async () => {
const output = cp.execFileSync(
"cargo",
["run", "-q", "-p", "clusterflux-node", "--bin", "clusterflux-quic-smoke"],
{ cwd: repo, encoding: "utf8" }
);
const report = JSON.parse(output.trim().split("\n").at(-1));
assert.strictEqual(report.kind, "clusterflux_quic_smoke");
assert.strictEqual(report.transport, "NativeQuic");
assert.strictEqual(report.rust_native_quic, true);
assert.strictEqual(report.authenticated_direct_connection, true);
assert.strictEqual(report.coordinator_assisted_rendezvous, true);
assert.strictEqual(report.coordinator_bulk_relay_allowed, false);
assert.strictEqual(report.source_node, "node-a");
assert.strictEqual(report.destination_node, "node-b");
assert.strictEqual(report.scope.tenant, "tenant");
assert.strictEqual(report.scope.project, "project");
assert.strictEqual(report.scope.process, "vp-quic");
assert.deepStrictEqual(report.scope.object, { Artifact: "quic-artifact" });
assert.ok(report.authorization_digest.startsWith("sha256:"));
assert.ok(report.request_bytes > 0);
assert.strictEqual(report.server_received_request_bytes, report.request_bytes);
assert.ok(report.payload_bytes > 0);
const coordinator = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"--",
"--listen",
"127.0.0.1:0",
"--allow-local-trusted-loopback",
],
{ cwd: repo }
);
try {
const ready = await waitForJsonLine(coordinator);
const [host, portText] = ready.listen.split(":");
const addr = { host, port: Number(portText) };
const plan = await send(addr, rendezvousRequest());
assert.strictEqual(plan.type, "rendezvous_plan");
assert.strictEqual(plan.charged_rendezvous_attempts, 1);
assert.strictEqual(plan.plan.transport, "NativeQuic");
assert.strictEqual(plan.plan.scope.tenant, "tenant");
assert.strictEqual(plan.plan.scope.project, "project");
assert.strictEqual(plan.plan.source.node, "node-a");
assert.strictEqual(plan.plan.destination.node, "node-b");
assert.strictEqual(plan.plan.coordinator_assisted_rendezvous, true);
assert.strictEqual(plan.plan.coordinator_bulk_relay_allowed, false);
assert.ok(plan.plan.authorization_digest.startsWith("sha256:"));
const failed = await send(
addr,
rendezvousRequest({
direct_connectivity: false,
failure_reason: "nat traversal failed",
})
);
assert.strictEqual(failed.type, "error");
assert.match(failed.message, /nat traversal failed/);
assert.match(failed.message, /coordinator bulk relay is disabled/);
} finally {
coordinator.kill("SIGTERM");
}
console.log("QUIC smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

View file

@ -0,0 +1,230 @@
const assert = require("assert");
const cp = require("child_process");
const net = require("net");
const path = require("path");
const { coordinatorWireRequest } = require("./coordinator-wire");
const { configurePodmanTestEnvironment } = require("./podman-test-env");
const repo = path.resolve(__dirname, "..");
const project = path.join(repo, "examples/launch-build-demo");
function waitForJsonLine(child) {
return new Promise((resolve, reject) => {
let buffer = "";
let stderr = "";
child.stdout.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
try {
resolve(JSON.parse(buffer.slice(0, newline).trim()));
} catch (error) {
reject(error);
}
});
child.stderr?.on("data", (chunk) => {
stderr += chunk.toString();
if (stderr.length > 4096) stderr = stderr.slice(-4096);
});
child.once("exit", (code) => {
const detail = stderr.trim();
reject(new Error(
`process exited before JSON line with code ${code}${detail ? `: ${detail}` : ""}`
));
});
});
}
function send(addr, message) {
return new Promise((resolve, reject) => {
const socket = net.connect(addr.port, addr.host, () => {
socket.write(`${JSON.stringify(coordinatorWireRequest(message))}\n`);
});
let buffer = "";
socket.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
socket.end();
try {
resolve(JSON.parse(buffer.slice(0, newline)));
} catch (error) {
reject(error);
}
});
socket.on("error", reject);
});
}
function configureContainerPolicyHome() {
configurePodmanTestEnvironment(repo);
}
function commandWithPodman(program, args) {
if (cp.spawnSync("podman", ["--version"], { stdio: "ignore" }).status === 0) {
return { program, args };
}
if (cp.spawnSync("nix", ["--version"], { stdio: "ignore" }).status === 0) {
return {
program: "nix",
args: ["shell", "nixpkgs#podman", "--command", program, ...args],
};
}
throw new Error(
"real flagship smoke requires rootless Podman (or Nix to provide it)"
);
}
function ensureRootlessPodman() {
configureContainerPolicyHome();
const invocation = commandWithPodman("podman", [
"info",
"--format",
"{{.Host.Security.Rootless}}",
]);
const rootless = cp.execFileSync(invocation.program, invocation.args, {
cwd: repo,
env: process.env,
encoding: "utf8",
}).trim();
assert.strictEqual(rootless, "true", "flagship worker must use rootless Podman");
}
async function runFlagshipWorker(addr, node, identity) {
const enrollment = await send(addr, {
type: "create_node_enrollment_grant",
tenant: "tenant",
project: "project",
actor_user: "user",
ttl_seconds: 60,
});
assert.strictEqual(enrollment.type, "node_enrollment_grant_created");
const cargoArgs = [
"run", "-q", "-p", "clusterflux-node", "--bin", "clusterflux-node", "--",
"--coordinator", `${addr.host}:${addr.port}`,
"--tenant", "tenant",
"--project-id", "project",
"--node", node,
"--enrollment-grant", enrollment.grant,
"--worker",
"--emit-ready",
"--project-root", project,
"--assignment-poll-ms", "25",
];
const invocation = commandWithPodman("cargo", cargoArgs);
const child = cp.spawn(invocation.program, invocation.args, {
cwd: repo,
env: {
...process.env,
CLUSTERFLUX_NODE_PRIVATE_KEY: identity.privateKey,
},
});
return { child, ready: waitForJsonLine(child) };
}
const delay = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
async function waitForTaskEvent(addr, process, predicate, description) {
for (let attempt = 0; attempt < 2400; attempt += 1) {
const response = await send(addr, {
type: "list_task_events",
tenant: "tenant",
project: "project",
actor_user: "user",
process,
});
assert.strictEqual(response.type, "task_events", JSON.stringify(response));
const event = response.events.find(predicate);
if (event) return event;
await delay(25);
}
throw new Error(`timed out waiting for real Wasm task ${description}`);
}
function startFlagship(addr) {
const report = JSON.parse(
cp.execFileSync(
"cargo",
[
"run", "-q", "-p", "clusterflux-cli", "--bin", "clusterflux", "--",
"run", "build",
"--coordinator", `clusterflux+tcp://${addr.host}:${addr.port}`,
"--project", project,
"--json",
],
{ cwd: repo, env: process.env, encoding: "utf8" }
)
);
assert.strictEqual(report.command, "run");
assert.strictEqual(report.status, "main_launched", JSON.stringify(report));
assert.strictEqual(report.entry, "build");
assert.strictEqual(report.task_launch.type, "main_launched");
assert.strictEqual(report.task_launch.task_instance, report.task_instance);
assert.strictEqual(report.task_launch.task_definition, report.task_definition);
assert.strictEqual(report.worker_placement_requested, true);
assert.match(report.bundle_digest, /^sha256:[0-9a-f]{64}$/);
assert.match(report.entry_export, /^clusterflux_entry_v1_/);
const virtualProcess = report.process;
return { report, process: virtualProcess };
}
async function launchFlagship(addr) {
const { report, process: virtualProcess } = startFlagship(addr);
const compileEvent = await waitForTaskEvent(
addr,
virtualProcess,
(event) => event.task_definition === "compile_linux",
"compile_linux"
);
const packageEvent = await waitForTaskEvent(
addr,
virtualProcess,
(event) => event.task_definition === "package_release",
"package_release"
);
const buildEvent = await waitForTaskEvent(
addr,
virtualProcess,
(event) => event.task === report.task_instance && event.executor === "coordinator_main",
"coordinator build main"
);
for (const event of [compileEvent, packageEvent, buildEvent]) {
assert.strictEqual(event.terminal_state, "completed", JSON.stringify(event));
}
return {
report,
process: virtualProcess,
compileEvent,
packageEvent,
buildEvent,
};
}
function flagshipNodeCapabilities() {
return {
os: "Linux",
arch: process.arch,
capabilities: [
"Command",
"Containers",
"RootlessPodman",
"SourceFilesystem",
"VfsArtifacts",
],
environment_backends: ["Container"],
source_providers: ["filesystem"],
};
}
module.exports = {
ensureRootlessPodman,
flagshipNodeCapabilities,
launchFlagship,
project,
repo,
runFlagshipWorker,
send,
startFlagship,
waitForTaskEvent,
waitForJsonLine,
};

73
scripts/release-source-scan.sh Executable file
View file

@ -0,0 +1,73 @@
#!/usr/bin/env bash
set -euo pipefail
repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo"
release_paths=(
Cargo.toml
Cargo.lock
README.md
crates
examples
private
scripts
vscode-extension
)
existing_release_paths=()
for path in "${release_paths[@]}"; do
if [[ -e "$path" ]]; then
existing_release_paths+=("$path")
fi
done
prose_scan_paths=(
README.md
crates
examples
private
scripts
vscode-extension
)
existing_prose_scan_paths=()
for path in "${prose_scan_paths[@]}"; do
if [[ -e "$path" ]]; then
existing_prose_scan_paths+=("$path")
fi
done
scan_globs=(
--glob '!**/target/**'
--glob '!**/node_modules/**'
--glob '!scripts/release-source-scan.sh'
--glob '!scripts/rename-to-clusterflux.sh'
--glob '!scripts/check-docs.js'
)
placeholder_pattern='debugger-gate|experiments/debugger-gate|CLUSTERFLUX-DEMO|device-code-placeholder|artifact://demo|vp-local-demo'
if rg -n "${scan_globs[@]}" "$placeholder_pattern" "${existing_release_paths[@]}"; then
echo "release source scan failed: stale experiment/demo placeholder reference found" >&2
exit 1
fi
demo_setup_pattern='undocumented manual state|hidden setup|demo-only credentials?|hard-coded local paths?'
if rg -n "${scan_globs[@]}" "$demo_setup_pattern" "${existing_prose_scan_paths[@]}"; then
echo "release source scan failed: demo requires hidden setup or demo-only state" >&2
exit 1
fi
hidden_local_pattern='file://|/home/[[:alnum:]_.-]+/|/Users/[[:alnum:]_.-]+/|C:\\Users\\|https?://(localhost|127\.0\.0\.1)[^[:space:]]*/artifacts/'
if rg -n "${scan_globs[@]}" "$hidden_local_pattern" "${existing_release_paths[@]}"; then
echo "release source scan failed: hidden local path or local artifact URL found" >&2
exit 1
fi
public_wording_pattern='reddit|hacker news|lobsters|launch forum|traffic source|free tier'
if rg -n "${scan_globs[@]}" "$public_wording_pattern" "${existing_prose_scan_paths[@]}"; then
echo "release source scan failed: public-facing launch-forum/free-tier wording found" >&2
exit 1
fi
echo "Release source scan passed"

View file

@ -0,0 +1,81 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
excluded_dirs=(
.git
target
node_modules
vendor
.direnv
.cache
dist
out
)
find_expression=()
for directory in "${excluded_dirs[@]}"; do
if ((${#find_expression[@]})); then
find_expression+=( -o )
fi
find_expression+=( -name "$directory" )
done
mapfile -d '' rename_paths < <(
find . \
\( -type d \( "${find_expression[@]}" \) -prune \) -o \
\( -name '*disasmer*' -o -name '*Disasmer*' -o -name '*DISASMER*' \) -print0
)
for ((index=${#rename_paths[@]} - 1; index >= 0; index--)); do
path="${rename_paths[$index]}"
parent="$(dirname "$path")"
name="$(basename "$path")"
renamed="${name//DISASMER/CLUSTERFLUX}"
renamed="${renamed//Disasmer/Clusterflux}"
renamed="${renamed//disasmer/clusterflux}"
destination="$parent/$renamed"
if [[ "$path" != "$destination" ]]; then
if [[ -e "$destination" ]]; then
printf 'rename destination already exists: %s\n' "$destination" >&2
exit 1
fi
mv -- "$path" "$destination"
fi
done
rg_args=(
--files-with-matches
--null
--hidden
--glob '!**/.git/**'
--glob '!**/target/**'
--glob '!**/node_modules/**'
--glob '!**/vendor/**'
--glob '!**/.direnv/**'
--glob '!**/.cache/**'
--glob '!**/dist/**'
--glob '!**/out/**'
--glob '!scripts/rename-to-clusterflux.sh'
--glob '!scripts/migrate-clusterflux-state.sh'
--glob '!internal/finish_mvp.md'
)
while IFS= read -r -d '' file; do
perl -0pi -e 's/DISASMER/CLUSTERFLUX/g; s/Disasmer/Clusterflux/g; s/disasmer/clusterflux/g' "$file"
done < <(rg "${rg_args[@]}" 'DISASMER|Disasmer|disasmer' . || true)
rm -f Cargo.lock private/hosted-policy/Cargo.lock experiments/debugger-gate/Cargo.lock
cargo generate-lockfile
cargo generate-lockfile --manifest-path private/hosted-policy/Cargo.toml
cargo generate-lockfile --manifest-path experiments/debugger-gate/Cargo.toml
for package in vscode-extension experiments/debugger-gate/vscode-extension; do
if [[ -f "$package/package-lock.json" ]]; then
npm install --package-lock-only --ignore-scripts --prefix "$package"
fi
done
printf 'Clusterflux rename applied. Rerunning this script is a no-op apart from lockfile regeneration.\n'

View file

@ -0,0 +1,200 @@
#!/usr/bin/env node
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const repo = path.resolve(__dirname, "..");
function read(relativePath) {
return fs.readFileSync(path.join(repo, relativePath), "utf8");
}
function maybeRead(segments) {
const fullPath = path.join(repo, ...segments);
if (!fs.existsSync(fullPath)) return null;
return fs.readFileSync(fullPath, "utf8");
}
function expect(source, name, pattern) {
assert.match(source, pattern, `missing resource metering evidence: ${name}`);
}
const coreLimits = read("crates/clusterflux-core/src/limits.rs");
// Phase 3 keeps the protocol dispatch in service.rs and the metered operation
// implementations in focused service modules. Read the complete relevant
// boundary so this contract follows the refactor instead of one mega-file.
const coordinatorService = [
read("crates/clusterflux-coordinator/src/service.rs"),
read("crates/clusterflux-coordinator/src/service/routing.rs"),
read("crates/clusterflux-coordinator/src/service/processes.rs"),
read("crates/clusterflux-coordinator/src/service/process_launch.rs"),
read("crates/clusterflux-coordinator/src/service/artifacts.rs"),
].join("\n");
const coordinatorQuota = read("crates/clusterflux-coordinator/src/service/quota.rs");
const coordinatorLogs = read("crates/clusterflux-coordinator/src/service/logs.rs");
const coordinatorDebug = read("crates/clusterflux-coordinator/src/service/debug.rs");
const coordinatorTests = read("crates/clusterflux-coordinator/src/service/tests.rs");
const artifactDownloadSmoke = read("scripts/artifact-download-smoke.js");
const operatorPanelSmoke = read("scripts/operator-panel-smoke.js");
const quicSmoke = read("scripts/quic-smoke.js");
for (const [name, pattern] of [
["API call limit kind", /\bApiCall,/],
["spawn limit kind", /\bSpawn,/],
["log bytes limit kind", /\bLogBytes,/],
["metadata bytes limit kind", /\bMetadataBytes,/],
["debug read bytes limit kind", /\bDebugReadBytes,/],
["UI event limit kind", /\bUiEvent,/],
["rendezvous attempt limit kind", /\bRendezvousAttempt,/],
["artifact download bytes limit kind", /\bArtifactDownloadBytes,/],
["hosted fuel limit kind", /\bHostedFuel,/],
[
"preflight can check without consuming",
/pub fn can_charge\([\s\S]*used\.saturating_add\(amount\) > limit/,
],
[
"charge goes through preflight",
/pub fn charge\([\s\S]*self\.can_charge\(limits, kind, amount\)\?/,
],
]) {
expect(coreLimits, name, pattern);
}
for (const [name, pattern] of [
[
"rendezvous charges before transport planning",
/handle_request_rendezvous[\s\S]*charge_rendezvous_attempt\([\s\S]*&scope\.tenant[\s\S]*&scope\.project[\s\S]*now_epoch_seconds[\s\S]*plan_authenticated_direct_bulk_transfer/,
],
[
"artifact link creation preflights downloadable bytes before link creation",
/handle_create_artifact_download_link[\s\S]*downloadable_size[\s\S]*can_charge_download\([\s\S]*&context\.tenant[\s\S]*&context\.project[\s\S]*downloadable_size[\s\S]*create_download_link/,
],
[
"artifact delivery charges scoped bytes before advancing its offset",
/handle_open_artifact_download_stream[\s\S]*stream_download_chunk\([\s\S]*charge_download\([\s\S]*&context\.tenant[\s\S]*&context\.project[\s\S]*streamed_bytes[\s\S]*delivered_offset = end/,
],
]) {
expect(coordinatorService, name, pattern);
}
for (const [name, pattern] of [
[
"quota keys include tenant/project resource kind and window",
/struct ProjectQuotaScope[\s\S]*tenant: TenantId[\s\S]*project: ProjectId[\s\S]*struct MeterKey[\s\S]*kind: LimitKind[\s\S]*window: u64/,
],
[
"quota module discards expired windows for an accessed scope and kind",
/fn meter_mut[\s\S]*self\.meters\.retain[\s\S]*existing\.scope != key\.scope[\s\S]*existing\.kind != kind[\s\S]*existing\.window == key\.window/,
],
[
"quota module charges rendezvous attempts through the scoped window meter",
/fn charge_rendezvous_attempt[\s\S]*self\.charge\([\s\S]*tenant[\s\S]*project[\s\S]*LimitKind::RendezvousAttempt/,
],
[
"quota module charges authenticated API calls through the scoped window meter",
/fn charge_api_call[\s\S]*self\.charge\(tenant, project, LimitKind::ApiCall, 1, now_epoch_seconds\)/,
],
[
"quota module preflights and charges log bytes through the scoped window meter",
/fn can_charge_log_bytes[\s\S]*LimitKind::LogBytes[\s\S]*fn charge_log_bytes[\s\S]*LimitKind::LogBytes/,
],
[
"quota module preflights artifact download bytes through the scoped meter",
/fn can_charge_download[\s\S]*self\.can_charge\([\s\S]*tenant[\s\S]*project[\s\S]*LimitKind::ArtifactDownloadBytes/,
],
[
"quota status reports current scoped window usage",
/fn project_status[\s\S]*for kind in LimitKind::ALL[\s\S]*self\.used\(tenant, project, kind, now_epoch_seconds\)/,
],
]) {
expect(coordinatorQuota, name, pattern);
}
for (const [source, name, pattern] of [
[
coordinatorService,
"authenticated API calls are charged after session authorization and before dispatch",
/authenticate_cli_session[\s\S]*authorize_authenticated_user_operation[\s\S]*charge_api_call[\s\S]*match request/,
],
[
coordinatorLogs,
"signed node log ingestion preflights and charges bytes before accepting the report",
/handle_report_task_log[\s\S]*authorize_node_for_process_or_termination[\s\S]*can_charge_log_bytes[\s\S]*charge_log_bytes[\s\S]*TaskLogRecorded/,
],
[
coordinatorDebug,
"debug reads charge the scoped debug-read budget before audit state is recorded",
/record_debug_audit_event[\s\S]*charge_debug_read[\s\S]*DebugAuditEvent/,
],
[
coordinatorTests,
"tests prove API-call and log-byte quota enforcement and project isolation",
/authenticated_api_calls_are_metered_per_tenant_and_project_before_dispatch[\s\S]*project-a[\s\S]*project-b[\s\S]*signed_node_log_ingestion_checks_scoped_quota_before_accepting_bytes[\s\S]*LogBytes/,
],
]) {
expect(source, name, pattern);
}
for (const [name, source, patterns] of [
[
"rendezvous smoke",
quicSmoke,
[/charged_rendezvous_attempts, 1/, /coordinator bulk relay is disabled/],
],
[
"artifact download smoke",
artifactDownloadSmoke,
[
/downloaded\.response\.charged_download_bytes,[\s\S]*packageEvent\.artifact_size_bytes/,
/retaining_node_reverse_stream/,
/revoked/,
],
],
[
"operator panel smoke",
operatorPanelSmoke,
[
/type: "submit_panel_event"/,
/max_events: 1/,
/used_events, 1/,
/rate limit/i,
/max_download_bytes: 1/,
/exceeds download limit/,
],
],
]) {
for (const pattern of patterns) {
expect(source, name, pattern);
}
}
const privateHostedLibSource = maybeRead(["private", "hosted-policy", "src", "lib.rs"]);
const privateHostedTests = maybeRead(["private", "hosted-policy", "src", "tests.rs"]);
const privateHostedLib = privateHostedLibSource
? [privateHostedLibSource, privateHostedTests].filter(Boolean).join("\n")
: null;
if (privateHostedLib) {
for (const [name, pattern] of [
[
"private hosted configuration owns exact limits and quota windows",
/community_tier_resource_limits[\s\S]*LimitKind::ApiCall[\s\S]*LimitKind::HostedFuel[\s\S]*community_tier_quota_configuration[\s\S]*CoordinatorQuotaConfiguration::new/,
],
[
"hosted zero-capability Wasm budget preflight is atomic across every resource kind",
/preflight_zero_capability_hosted_wasm\([\s\S]*let mut trial_meter = meter\.clone\(\)[\s\S]*LimitKind::HostedFuel[\s\S]*LimitKind::HostedMemoryBytes[\s\S]*LimitKind::HostedWallClockMs[\s\S]*LimitKind::HostedStateBytes[\s\S]*LimitKind::LogBytes[\s\S]*LimitKind::MetadataBytes[\s\S]*LimitKind::UiEvent[\s\S]*LimitKind::ApiCall[\s\S]*\*meter = trial_meter/,
],
[
"hosted tests cover each zero-capability Wasm budget",
/hosted_zero_capability_wasm_preflight_rejects_each_budget_over_limit\([\s\S]*LimitKind::HostedFuel[\s\S]*LimitKind::LogBytes[\s\S]*LimitKind::MetadataBytes[\s\S]*LimitKind::UiEvent[\s\S]*LimitKind::ApiCall/,
],
[
"hosted tests prove tenant/project quota isolation",
/hosted_resource_usage_is_isolated_by_tenant_and_project\([\s\S]*project-a[\s\S]*project-b[\s\S]*HostedFuel/,
],
]) {
expect(privateHostedLib, name, pattern);
}
}
console.log("Resource metering contract smoke passed");

View file

@ -0,0 +1,407 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const crypto = require("crypto");
const fs = require("fs");
const net = require("net");
const path = require("path");
const { coordinatorWireRequest } = require("./coordinator-wire");
const { nodeIdentity, signedNodeRequest } = require("./node-signing");
const repo = path.resolve(__dirname, "..");
const digest = (value) =>
`sha256:${crypto.createHash("sha256").update(value).digest("hex")}`;
const environmentDigest = digest("scheduler-linux-container");
const dependencyDigest = digest("scheduler-toolchain-dependencies");
const sourceDigest = digest("scheduler-source-tree");
function buildFlagshipBundle() {
const output = cp.execFileSync(
"cargo",
[
"run", "-q", "-p", "clusterflux-cli", "--bin", "clusterflux", "--",
"build", "--project", "examples/launch-build-demo", "--json",
],
{ cwd: repo, encoding: "utf8" }
);
const report = JSON.parse(output);
const directory = path.resolve(repo, report.bundle_artifact.directory);
const manifest = JSON.parse(fs.readFileSync(path.join(directory, "manifest.json"), "utf8"));
const entrypoints = JSON.parse(
fs.readFileSync(path.join(directory, manifest.entrypoints), "utf8")
);
const entrypoint = entrypoints.find((candidate) => candidate.name === "build");
assert(entrypoint, "flagship bundle omitted build entrypoint");
const taskDescriptors = JSON.parse(
fs.readFileSync(path.join(directory, manifest.task_descriptors), "utf8")
);
const prepareSource = taskDescriptors.find(
(candidate) => candidate.name === "prepare_source"
);
assert(prepareSource, "flagship bundle omitted prepare_source task");
return {
digest: manifest.bundle_digest,
taskExport: prepareSource.export,
wasmModuleBase64: fs.readFileSync(path.join(directory, "module.wasm")).toString("base64"),
};
}
function waitForJsonLine(child) {
return new Promise((resolve, reject) => {
let buffer = "";
child.stdout.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
try {
resolve(JSON.parse(buffer.slice(0, newline).trim()));
} catch (error) {
reject(error);
}
});
child.once("exit", (code) => {
reject(new Error(`process exited before JSON line with code ${code}`));
});
});
}
function send(addr, message) {
return new Promise((resolve, reject) => {
const socket = net.connect(addr.port, addr.host, () => {
socket.write(`${JSON.stringify(coordinatorWireRequest(message))}\n`);
});
let buffer = "";
socket.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
socket.end();
try {
resolve(JSON.parse(buffer.slice(0, newline)));
} catch (error) {
reject(error);
}
});
socket.on("error", reject);
});
}
function linuxCapabilities() {
return {
os: "Linux",
arch: "x86_64",
capabilities: [
"Command",
"Containers",
"RootlessPodman",
"SourceFilesystem",
"VfsArtifacts"
],
environment_backends: ["Container"],
source_providers: ["filesystem"]
};
}
function gitCapabilities() {
const capabilities = linuxCapabilities();
capabilities.capabilities = [...capabilities.capabilities, "SourceGit"].sort();
capabilities.source_providers = [...capabilities.source_providers, "git"].sort();
return capabilities;
}
async function attachNode(addr, node) {
const identity = nodeIdentity("scheduler-placement-smoke", node);
const attached = await send(addr, {
type: "attach_node",
tenant: "tenant",
project: "project",
node,
public_key: identity.publicKey
});
assert.strictEqual(attached.type, "node_attached");
assert.strictEqual(attached.node, node);
return identity;
}
async function reportNode(addr, node, identity, locality) {
const recorded = await send(addr, signedNodeRequest(node, identity, "report_node_capabilities", {
type: "report_node_capabilities",
tenant: "tenant",
project: "project",
node,
capabilities: locality.capabilities || linuxCapabilities(),
cached_environment_digests: locality.cached_environment_digests,
dependency_cache_digests: locality.dependency_cache_digests,
source_snapshots: locality.source_snapshots,
artifact_locations: locality.artifact_locations,
direct_connectivity: locality.direct_connectivity !== false,
online: true
}));
assert.strictEqual(
recorded.type,
"node_capabilities_recorded",
JSON.stringify(recorded)
);
assert.strictEqual(recorded.node, node);
return recorded;
}
(async () => {
const bundle = buildFlagshipBundle();
const coordinator = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"--",
"--listen",
"127.0.0.1:0",
"--allow-local-trusted-loopback"
],
{ cwd: repo }
);
let coordinatorStderr = "";
coordinator.stderr.on("data", (chunk) => {
coordinatorStderr += chunk.toString();
});
try {
const ready = await waitForJsonLine(coordinator);
const [host, portText] = ready.listen.split(":");
const addr = { host, port: Number(portText) };
assert.strictEqual((await send(addr, { type: "ping" })).type, "pong");
const coldNode = await attachNode(addr, "cold-node");
const warmNode = await attachNode(addr, "warm-node");
const cold = await reportNode(addr, "cold-node", coldNode, {
cached_environment_digests: [],
dependency_cache_digests: [],
source_snapshots: [],
artifact_locations: [],
direct_connectivity: false
});
assert.strictEqual(cold.node_descriptors, 1);
const warm = await reportNode(addr, "warm-node", warmNode, {
cached_environment_digests: [environmentDigest],
dependency_cache_digests: [dependencyDigest],
source_snapshots: [sourceDigest],
artifact_locations: ["toolchain-cache"]
});
assert.strictEqual(warm.node_descriptors, 2);
const reportedNodes = new Set([cold.node, warm.node]);
assert.strictEqual(reportedNodes.size, 2);
assert(reportedNodes.has("cold-node"));
assert(reportedNodes.has("warm-node"));
const inspected = await send(addr, {
type: "list_node_descriptors",
tenant: "tenant",
project: "project",
actor_user: "operator"
});
assert.strictEqual(inspected.type, "node_descriptors");
assert.strictEqual(inspected.actor, "operator");
assert.strictEqual(inspected.descriptors.length, 2);
const warmDescriptor = inspected.descriptors.find(
(descriptor) => descriptor.id === "warm-node"
);
assert(warmDescriptor, "warm node descriptor must be visible to inspector state");
assert(warmDescriptor.capabilities.capabilities.includes("Command"));
assert(warmDescriptor.capabilities.capabilities.includes("RootlessPodman"));
assert(warmDescriptor.cached_environments.includes(environmentDigest));
assert(warmDescriptor.dependency_caches.includes(dependencyDigest));
assert(warmDescriptor.source_snapshots.includes(sourceDigest));
assert(warmDescriptor.artifact_locations.includes("toolchain-cache"));
const crossScopeInspection = await send(addr, {
type: "list_node_descriptors",
tenant: "other-tenant",
project: "project",
actor_user: "operator"
});
assert.strictEqual(crossScopeInspection.type, "node_descriptors");
assert.strictEqual(crossScopeInspection.descriptors.length, 0);
const crossTenantReport = await send(addr, signedNodeRequest("warm-node", warmNode, "report_node_capabilities", {
type: "report_node_capabilities",
tenant: "other-tenant",
project: "project",
node: "warm-node",
capabilities: linuxCapabilities(),
cached_environment_digests: [],
dependency_cache_digests: [],
source_snapshots: [],
artifact_locations: [],
direct_connectivity: true,
online: true
}));
assert.strictEqual(crossTenantReport.type, "error");
assert.match(crossTenantReport.message, /tenant\/project scope/);
const placement = await send(addr, {
type: "schedule_task",
tenant: "tenant",
project: "project",
environment: {
os: "Linux",
arch: null,
capabilities: ["Containers", "RootlessPodman"]
},
environment_digest: environmentDigest,
required_capabilities: ["Command"],
dependency_cache: dependencyDigest,
source_snapshot: sourceDigest,
required_artifacts: ["toolchain-cache"],
prefer_node: null
});
assert.strictEqual(placement.type, "task_placement");
assert.strictEqual(placement.placement.node, "warm-node");
assert.ok(placement.placement.score > 0);
assert.ok(placement.placement.reasons.includes("warm environment cache"));
assert.ok(placement.placement.reasons.includes("warm dependency cache"));
assert.ok(placement.placement.reasons.includes("source snapshot already local"));
assert.ok(
placement.placement.reasons.includes("1 required artifact(s) already local")
);
const impossible = await send(addr, {
type: "schedule_task",
tenant: "tenant",
project: "project",
environment: null,
environment_digest: null,
required_capabilities: ["WindowsCommandDev"],
dependency_cache: null,
source_snapshot: null,
required_artifacts: [],
prefer_node: null
});
assert.strictEqual(impossible.type, "error");
assert.match(impossible.message, /WindowsCommandDev/);
const started = await send(addr, {
type: "start_process",
tenant: "tenant",
project: "project",
actor_user: "operator",
process: "vp-wait-for-git"
});
assert.strictEqual(started.type, "process_started");
const queued = await send(addr, {
type: "launch_task",
tenant: "tenant",
project: "project",
actor_user: "operator",
task_spec: {
tenant: "tenant",
project: "project",
process: "vp-wait-for-git",
task_definition: "prepare_source",
task_instance: "prepare_source-1",
dispatch: {
kind: "coordinator_node_wasm",
export: bundle.taskExport,
abi: "task_v1",
},
environment_id: null,
environment: null,
environment_digest: null,
required_capabilities: ["SourceFilesystem", "SourceGit"],
dependency_cache: null,
source_snapshot: null,
required_artifacts: [],
args: [],
vfs_epoch: started.epoch,
bundle_digest: bundle.digest,
},
wait_for_node: true,
artifact_path: "/vfs/artifacts/git-status.txt",
wasm_module_base64: bundle.wasmModuleBase64,
});
assert.strictEqual(queued.type, "task_queued");
assert.strictEqual(queued.process, "vp-wait-for-git");
assert.strictEqual(queued.task, "prepare_source-1");
assert.match(queued.reason, /SourceGit/);
assert.strictEqual(queued.queued_tasks, 1);
const gitNode = await attachNode(addr, "git-node");
const gitRecorded = await reportNode(addr, "git-node", gitNode, {
capabilities: gitCapabilities(),
cached_environment_digests: [],
dependency_cache_digests: [],
source_snapshots: [],
artifact_locations: [],
direct_connectivity: false
});
assert.strictEqual(gitRecorded.type, "node_capabilities_recorded");
const pendingAssignment = await send(addr, signedNodeRequest("git-node", gitNode, "poll_task_assignment", {
type: "poll_task_assignment",
tenant: "tenant",
project: "project",
node: "git-node"
}));
assert.strictEqual(pendingAssignment.type, "task_assignment");
assert(pendingAssignment.assignment, "late capable node should receive queued assignment");
assert.strictEqual(pendingAssignment.assignment.process, "vp-wait-for-git");
assert.strictEqual(pendingAssignment.assignment.task, "prepare_source-1");
assert.strictEqual(pendingAssignment.assignment.node, "git-node");
assert.strictEqual(
pendingAssignment.assignment.task_spec.dispatch.export,
bundle.taskExport
);
const emptyAssignment = await send(addr, signedNodeRequest("git-node", gitNode, "poll_task_assignment", {
type: "poll_task_assignment",
tenant: "tenant",
project: "project",
node: "git-node"
}));
assert.strictEqual(emptyAssignment.type, "task_assignment");
assert.strictEqual(emptyAssignment.assignment, null);
await reportNode(addr, "warm-node", warmNode, {
cached_environment_digests: [],
dependency_cache_digests: [],
source_snapshots: [],
artifact_locations: [],
direct_connectivity: false
});
const disconnectedTransfer = await send(addr, {
type: "schedule_task",
tenant: "tenant",
project: "project",
environment: null,
environment_digest: null,
required_capabilities: ["Command"],
dependency_cache: null,
source_snapshot: sourceDigest,
required_artifacts: ["toolchain-cache"],
prefer_node: null
});
assert.strictEqual(disconnectedTransfer.type, "error");
assert.match(disconnectedTransfer.message, /source snapshot unavailable/);
assert.match(disconnectedTransfer.message, /required artifact\(s\) unavailable/);
assert.match(disconnectedTransfer.message, /direct connectivity unavailable/);
} catch (error) {
if (coordinatorStderr) {
error.message = `${error.message}\ncoordinator stderr:\n${coordinatorStderr}`;
}
throw error;
} finally {
coordinator.kill("SIGTERM");
}
console.log("Scheduler placement smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

View file

@ -0,0 +1,49 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const fs = require("fs");
const path = require("path");
const repo = path.resolve(__dirname, "..");
const sdk = fs.readFileSync(path.join(repo, "crates/clusterflux-sdk/src/lib.rs"), "utf8");
const productRuntime = fs.readFileSync(
path.join(repo, "crates/clusterflux-sdk/src/sdk_runtime.rs"),
"utf8"
);
assert.match(sdk, /pub struct RuntimeSpawnEvent/);
assert.match(sdk, /pub debugger_visible: bool/);
assert.match(sdk, /fn register_runtime_thread/);
assert.match(sdk, /register_runtime_thread\(id, self\.name, self\.env\)/);
assert.match(sdk, /pub fn debugger_visible\(&self\) -> bool/);
assert.match(sdk, /ProductRuntimeConfig::from_env\(\)/);
assert.match(sdk, /start_remote_task\(\s*config,\s*task_id/);
assert.match(sdk, /start_guest_host_task/);
assert.match(sdk, /join_remote_task\(remote\)/);
assert.match(productRuntime, /let spec = TaskSpec \{/);
assert.match(productRuntime, /CoordinatorNodeWasm/);
assert.match(productRuntime, /task_start_v1/);
assert.match(productRuntime, /task_join_v1/);
assert.match(productRuntime, /command_run_v1/);
assert.match(productRuntime, /"task_spec": spec/);
assert.match(productRuntime, /remote_completion_observed/);
assert.match(productRuntime, /TaskJoinState::Pending/);
assert.doesNotMatch(
productRuntime,
/entry\s*\(/,
"product runtime must not invoke the submitted local Rust closure"
);
cp.execFileSync(
"cargo",
[
"test",
"-p",
"clusterflux-sdk",
"spawn_task_start_registers_debugger_visible_runtime_thread",
],
{ cwd: repo, stdio: "inherit" }
);
console.log("SDK spawn runtime smoke passed");

View file

@ -0,0 +1,717 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const crypto = require("crypto");
const fs = require("fs");
const net = require("net");
const path = require("path");
const { coordinatorWireRequest } = require("./coordinator-wire");
const repo = path.resolve(__dirname, "..");
const teamArtifactDigest = `sha256:${"a".repeat(64)}`;
const teamEnvironmentDigest = `sha256:${crypto
.createHash("sha256")
.update("env-team-linux")
.digest("hex")}`;
const teamDependencyCacheDigest = `sha256:${crypto
.createHash("sha256")
.update("cargo-cache")
.digest("hex")}`;
const teamSourceDigest = `sha256:${crypto
.createHash("sha256")
.update("source-team")
.digest("hex")}`;
const coordinatorTaskModule = Buffer.from([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
const coordinatorTaskBundleDigest = `sha256:${crypto
.createHash("sha256")
.update(coordinatorTaskModule)
.digest("hex")}`;
const adminToken = "self-hosted-smoke-admin-token";
const clientSessionSecret = "self-hosted-smoke-client-session-secret";
const releaseManifestPath =
process.env.CLUSTERFLUX_PUBLIC_RELEASE_MANIFEST ||
path.join(repo, "target/public-release-dryrun/public-release-manifest.json");
function sha256(value) {
return `sha256:${crypto.createHash("sha256").update(value).digest("hex")}`;
}
function digestFromParts(parts) {
const hash = crypto.createHash("sha256");
for (const value of parts) {
const bytes = Buffer.from(String(value));
const length = Buffer.alloc(8);
length.writeBigUInt64BE(BigInt(bytes.length));
hash.update(length);
hash.update(bytes);
}
return `sha256:${hash.digest("hex")}`;
}
function adminRequest(token, operation, tenant, actorUser, targetTenant, nonce) {
const issuedAtEpochSeconds = Math.floor(Date.now() / 1000);
return {
type: operation,
tenant,
actor_user: actorUser,
...(operation === "suspend_tenant" ? { target_tenant: targetTenant } : {}),
admin_proof: digestFromParts([
"clusterflux-admin-request-proof:v1",
sha256(token),
operation,
tenant,
actorUser,
targetTenant,
nonce,
issuedAtEpochSeconds,
]),
admin_nonce: nonce,
issued_at_epoch_seconds: issuedAtEpochSeconds,
};
}
function waitForJsonLine(child) {
return new Promise((resolve, reject) => {
let buffer = "";
child.stdout.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
try {
resolve(JSON.parse(buffer.slice(0, newline).trim()));
} catch (error) {
reject(error);
}
});
child.once("exit", (code) => {
reject(new Error(`process exited before JSON line with code ${code}`));
});
});
}
function send(addr, message) {
return new Promise((resolve, reject) => {
const socket = net.connect(addr.port, addr.host, () => {
socket.write(`${JSON.stringify(coordinatorWireRequest(message))}\n`);
});
let buffer = "";
socket.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
socket.end();
try {
resolve(JSON.parse(buffer.slice(0, newline)));
} catch (error) {
reject(error);
}
});
socket.on("error", reject);
});
}
function authenticated(request, sessionSecret = clientSessionSecret) {
return {
type: "authenticated",
session_secret: sessionSecret,
request,
};
}
function linuxNodeCapabilities() {
return {
os: "Linux",
arch: "x86_64",
capabilities: ["Command", "RootlessPodman", "VfsArtifacts", "QuicDirect"],
environment_backends: ["Container"],
source_providers: ["filesystem", "git"]
};
}
function nodeIdentity(node) {
void node;
const { privateKey: privateKeyObject, publicKey } =
crypto.generateKeyPairSync("ed25519");
const publicDer = publicKey.export({
format: "der",
type: "spki",
});
return {
publicKey: `ed25519:${Buffer.from(publicDer).subarray(-32).toString("base64")}`,
privateKeyObject,
};
}
function signedRequestPayloadDigest(request) {
const canonicalize = (value, topLevel = true) => {
if (Array.isArray(value)) return value.map((entry) => canonicalize(entry, false));
if (value && typeof value === "object") {
return Object.fromEntries(
Object.entries(value)
.filter(
([key, entry]) =>
entry !== null &&
(!topLevel || !["agent_signature", "node_signature"].includes(key))
)
.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
.map(([key, entry]) => [key, canonicalize(entry, false)])
);
}
return value;
};
return `sha256:${crypto
.createHash("sha256")
.update(JSON.stringify(canonicalize(request)))
.digest("hex")}`;
}
function nodeSignatureMessage(
node,
requestKind,
payloadDigest,
nonce,
issuedAtEpochSeconds
) {
const parts = [
"clusterflux-node-request-signature:v2",
node,
requestKind,
payloadDigest,
nonce,
String(issuedAtEpochSeconds),
];
return Buffer.concat(
parts.flatMap((part) => [
Buffer.from(`${Buffer.byteLength(part)}:`),
Buffer.from(part),
Buffer.from("\n"),
])
);
}
function signedNodeHeartbeat(node, identity) {
const request = { type: "node_heartbeat", node };
const nonce = `self-hosted-heartbeat-${process.pid}-${Date.now()}`;
const issuedAt = Math.floor(Date.now() / 1000);
const signature = crypto.sign(
null,
nodeSignatureMessage(
node,
"node_heartbeat",
signedRequestPayloadDigest(request),
nonce,
issuedAt
),
identity.privateKeyObject
);
return {
nonce,
issued_at_epoch_seconds: issuedAt,
signature: `ed25519:${signature.toString("base64")}`,
};
}
function signedNodeRequest(node, identity, requestKind, request) {
return {
type: "signed_node",
node,
node_signature: signedNodeHeartbeatForKind(node, identity, requestKind, request),
request,
};
}
function signedNodeHeartbeatForKind(node, identity, requestKind, request) {
const nonce = `${requestKind}-${process.pid}-${Date.now()}`;
const issuedAt = Math.floor(Date.now() / 1000);
const signature = crypto.sign(
null,
nodeSignatureMessage(
node,
requestKind,
signedRequestPayloadDigest(request),
nonce,
issuedAt
),
identity.privateKeyObject
);
return {
nonce,
issued_at_epoch_seconds: issuedAt,
signature: `ed25519:${signature.toString("base64")}`,
};
}
function commandOutput(command, args) {
try {
return cp
.execFileSync(command, args, {
cwd: repo,
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
})
.trim();
} catch (_) {
return null;
}
}
function runJson(command, args, options = {}) {
return JSON.parse(
cp.execFileSync(command, args, {
cwd: options.cwd || repo,
encoding: "utf8",
input: options.input,
})
);
}
function expectedSourceCommit() {
return (
process.env.CLUSTERFLUX_ACCEPTANCE_COMMIT ||
commandOutput("git", ["rev-parse", "HEAD"])
);
}
function readReleaseManifest() {
if (!fs.existsSync(releaseManifestPath)) return null;
const manifest = JSON.parse(fs.readFileSync(releaseManifestPath, "utf8"));
if (manifest.kind !== "clusterflux-public-release-dryrun") return null;
const expectedCommit = expectedSourceCommit();
if (expectedCommit && manifest.source_commit !== expectedCommit) return null;
return manifest;
}
function releaseIdentity() {
const manifest = readReleaseManifest();
return {
sourceCommit: manifest ? manifest.source_commit : expectedSourceCommit(),
releaseName:
(manifest && manifest.release_name) ||
process.env.CLUSTERFLUX_PUBLIC_RELEASE_NAME ||
null,
};
}
async function attachTrustedNode(addr, node, capabilities = linuxNodeCapabilities()) {
const identity = nodeIdentity(node);
const grant = await send(addr, authenticated({
type: "create_node_enrollment_grant",
ttl_seconds: 900,
}));
assert.strictEqual(grant.type, "node_enrollment_grant_created");
const attached = await send(addr, {
type: "exchange_node_enrollment_grant",
tenant: "team",
project: "self-hosted",
node,
public_key: identity.publicKey,
enrollment_grant: grant.grant,
});
assert.strictEqual(attached.type, "node_enrollment_exchanged");
const heartbeat = await send(addr, {
type: "node_heartbeat",
node,
node_signature: signedNodeHeartbeat(node, identity)
});
assert.strictEqual(heartbeat.type, "node_heartbeat");
const reported = await send(addr, signedNodeRequest(node, identity, "report_node_capabilities", {
type: "report_node_capabilities",
tenant: "team",
project: "self-hosted",
node,
capabilities,
cached_environment_digests: [teamEnvironmentDigest],
dependency_cache_digests: [teamDependencyCacheDigest],
source_snapshots: [teamSourceDigest],
artifact_locations: [],
direct_connectivity: true,
online: true
}));
assert.strictEqual(reported.type, "node_capabilities_recorded");
return identity;
}
(async () => {
const release = releaseIdentity();
const coordinator = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"--",
"--listen",
"127.0.0.1:0"
],
{
cwd: repo,
env: {
...process.env,
CLUSTERFLUX_ADMIN_TOKEN: adminToken,
CLUSTERFLUX_SELF_HOSTED_SESSION_SECRET: clientSessionSecret,
CLUSTERFLUX_SELF_HOSTED_TENANT: "team",
CLUSTERFLUX_SELF_HOSTED_PROJECT: "self-hosted",
CLUSTERFLUX_SELF_HOSTED_USER: "developer",
},
}
);
try {
const ready = await waitForJsonLine(coordinator);
const [host, portText] = ready.listen.split(":");
const addr = { host, port: Number(portText) };
assert.strictEqual(ready.client_authority, "strict");
assert.strictEqual(ready.self_hosted_session_bootstrapped, true);
assert.strictEqual((await send(addr, { type: "ping" })).type, "pong");
const forgedBodyAuthority = await send(addr, {
type: "start_process",
tenant: "victim-tenant",
project: "victim-project",
actor_user: "forged-user",
process: "vp-forged",
});
assert.strictEqual(forgedBodyAuthority.type, "error");
assert.match(forgedBodyAuthority.message, /body.*identity.*not authority/i);
const wrongSession = await send(
addr,
authenticated({ type: "auth_status" }, "wrong-session-secret")
);
assert.strictEqual(wrongSession.type, "error");
assert.match(wrongSession.message, /session.*not recognized|not recognized.*session/i);
const authStatus = await send(addr, authenticated({ type: "auth_status" }));
assert.strictEqual(authStatus.type, "auth_status");
assert.strictEqual(authStatus.tenant, "team");
assert.strictEqual(authStatus.project, "self-hosted");
assert.strictEqual(authStatus.actor, "developer");
const missingAdminCredential = await send(
addr,
adminRequest("", "admin_status", "team", "forged-admin", "team", "admin-empty")
);
assert.strictEqual(missingAdminCredential.type, "error");
assert.match(missingAdminCredential.message, /admin.*proof.*invalid/i);
const wrongAdminCredential = await send(
addr,
adminRequest(
"wrong-token",
"admin_status",
"team",
"forged-admin",
"team",
"admin-wrong"
)
);
assert.strictEqual(wrongAdminCredential.type, "error");
assert.match(wrongAdminCredential.message, /admin.*proof.*invalid/i);
const replayableAdminRequest = adminRequest(
adminToken,
"admin_status",
"team",
"self-hosted-admin",
"team",
"admin-replay"
);
const directAdminStatus = await send(addr, replayableAdminRequest);
assert.strictEqual(directAdminStatus.type, "admin_status");
const replayedAdminStatus = await send(addr, replayableAdminRequest);
assert.strictEqual(replayedAdminStatus.type, "error");
assert.match(replayedAdminStatus.message, /nonce was already used/i);
const cargoTargetDir = path.resolve(
process.env.CARGO_TARGET_DIR || path.join(repo, "target")
);
const cliBin = path.join(
cargoTargetDir,
"debug",
process.platform === "win32" ? "clusterflux.exe" : "clusterflux"
);
const selfHostedCliProject = path.join(
repo,
"target/acceptance/self-hosted-cli-project"
);
fs.rmSync(selfHostedCliProject, { recursive: true, force: true });
fs.mkdirSync(selfHostedCliProject, { recursive: true });
const cliConnect = runJson(
cliBin,
[
"auth",
"connect-self-hosted",
"--coordinator",
ready.listen,
"--tenant",
"team",
"--project-id",
"self-hosted",
"--user",
"developer",
"--session-secret-stdin",
"--json",
],
{ cwd: selfHostedCliProject, input: `${clientSessionSecret}\n` }
);
assert.strictEqual(cliConnect.status, "connected");
assert.strictEqual(cliConnect.session_secret_read_from_stdin, true);
assert.strictEqual(cliConnect.session_secret_exposed_in_report, false);
assert.strictEqual(cliConnect.coordinator_response.type, "auth_status");
const sessionPath = path.join(
selfHostedCliProject,
".clusterflux/session.json"
);
const storedSession = JSON.parse(fs.readFileSync(sessionPath, "utf8"));
assert.strictEqual(storedSession.kind, "self_hosted");
assert.strictEqual(storedSession.session_secret, clientSessionSecret);
assert.strictEqual(storedSession.provider_tokens_exposed_to_cli, false);
assert.strictEqual(storedSession.provider_tokens_sent_to_nodes, false);
if (process.platform !== "win32") {
assert.strictEqual(fs.statSync(sessionPath).mode & 0o777, 0o600);
}
const cliAuthStatus = runJson(
cliBin,
["auth", "status", "--json"],
{ cwd: selfHostedCliProject }
);
assert.strictEqual(cliAuthStatus.active_coordinator, ready.listen);
assert.strictEqual(
cliAuthStatus.coordinator_account_status.used_cli_session_credential,
true
);
assert.strictEqual(
cliAuthStatus.coordinator_account_status.coordinator_response_type,
"auth_status"
);
const cliAdminStatus = runJson(cliBin, [
"admin",
"status",
"--coordinator",
ready.listen,
"--tenant",
"team",
"--user",
"self-hosted-admin",
"--admin-token",
adminToken,
"--json",
]);
assert.strictEqual(cliAdminStatus.response.type, "admin_status");
assert.strictEqual(cliAdminStatus.suspended, false);
const cliAdminSuspend = runJson(cliBin, [
"admin",
"suspend-tenant",
"--coordinator",
ready.listen,
"--tenant",
"team",
"--user",
"self-hosted-admin",
"--target-tenant",
"admin-probe-tenant",
"--admin-token",
adminToken,
"--yes",
"--json",
]);
assert.strictEqual(cliAdminSuspend.response.type, "tenant_suspended");
assert.strictEqual(cliAdminSuspend.suspended, true);
const cliAdminProbeStatus = runJson(cliBin, [
"admin",
"status",
"--coordinator",
ready.listen,
"--tenant",
"admin-probe-tenant",
"--user",
"self-hosted-admin",
"--admin-token",
adminToken,
"--json",
]);
assert.strictEqual(cliAdminProbeStatus.suspended, true);
const teamLinuxA = await attachTrustedNode(addr, "team-linux-a");
const teamLinuxBCapabilities = linuxNodeCapabilities();
teamLinuxBCapabilities.capabilities = teamLinuxBCapabilities.capabilities.filter(
(capability) => capability !== "VfsArtifacts"
);
await attachTrustedNode(addr, "team-linux-b", teamLinuxBCapabilities);
const placement = await send(addr, authenticated({
type: "schedule_task",
environment: {
os: "Linux",
arch: "x86_64",
capabilities: ["Command", "QuicDirect"]
},
environment_digest: teamEnvironmentDigest,
required_capabilities: ["VfsArtifacts"],
source_snapshot: teamSourceDigest,
required_artifacts: [],
prefer_node: "team-linux-a"
}));
assert.strictEqual(placement.type, "task_placement");
assert.strictEqual(placement.placement.node, "team-linux-a");
assert(placement.placement.reasons.includes("preferred node"));
assert(placement.placement.reasons.includes("warm environment cache"));
assert(placement.placement.reasons.includes("source snapshot already local"));
const started = await send(addr, authenticated({
type: "start_process",
process: "vp-team-build",
restart: false,
}));
assert.strictEqual(started.type, "process_started");
const reconnected = await send(addr, signedNodeRequest("team-linux-a", teamLinuxA, "reconnect_node", {
type: "reconnect_node",
node: "team-linux-a",
process: "vp-team-build",
epoch: started.epoch
}));
assert.strictEqual(reconnected.type, "node_reconnected");
const launched = await send(addr, authenticated({
type: "launch_task",
task_spec: {
tenant: "team",
project: "self-hosted",
process: "vp-team-build",
task_definition: "compile-linux",
task_instance: "compile-linux",
dispatch: {
kind: "coordinator_node_wasm",
export: "compile_linux",
abi: "task_v1",
},
environment_id: null,
environment: null,
environment_digest: null,
required_capabilities: ["VfsArtifacts"],
dependency_cache: null,
source_snapshot: null,
required_artifacts: [],
args: [],
vfs_epoch: started.epoch,
bundle_digest: coordinatorTaskBundleDigest,
},
wait_for_node: false,
artifact_path: "/vfs/artifacts/team-output.txt",
wasm_module_base64: coordinatorTaskModule.toString("base64"),
}));
assert.strictEqual(launched.type, "task_launched", JSON.stringify(launched));
assert.strictEqual(launched.placement.node, "team-linux-a");
const completed = await send(addr, signedNodeRequest("team-linux-a", teamLinuxA, "task_completed", {
type: "task_completed",
tenant: "team",
project: "self-hosted",
process: "vp-team-build",
node: "team-linux-a",
task: "compile-linux",
status_code: 0,
stdout_bytes: 18,
stderr_bytes: 0,
stdout_tail: "",
stderr_tail: "",
stdout_truncated: false,
stderr_truncated: false,
artifact_path: "/vfs/artifacts/team-output.txt",
artifact_digest: teamArtifactDigest,
artifact_size_bytes: 18
}));
assert.strictEqual(completed.type, "task_recorded", JSON.stringify(completed));
const events = await send(addr, authenticated({
type: "list_task_events",
process: "vp-team-build",
}));
assert.strictEqual(events.type, "task_events");
assert.strictEqual(events.events.length, 1);
assert.strictEqual(events.events[0].node, "team-linux-a");
assert.strictEqual(events.events[0].artifact_path, "/vfs/artifacts/team-output.txt");
const link = await send(addr, authenticated({
type: "create_artifact_download_link",
artifact: "team-output.txt",
max_bytes: 1024 * 1024,
ttl_seconds: 60
}));
assert.strictEqual(link.type, "artifact_download_link");
assert.deepStrictEqual(link.link.source, { RetainedNode: "team-linux-a" });
const exportPlan = await send(addr, authenticated({
type: "export_artifact_to_node",
artifact: "team-output.txt",
receiver_node: "team-linux-b",
direct_connectivity: true,
failure_reason: ""
}));
assert.strictEqual(exportPlan.type, "artifact_export_plan");
assert.strictEqual(exportPlan.source_node, "team-linux-a");
assert.strictEqual(exportPlan.receiver_node, "team-linux-b");
assert.strictEqual(exportPlan.plan.transport, "NativeQuic");
assert.strictEqual(exportPlan.plan.coordinator_assisted_rendezvous, true);
assert.strictEqual(exportPlan.plan.coordinator_bulk_relay_allowed, false);
const reportPath = path.join(repo, "target/acceptance/core-coordinator-compat.json");
fs.mkdirSync(path.dirname(reportPath), { recursive: true });
fs.writeFileSync(
reportPath,
`${JSON.stringify(
{
kind: "clusterflux-core-coordinator-compatibility",
source_commit: release.sourceCommit,
release_name: release.releaseName,
coordinator_implementation: "standalone-core-coordinator",
coordinator_addr: ready.listen,
client_authority: ready.client_authority,
authenticated_session: authStatus.authenticated,
forged_body_authority_denied: forgedBodyAuthority.type,
wrong_session_denied: wrongSession.type,
ping: "pong",
nodes: ["team-linux-a", "team-linux-b"],
task_placement: placement.type,
process_started: started.type,
task_completion: completed.type,
task_events: events.events.length,
artifact_download_link: link.type,
artifact_export_plan: exportPlan.type,
self_hosted_admin: {
missing_credential_denied: missingAdminCredential.type,
wrong_credential_denied: wrongAdminCredential.type,
nonce_bound_proof_succeeded: directAdminStatus.type,
replay_denied: replayedAdminStatus.type,
cli_status: cliAdminStatus.response.type,
cli_suspend: cliAdminSuspend.response.type,
suspended_state_observed: cliAdminProbeStatus.suspended,
},
self_hosted_cli: {
connected: cliConnect.status,
secret_read_from_stdin: cliConnect.session_secret_read_from_stdin,
secret_exposed_in_report: cliConnect.session_secret_exposed_in_report,
session_file_mode:
process.platform === "win32"
? "windows-best-effort"
: (fs.statSync(sessionPath).mode & 0o777).toString(8),
authenticated_status:
cliAuthStatus.coordinator_account_status.coordinator_response_type,
},
},
null,
2
)}\n`
);
} finally {
coordinator.kill("SIGTERM");
}
console.log("Self-hosted coordinator smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

View file

@ -0,0 +1,218 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const net = require("net");
const path = require("path");
const { coordinatorWireRequest } = require("./coordinator-wire");
const { nodeIdentity, signedNodeRequest } = require("./node-signing");
const repo = path.resolve(__dirname, "..");
function waitForJsonLine(child) {
return new Promise((resolve, reject) => {
let buffer = "";
child.stdout.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
try {
resolve(JSON.parse(buffer.slice(0, newline).trim()));
} catch (error) {
reject(error);
}
});
child.once("exit", (code) => {
reject(new Error(`process exited before JSON line with code ${code}`));
});
});
}
function send(addr, message) {
return new Promise((resolve, reject) => {
const socket = net.connect(addr.port, addr.host, () => {
socket.write(`${JSON.stringify(coordinatorWireRequest(message))}\n`);
});
let buffer = "";
socket.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
socket.end();
try {
resolve(JSON.parse(buffer.slice(0, newline)));
} catch (error) {
reject(error);
}
});
socket.on("error", reject);
});
}
function sourceCapableNode(sourceProviders = ["git"]) {
return {
os: "Linux",
arch: "x86_64",
capabilities: ["Command", "SourceFilesystem", "SourceGit"],
environment_backends: [],
source_providers: sourceProviders
};
}
(async () => {
const coordinator = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"--",
"--listen",
"127.0.0.1:0",
"--allow-local-trusted-loopback"
],
{ cwd: repo }
);
let coordinatorStderr = "";
coordinator.stderr.on("data", (chunk) => {
coordinatorStderr += chunk.toString();
});
try {
const ready = await waitForJsonLine(coordinator);
const [host, portText] = ready.listen.split(":");
const addr = { host, port: Number(portText) };
assert.strictEqual((await send(addr, { type: "ping" })).type, "pong");
const pending = await send(addr, {
type: "request_source_preparation",
tenant: "tenant",
project: "project",
provider: "Git"
});
assert.strictEqual(pending.type, "source_preparation");
assert.strictEqual(pending.status.preparation.tenant, "tenant");
assert.strictEqual(pending.status.preparation.project, "project");
assert.strictEqual(pending.status.preparation.provider, "Git");
assert.strictEqual(
pending.status.preparation.coordinator_requires_checkout_access,
false
);
assert.deepStrictEqual(pending.status.preparation.required_capabilities, [
"SourceGit"
]);
assert.match(pending.status.disposition.Pending.reason, /waiting|node/i);
const nodeIdentities = new Map();
for (const node of ["source-cold", "source-ready"]) {
const identity = nodeIdentity("source-preparation-smoke", node);
nodeIdentities.set(node, identity);
const attached = await send(addr, {
type: "attach_node",
tenant: "tenant",
project: "project",
node,
public_key: identity.publicKey
});
assert.strictEqual(attached.type, "node_attached");
}
const cold = await send(addr, signedNodeRequest("source-cold", nodeIdentities.get("source-cold"), "report_node_capabilities", {
type: "report_node_capabilities",
tenant: "tenant",
project: "project",
node: "source-cold",
capabilities: sourceCapableNode(),
cached_environment_digests: [],
source_snapshots: [],
artifact_locations: [],
direct_connectivity: true,
online: true
}));
assert.strictEqual(cold.type, "node_capabilities_recorded");
const readyReport = await send(addr, signedNodeRequest("source-ready", nodeIdentities.get("source-ready"), "report_node_capabilities", {
type: "report_node_capabilities",
tenant: "tenant",
project: "project",
node: "source-ready",
capabilities: sourceCapableNode(),
cached_environment_digests: [],
source_snapshots: [],
artifact_locations: [],
direct_connectivity: true,
online: true
}));
assert.strictEqual(readyReport.type, "node_capabilities_recorded");
const assigned = await send(addr, {
type: "request_source_preparation",
tenant: "tenant",
project: "project",
provider: "Git"
});
assert.strictEqual(assigned.type, "source_preparation");
assert(["source-cold", "source-ready"].includes(assigned.status.disposition.Assigned.node));
assert.strictEqual(
assigned.status.preparation.coordinator_requires_checkout_access,
false
);
const crossTenantCompletion = await send(addr, signedNodeRequest("source-ready", nodeIdentities.get("source-ready"), "complete_source_preparation", {
type: "complete_source_preparation",
tenant: "other",
project: "project",
node: "source-ready",
provider: "Git",
source_snapshot: "sha256:source-prepared"
}));
assert.strictEqual(crossTenantCompletion.type, "error");
assert.match(crossTenantCompletion.message, /tenant\/project scope/i);
const completed = await send(addr, signedNodeRequest("source-ready", nodeIdentities.get("source-ready"), "complete_source_preparation", {
type: "complete_source_preparation",
tenant: "tenant",
project: "project",
node: "source-ready",
provider: "Git",
source_snapshot: "sha256:source-prepared"
}));
assert.strictEqual(completed.type, "source_preparation_completed");
assert.strictEqual(completed.node, "source-ready");
assert.strictEqual(completed.provider, "Git");
assert.strictEqual(completed.source_snapshot, "sha256:source-prepared");
const placement = await send(addr, {
type: "schedule_task",
tenant: "tenant",
project: "project",
environment: null,
environment_digest: null,
required_capabilities: ["SourceGit"],
source_snapshot: "sha256:source-prepared",
required_artifacts: [],
prefer_node: null
});
assert.strictEqual(placement.type, "task_placement");
assert.strictEqual(placement.placement.node, "source-ready");
assert(
placement.placement.reasons.includes("source snapshot already local"),
"completed source preparation must update node source locality"
);
} catch (error) {
if (coordinatorStderr) {
error.message = `${error.message}\ncoordinator stderr:\n${coordinatorStderr}`;
}
throw error;
} finally {
coordinator.kill("SIGTERM");
}
console.log("Source preparation smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

View file

@ -0,0 +1,181 @@
#!/usr/bin/env node
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const repo = path.resolve(__dirname, "..");
function read(relativePath) {
return fs.readFileSync(path.join(repo, relativePath), "utf8");
}
function maybeRead(segments) {
const fullPath = path.join(repo, ...segments);
if (!fs.existsSync(fullPath)) return null;
return fs.readFileSync(fullPath, "utf8");
}
function expect(source, name, pattern) {
assert.match(source, pattern, `missing tenant-isolation evidence: ${name}`);
}
const auth = read("crates/clusterflux-core/src/auth.rs");
const artifact = read("crates/clusterflux-core/src/artifact.rs");
const operatorPanel = read("crates/clusterflux-core/src/operator_panel.rs");
const source = read("crates/clusterflux-core/src/source.rs");
const coordinatorService = [
read("crates/clusterflux-coordinator/src/service.rs"),
read("crates/clusterflux-coordinator/src/service/routing.rs"),
read("crates/clusterflux-coordinator/src/service/nodes.rs"),
read("crates/clusterflux-coordinator/src/service/keys.rs"),
read("crates/clusterflux-coordinator/src/service/artifacts.rs"),
read("crates/clusterflux-coordinator/src/service/processes.rs"),
read("crates/clusterflux-coordinator/src/service/process_launch.rs"),
read("crates/clusterflux-coordinator/src/service/tests.rs"),
].join("\n");
const artifactDownloadSmoke = read("scripts/artifact-download-smoke.js");
const operatorPanelSmoke = read("scripts/operator-panel-smoke.js");
const schedulerSmoke = read("scripts/scheduler-placement-smoke.js");
const sourcePreparationSmoke = read("scripts/source-preparation-smoke.js");
for (const [name, pattern] of [
["auth contexts carry tenant and project", /pub struct AuthContext[\s\S]*pub tenant: TenantId[\s\S]*pub project: ProjectId/],
["enrollment grants carry tenant and project", /pub struct EnrollmentGrant[\s\S]*pub tenant: TenantId[\s\S]*pub project: ProjectId/],
["node credentials carry tenant and project", /pub struct NodeCredential[\s\S]*pub tenant: TenantId[\s\S]*pub project: ProjectId/],
["same tenant/project denies tenant mismatch", /pub fn same_tenant_project[\s\S]*tenant mismatch/],
["same tenant/project denies project mismatch", /pub fn same_tenant_project[\s\S]*project mismatch/],
["auth unit denies cross-tenant access", /fn tenant_project_scope_denies_cross_tenant_access\(\)/],
]) {
expect(auth, name, pattern);
}
for (const [name, pattern] of [
["artifact metadata carries tenant and project", /pub struct ArtifactMetadata[\s\S]*pub tenant: TenantId[\s\S]*pub project: ProjectId/],
["download links carry tenant project process and actor", /pub struct DownloadLink[\s\S]*pub tenant: TenantId[\s\S]*pub project: ProjectId[\s\S]*pub process: ProcessId[\s\S]*pub actor: Actor/],
["downloads authorize against scoped metadata", /let authz = same_tenant_project\(context, &scope\)/],
["artifact test denies cross-tenant download", /fn cross_tenant_download_is_denied_even_with_known_artifact_id\(\)/],
["artifact test denies cross-project download", /fn cross_project_download_is_denied_even_with_known_artifact_id\(\)/],
]) {
expect(artifact, name, pattern);
}
for (const [name, pattern] of [
["panel state carries tenant project and process", /pub struct PanelState[\s\S]*pub tenant: TenantId[\s\S]*pub project: ProjectId[\s\S]*pub process: ProcessId/],
["panel events carry tenant project and process", /pub struct PanelEvent[\s\S]*pub tenant: TenantId[\s\S]*pub project: ProjectId[\s\S]*pub process: ProcessId/],
["panel events reject scope mismatch", /PanelError::ScopeMismatch/],
["panel scope validation compares tenant project process", /self\.tenant != event\.tenant[\s\S]*self\.project != event\.project[\s\S]*self\.process != event\.process/],
]) {
expect(operatorPanel, name, pattern);
}
expect(
source,
"source preparation carries tenant and project",
/pub struct SourcePreparation[\s\S]*pub tenant: TenantId[\s\S]*pub project: ProjectId/
);
for (const [name, pattern] of [
["project creation rejects foreign tenant reuse", /project id is outside the signed-in tenant scope/],
["project selection rejects foreign tenant", /project is outside the signed-in tenant scope/],
["project listing uses tenant-scoped context", /CoordinatorRequest::ListProjects[\s\S]*list_projects\(&context\)/],
["node capability reports check enrollment tenant scope", /node capability report is outside the enrolled tenant\/project scope/],
["operator panel stop state is tenant/project/process keyed", /type PanelStopKey = \(TenantId, ProjectId, ProcessId\)/],
["download service tests tenant mismatch", /cross_tenant\.to_string\(\)\.contains\("tenant mismatch"\)/],
["download service tests project mismatch", /cross_project\.to_string\(\)\.contains\("project mismatch"\)/],
["node capability test rejects cross-scope report", /fn service_rejects_node_capability_report_outside_enrollment_scope\(\)/],
["source preparation test rejects cross-scope completion", /fn service_rejects_source_preparation_completion_outside_node_scope\(\)/],
]) {
expect(coordinatorService, name, pattern);
}
for (const [name, sourceText, patterns] of [
[
"artifact download smoke",
artifactDownloadSmoke,
[
/const crossTenant = await send/,
/const crossProject = await send/,
/const crossTenantOpen = await send/,
/const crossProjectOpen = await send/,
/tenant mismatch/,
/project mismatch/,
/token is invalid/,
],
],
[
"operator panel smoke",
operatorPanelSmoke,
[/const crossTenant = await send/, /render_operator_panel/, /scope\|tenant\|project/],
],
[
"scheduler and capability smoke",
schedulerSmoke,
[
/const crossScopeInspection = await send/,
/assert\.strictEqual\(crossScopeInspection\.descriptors\.length, 0\)/,
/const crossTenantReport = await send/,
/tenant\\\/project scope/,
],
],
[
"source preparation smoke",
sourcePreparationSmoke,
[/const crossTenantCompletion = await send/, /complete_source_preparation/, /tenant\\\/project scope/i],
],
]) {
for (const pattern of patterns) {
expect(sourceText, name, pattern);
}
}
const hostedLibRoot = maybeRead(["private", "hosted-policy", "src", "lib.rs"]);
const hostedServiceSource = maybeRead([
"private",
"hosted-policy",
"src",
"bin",
"clusterflux-hosted-service.rs",
]);
const hostedLib = hostedLibRoot;
const hostedSmoke = maybeRead([
"private",
"hosted-policy",
"scripts",
"hosted-client-compat-smoke.js",
]);
if (hostedLib && hostedServiceSource && hostedSmoke) {
for (const [name, pattern] of [
["hosted private layer is a compact identity broker", /pub struct HostedIdentityBroker[\s\S]*cli_session_ttl_seconds/],
["hosted private layer has no parallel coordinator", /Runtime, persistence, nodes, processes,[\s\S]*remain owned by public CoordinatorService/],
["hosted service delegates Client state to Core", /core_coordinator: CoordinatorService/],
["hosted login creates project through Core", /issue_cli_session[\s\S]*AuthenticatedCoordinatorRequest::CreateProject/],
]) {
expect(`${hostedLib}\n${hostedServiceSource}`, name, pattern);
}
for (const forbidden of [
"HostedCommunityControlPlane",
"HostedObservabilitySnapshot",
"agent_public_keys: BTreeMap",
"node_statuses: BTreeMap",
"process_statuses: BTreeMap",
"debug_sessions: BTreeMap",
]) {
assert(
!hostedLib.includes(forbidden),
`private hosted policy must not reimplement Core state: ${forbidden}`
);
}
for (const [name, pattern] of [
["client-supplied identity is denied", /const forged = await sendHostedControl[\s\S]*authenticated CLI session/],
["second OIDC subject receives a different tenant", /assert\.notStrictEqual\(victimLogin\.session\.tenant, session\.tenant\)/],
["cross-tenant process events are denied", /const crossTenantTaskEventsDenied = await sendHostedControl[\s\S]*vp-victim[\s\S]*scope\|denied\|unauthorized/],
]) {
expect(hostedSmoke, name, pattern);
}
}
console.log("Tenant isolation contract smoke passed");

View file

@ -0,0 +1,120 @@
#!/usr/bin/env node
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const repo = path.resolve(__dirname, "..");
function read(file) {
return fs.readFileSync(path.join(repo, file), "utf8");
}
function extractBalancedBlock(source, marker) {
const start = source.indexOf(marker);
assert(start >= 0, `missing marker ${marker}`);
const open = source.indexOf("{", start);
assert(open >= 0, `missing opening brace for ${marker}`);
let depth = 0;
for (let index = open; index < source.length; index += 1) {
const char = source[index];
if (char === "{") depth += 1;
if (char === "}") {
depth -= 1;
if (depth === 0) return source.slice(start, index + 1);
}
}
throw new Error(`missing closing brace for ${marker}`);
}
function extractEnumVariant(source, variant) {
const marker = ` ${variant} {`;
return extractBalancedBlock(source, marker);
}
const forbiddenUserSessionCredentials =
/\b(BrowserSession|CliDeviceSession|BrowserLoginFlow|CliLoginFlow|authorization_url|verification_url|device_code|access_token|refresh_token|provider_token|provider_tokens|session_token|user_token|oauth_token)\b/i;
function assertNoUserSessionCredential(surface, text) {
assert.doesNotMatch(
text,
forbiddenUserSessionCredentials,
`${surface} must not carry user OAuth/browser/session credentials`
);
}
const coordinatorService = `${read("crates/clusterflux-coordinator/src/service/protocol.rs")}\n${read("crates/clusterflux-coordinator/src/service/protocol/responses.rs")}`;
for (const variant of [
"AdminStatus",
"SuspendTenant",
"AttachNode",
"RegisterAgentPublicKey",
"ListAgentPublicKeys",
"RotateAgentPublicKey",
"RevokeAgentPublicKey",
"NodeHeartbeat",
"ReportNodeCapabilities",
"RevokeNodeCredential",
"RequestRendezvous",
"RequestSourcePreparation",
"CompleteSourcePreparation",
"StartProcess",
"ReconnectNode",
"CancelTask",
"CancelProcess",
"PollTaskControl",
"RestartTask",
"DebugAttach",
"TaskCompleted",
]) {
assertNoUserSessionCredential(
`CoordinatorRequest::${variant}`,
extractEnumVariant(coordinatorService, variant)
);
}
const nodeRuntime = [
read("crates/clusterflux-node/src/lib.rs"),
read("crates/clusterflux-node/src/command_runner.rs"),
].join("\n");
for (const marker of [
"pub struct LinuxCommandRunPlan",
"pub struct LinuxCommandTaskOutput",
"pub struct CapturedCommandLogs",
"pub struct VirtualThreadCommand",
"pub struct CommandOutput",
]) {
assertNoUserSessionCredential(marker, extractBalancedBlock(nodeRuntime, marker));
}
const coreExecution = read("crates/clusterflux-core/src/execution.rs");
assertNoUserSessionCredential(
"CommandInvocation",
extractBalancedBlock(coreExecution, "pub struct CommandInvocation")
);
const dapAdapter = read("crates/clusterflux-dap/src/variables.rs");
assertNoUserSessionCredential(
"DAP variables response",
extractBalancedBlock(dapAdapter, "fn variables_response")
);
const panel = read("crates/clusterflux-core/src/operator_panel.rs");
assertNoUserSessionCredential(
"PanelEvent",
extractBalancedBlock(panel, "pub struct PanelEvent")
);
const auth = read("crates/clusterflux-core/src/auth.rs");
assert.match(
auth,
/task_credentials_do_not_contain_user_session/,
"core auth must keep the task credential user-session guard"
);
assert.match(
auth,
/CredentialKind::BrowserSession \| CredentialKind::CliDeviceSession/,
"task credential guard must reject browser and CLI sessions"
);
console.log("User session token boundary smoke passed");

72
scripts/verify-public-split.sh Executable file
View file

@ -0,0 +1,72 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source_commit="$(git -C "$repo_root" rev-parse HEAD)"
export CLUSTERFLUX_ACCEPTANCE_COMMIT="$source_commit"
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
tar \
--exclude='./.git' \
--exclude='./target' \
--exclude='./private' \
--exclude='./internal' \
--exclude='./experiments' \
--exclude='./.clusterflux' \
--exclude='./vscode-extension/node_modules' \
--exclude='./scripts/containers-home' \
-C "$repo_root" \
-cf - . | tar -C "$tmp_dir" -xf -
if find "$tmp_dir" -path "$tmp_dir/private" -print -quit | grep -q .; then
echo "private directory leaked into public split" >&2
exit 1
fi
if find "$tmp_dir" -path "$tmp_dir/experiments" -print -quit | grep -q .; then
echo "experiments directory leaked into public split" >&2
exit 1
fi
if find "$tmp_dir" -path "$tmp_dir/internal" -print -quit | grep -q .; then
echo "internal directory leaked into public split" >&2
exit 1
fi
(cd "$tmp_dir" && scripts/check-old-name.sh)
(cd "$tmp_dir" && CLUSTERFLUX_FILTERED_PUBLIC_TREE=1 node scripts/check-docs.js)
(cd "$tmp_dir" && scripts/check-code-size.sh)
(cd "$tmp_dir" && node scripts/resource-metering-contract-smoke.js)
(cd "$tmp_dir" && node scripts/hostile-input-contract-smoke.js)
(cd "$tmp_dir" && node scripts/tenant-isolation-contract-smoke.js)
(cd "$tmp_dir" && cargo fmt --all --check)
CARGO_TARGET_DIR="$tmp_dir/target" cargo test \
--workspace \
--all-targets \
--manifest-path "$tmp_dir/Cargo.toml"
CARGO_TARGET_DIR="$tmp_dir/target" cargo build \
--workspace \
--all-targets \
--manifest-path "$tmp_dir/Cargo.toml"
(cd "$tmp_dir" && node scripts/cli-install-smoke.js)
(cd "$tmp_dir" && node scripts/flagship-demo-smoke.js)
(cd "$tmp_dir" && node scripts/cli-local-run-smoke.js)
(cd "$tmp_dir" && node scripts/node-attach-smoke.js)
(cd "$tmp_dir" && node scripts/vscode-extension-smoke.js)
(cd "$tmp_dir" && node scripts/vscode-f5-smoke.js)
(cd "$tmp_dir" && node scripts/artifact-download-smoke.js)
(cd "$tmp_dir" && node scripts/artifact-export-smoke.js)
public_digest="$(
find "$tmp_dir" \
-path "$tmp_dir/target" -prune -o \
-type f -print0 \
| LC_ALL=C sort -z \
| xargs -0 sha256sum \
| sha256sum \
| cut -d' ' -f1
)"
printf 'Filtered public tree passed: commit=%s digest=sha256:%s\n' \
"$source_commit" \
"$public_digest"

229
scripts/vscode-extension-smoke.js Executable file
View file

@ -0,0 +1,229 @@
#!/usr/bin/env node
const fs = require("fs");
const os = require("os");
const path = require("path");
const assert = require("assert");
const extension = require("../vscode-extension/extension");
const packageJson = require("../vscode-extension/package.json");
const extensionSource = fs.readFileSync(
path.join(__dirname, "../vscode-extension/extension.js"),
"utf8"
);
const repo = path.resolve(__dirname, "..");
assert.strictEqual(packageJson.main, "./extension.js");
assert(fs.existsSync(path.join(__dirname, "../vscode-extension", packageJson.main)));
assert.deepStrictEqual(packageJson.dependencies || {}, {});
const root = fs.mkdtempSync(path.join(os.tmpdir(), "clusterflux-vscode-"));
fs.mkdirSync(path.join(root, "envs/linux"), { recursive: true });
fs.writeFileSync(path.join(root, "envs/linux/Containerfile"), "FROM alpine\n");
fs.mkdirSync(path.join(root, ".clusterflux"), { recursive: true });
fs.writeFileSync(
extension.clusterfluxViewStatePath(root),
JSON.stringify({
nodes: [{ id: "node-linux", status: "online", capabilities: "Command RootlessPodman" }],
processes: [{ id: "vp-build", status: "running", entry: "build" }],
logs: [{ task: "compile-linux", message: "stdout=12 stderr=0", bytes: 12 }],
artifacts: [{ path: "/vfs/artifacts/app.tar.zst", status: "retained", size: 12 }],
inspector: [{ label: "debug", value: "attached" }]
})
);
const envs = extension.discoverEnvironmentNames(root);
assert.deepStrictEqual(envs, ["linux"]);
const diagnostics = extension.diagnoseEnvReferences(
'let _ = env!("linux"); let _ = env!("windows");',
envs
);
assert.strictEqual(diagnostics.length, 1);
assert.strictEqual(diagnostics[0].name, "windows");
assert.match(diagnostics[0].message, /envs\/windows\/Containerfile/);
const inspectCommand = extension.bundleInspectCommand(root, "/repo");
assert.strictEqual(inspectCommand.command, "cargo");
assert.deepStrictEqual(inspectCommand.args.slice(0, 8), [
"run",
"-q",
"-p",
"clusterflux-cli",
"--bin",
"clusterflux",
"--",
"bundle"
]);
assert(inspectCommand.args.includes("inspect"));
assert(inspectCommand.args.includes("--project"));
assert(inspectCommand.args.includes(root));
assert(inspectCommand.args.includes("--json"));
const refreshed = extension.refreshBundleBeforeLaunch(root, "/repo", (command, args, options) => {
assert.strictEqual(command, "cargo");
assert(args.includes("bundle"));
assert.strictEqual(options.cwd, "/repo");
return {
status: 0,
stdout: JSON.stringify({ metadata: { identity: "sha256:abc" } }),
stderr: ""
};
});
assert.strictEqual(refreshed.metadata.identity, "sha256:abc");
const launch = extension.resolveClusterfluxDebugConfiguration(
{ uri: { fsPath: root } },
{}
);
assert.deepStrictEqual(launch, {
name: "Clusterflux: Launch Virtual Process",
type: "clusterflux",
request: "launch",
entry: "build",
project: root,
runtimeBackend: "local-services"
});
assert.strictEqual(
extension.clusterfluxProcessId("/workspace/app", "build"),
"vp-e4bd6ef50539"
);
assert.strictEqual(
extension.existingProcessRelationship(
{ process: "vp-e4bd6ef50539", state: "running" },
"vp-e4bd6ef50539"
),
"same_launch_target"
);
assert.strictEqual(
extension.existingProcessRelationship(
{ process: "vp-other", state: "running" },
"vp-e4bd6ef50539"
),
"different_launch_target"
);
const liveProcesses = extension.loadLiveProcesses(root, "/repo", (_command, args) => {
assert.deepStrictEqual(args.slice(-3), ["process", "list", "--json"]);
return {
status: 0,
stdout: JSON.stringify({
coordinator: "https://clusterflux.michelpaulissen.com",
tenant: "tenant-live",
project: "project-live",
user: "user-live",
processes: [{ process: "vp-live", state: "cancelling" }]
}),
stderr: ""
};
});
assert.deepStrictEqual(liveProcesses.processes, [
{ process: "vp-live", state: "cancelling" }
]);
assert.strictEqual(liveProcesses.project, "project-live");
const adapter = extension.debugAdapterExecutableSpec(root, repo);
assert.strictEqual(adapter.command, "cargo");
assert.deepStrictEqual(adapter.args, [
"run",
"-q",
"-p",
"clusterflux-dap",
"--bin",
"clusterflux-debug-dap"
]);
assert.deepStrictEqual(adapter.options, { cwd: repo });
const releasedAdapterPath = path.join(root, process.platform === "win32" ? "clusterflux-debug-dap.exe" : "clusterflux-debug-dap");
fs.writeFileSync(releasedAdapterPath, "");
const releasedAdapter = extension.debugAdapterExecutableSpec(root, repo);
assert.strictEqual(releasedAdapter.command, releasedAdapterPath);
assert.deepStrictEqual(releasedAdapter.args, []);
assert.deepStrictEqual(releasedAdapter.options, { cwd: root });
assert.throws(
() =>
extension.refreshBundleBeforeLaunch(root, "/repo", () => ({
status: 1,
stdout: "",
stderr: "missing environment linux"
})),
/missing environment linux/
);
assert(
packageJson.contributes.viewsContainers.activitybar.some(
(container) => container.id === "clusterflux" && container.title === "Clusterflux"
),
"package.json must contribute a Clusterflux activity-bar container"
);
assert(
fs.existsSync(path.join(__dirname, "../vscode-extension/resources/clusterflux.svg")),
"Clusterflux activity-bar icon must exist"
);
const packageViewIds = packageJson.contributes.views.clusterflux.map((view) => view.id).sort();
const descriptorViewIds = extension.clusterfluxViewDescriptors().map((view) => view.id).sort();
assert.deepStrictEqual(descriptorViewIds, [
"clusterflux.artifacts",
"clusterflux.inspector",
"clusterflux.logs",
"clusterflux.nodes",
"clusterflux.processes"
]);
assert.deepStrictEqual(packageViewIds, descriptorViewIds);
for (const viewId of descriptorViewIds) {
const items = extension.clusterfluxViewItems(
extension.loadClusterfluxViewState(root),
viewId
);
assert(
items.length > 0 && !items[0].label.startsWith("No "),
`${viewId} should render state-backed items`
);
}
assert.deepStrictEqual(
extension.clusterfluxViewItems(extension.loadClusterfluxViewState(root), "clusterflux.nodes")[0],
{
label: "node-linux",
description: "online Command RootlessPodman"
}
);
assert(
packageJson.contributes.debuggers.some((debuggerContribution) => debuggerContribution.type === "clusterflux"),
"package.json must contribute the clusterflux debugger type"
);
for (const viewId of descriptorViewIds) {
assert(
packageJson.activationEvents.includes(`onView:${viewId}`),
`${viewId} should activate the extension when opened`
);
}
const launchProperties =
packageJson.contributes.debuggers[0].configurationAttributes.launch.properties;
assert.strictEqual(launchProperties.runtimeBackend.default, "local-services");
assert(launchProperties.runtimeBackend.enum.includes("live-services"));
assert.strictEqual(launchProperties.coordinatorEndpoint.default, undefined);
assert.strictEqual(launchProperties.tenant, undefined);
assert.strictEqual(launchProperties.projectId, undefined);
assert.strictEqual(launchProperties.actorUser, undefined);
assert(
packageJson.contributes.debuggers[0].configurationAttributes.attach,
"package.json must contribute an attach configuration"
);
for (const command of [
"clusterflux.refreshProcesses",
"clusterflux.process.attach",
"clusterflux.process.cancel",
"clusterflux.process.abort"
]) {
assert(
packageJson.contributes.commands.some((entry) => entry.command === command),
`${command} must be contributed`
);
}
assert.match(extensionSource, /registerDebugAdapterDescriptorFactory\("clusterflux"/);
assert.match(extensionSource, /clusterflux-debug-dap/);
assert.match(extensionSource, /\.clusterflux\/views\.json/);
fs.rmSync(root, { recursive: true, force: true });
console.log("VS Code extension smoke passed");

310
scripts/vscode-f5-smoke.js Executable file
View file

@ -0,0 +1,310 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const fs = require("fs");
const path = require("path");
const extension = require("../vscode-extension/extension");
class DapClient {
constructor(spec) {
this.child = cp.spawn(spec.command, spec.args, {
cwd: spec.options && spec.options.cwd,
env: spec.options && spec.options.env,
detached: process.platform !== "win32"
});
this.seq = 1;
this.buffer = Buffer.alloc(0);
this.messages = [];
this.waiters = [];
this.stderr = "";
this.child.stdout.on("data", (chunk) => {
this.buffer = Buffer.concat([this.buffer, chunk]);
this.parse();
});
this.child.stderr.on("data", (chunk) => {
this.stderr += chunk.toString();
});
this.child.on("exit", () => this.flushWaiters());
}
send(command, args = {}) {
const seq = this.seq++;
const message = { seq, type: "request", command, arguments: args };
const payload = Buffer.from(JSON.stringify(message));
this.child.stdin.write(`Content-Length: ${payload.length}\r\n\r\n`);
this.child.stdin.write(payload);
return seq;
}
async response(seq, command) {
const message = await this.waitFor(
(item) =>
item.type === "response" &&
item.request_seq === seq &&
item.command === command
);
if (!message.success) {
throw new Error(
`DAP ${command} failed: ${message.message || JSON.stringify(message)}\n${this.stderr}`
);
}
return message;
}
terminate() {
if (this.child.exitCode !== null) return;
if (process.platform === "win32") {
this.child.kill("SIGKILL");
return;
}
try {
process.kill(-this.child.pid, "SIGKILL");
} catch (_) {
this.child.kill("SIGKILL");
}
}
waitFor(predicate, timeoutMs = 240000) {
const existing = this.messages.find(predicate);
if (existing) return Promise.resolve(existing);
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
this.terminate();
reject(new Error(`timed out waiting for DAP message\n${this.stderr}`));
}, timeoutMs);
this.waiters.push({ predicate, resolve, timer });
});
}
parse() {
while (true) {
const headerEnd = this.buffer.indexOf("\r\n\r\n");
if (headerEnd < 0) return;
const header = this.buffer.slice(0, headerEnd).toString();
const match = header.match(/Content-Length: (\d+)/i);
if (!match) throw new Error(`bad DAP header: ${header}`);
const length = Number(match[1]);
const start = headerEnd + 4;
const end = start + length;
if (this.buffer.length < end) return;
const payload = this.buffer.slice(start, end).toString();
this.buffer = this.buffer.slice(end);
this.messages.push(JSON.parse(payload));
this.flushWaiters();
}
}
flushWaiters() {
for (const waiter of [...this.waiters]) {
const message = this.messages.find(waiter.predicate);
if (!message) continue;
clearTimeout(waiter.timer);
this.waiters.splice(this.waiters.indexOf(waiter), 1);
waiter.resolve(message);
}
}
async close() {
if (this.child.exitCode !== null) return;
const seq = this.send("disconnect");
await this.response(seq, "disconnect");
this.child.stdin.end();
}
}
(async () => {
const repo = path.resolve(__dirname, "..");
const project = path.join(repo, "examples/launch-build-demo");
const buildSourceLines = fs
.readFileSync(path.join(project, "src/build.rs"), "utf8")
.split(/\r?\n/);
const sourceLine = (needle) => {
const index = buildSourceLines.findIndex((line) => line.includes(needle));
assert(index >= 0, `flagship source must contain ${needle}`);
return index + 1;
};
const buildMainLine = sourceLine("pub async fn build_main()");
const launchConfig = extension.resolveClusterfluxDebugConfiguration(
{ uri: { fsPath: project } },
{}
);
assert.strictEqual(launchConfig.type, "clusterflux");
assert.strictEqual(launchConfig.request, "launch");
assert.strictEqual(launchConfig.entry, "build");
assert.strictEqual(launchConfig.project, project);
assert.strictEqual(launchConfig.runtimeBackend, "local-services");
const inspection = extension.refreshBundleBeforeLaunch(project, repo);
assert.match(inspection.metadata.identity, /^sha256:/);
// Keep the timed attach focused on the runtime boundary. A completely fresh
// public checkout may otherwise spend most of that window compiling the
// coordinator or node after the adapter has already started waiting.
cp.execFileSync(
"cargo",
[
"build",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"-p",
"clusterflux-node",
"--bin",
"clusterflux-node",
],
{ cwd: repo, stdio: "inherit" }
);
const executableSuffix = process.platform === "win32" ? ".exe" : "";
const adapterSpec = extension.debugAdapterExecutableSpec(repo);
adapterSpec.options = {
...(adapterSpec.options || {}),
env: {
...process.env,
CLUSTERFLUX_COORDINATOR_BIN: path.join(
repo,
"target",
"debug",
`clusterflux-coordinator${executableSuffix}`
),
CLUSTERFLUX_NODE_BIN: path.join(
repo,
"target",
"debug",
`clusterflux-node${executableSuffix}`
),
},
};
const client = new DapClient(adapterSpec);
try {
const initialize = client.send("initialize", {
adapterID: "clusterflux",
linesStartAt1: true,
columnsStartAt1: true
});
await client.response(initialize, "initialize");
const launch = client.send("launch", launchConfig);
await client.response(launch, "launch");
await client.waitFor(
(message) => message.type === "event" && message.event === "initialized"
);
const breakpoints = client.send("setBreakpoints", {
source: { path: path.join(project, "src/build.rs") },
breakpoints: [{ line: buildMainLine }]
});
const breakpointResponse = await client.response(breakpoints, "setBreakpoints");
assert.strictEqual(breakpointResponse.body.breakpoints[0].verified, true);
const configurationDone = client.send("configurationDone");
await client.response(configurationDone, "configurationDone");
const stopped = await client.waitFor(
(message) => message.type === "event" && message.event === "stopped"
);
assert.strictEqual(stopped.body.allThreadsStopped, true);
assert.strictEqual(stopped.body.reason, "breakpoint");
const threadsRequest = client.send("threads");
const threads = (await client.response(threadsRequest, "threads")).body.threads;
const mainThread = threads.find((thread) => thread.name.includes("build coordinator main"));
assert(mainThread, "F5 launch must expose the real coordinator-main entrypoint thread");
const stackRequest = client.send("stackTrace", {
threadId: mainThread.id,
startFrame: 0,
levels: 1
});
const stack = (await client.response(stackRequest, "stackTrace")).body.stackFrames;
assert.strictEqual(stack[0].line, buildMainLine);
assert.strictEqual(stack[0].source.path, path.join(project, "src/build.rs"));
assert.strictEqual(stack[0].source.sourceReference || 0, 0);
const sourceRequest = client.send("source", { source: stack[0].source });
const source = (await client.response(sourceRequest, "source")).body;
assert.match(source.content, /compile_linux/);
const scopesRequest = client.send("scopes", { frameId: stack[0].id });
const scopes = (await client.response(scopesRequest, "scopes")).body.scopes;
const localsScope = scopes.find((scope) => scope.name === "Source Locals");
const argsScope = scopes.find((scope) => scope.name === "Task Args and Handles");
const runtimeScope = scopes.find((scope) => scope.name === "Clusterflux Runtime");
const outputScope = scopes.find((scope) => scope.name === "Recent Output");
assert(localsScope, "F5 launch must expose source locals scope");
assert(argsScope, "F5 launch must expose task args and handles");
assert(runtimeScope, "F5 launch must expose Clusterflux runtime state");
assert(outputScope, "F5 launch must expose recent output state");
const localsRequest = client.send("variables", {
variablesReference: localsScope.variablesReference
});
const locals = (await client.response(localsRequest, "variables")).body.variables;
assert(
locals.some(
(variable) =>
variable.name === "unavailable-local-diagnostic" &&
String(variable.value).includes("cannot be inspected")
),
"source locals scope must report unavailable real Rust locals explicitly"
);
const runtimeRequest = client.send("variables", {
variablesReference: runtimeScope.variablesReference
});
const runtime = (await client.response(runtimeRequest, "variables")).body.variables;
assert(
runtime.some(
(variable) => variable.name === "runtime_backend" && variable.value === "LocalServices"
),
"extension-resolved F5 launch must use the real local-services backend"
);
assert(
runtime.some(
(variable) => variable.name === "coordinator_task_events" && variable.value === 0
),
"a task frozen at its entry probe must not fabricate a terminal task event"
);
assert(
runtime.some(
(variable) =>
variable.name === "command_status" &&
String(variable.value).includes(
"frozen through local services at executing Wasm probe"
)
)
);
assert(
runtime.some(
(variable) => variable.name === "state" && variable.value === "Frozen"
),
"F5 must expose the node-acknowledged frozen participant state"
);
assert(runtime.some((variable) => variable.name === "command_spec"));
assert(runtime.some((variable) => variable.name === "stdout_tail"));
assert(runtime.some((variable) => variable.name === "stderr_tail"));
const outputRequest = client.send("variables", {
variablesReference: outputScope.variablesReference
});
const output = (await client.response(outputRequest, "variables")).body.variables;
assert(output.some((variable) => variable.name === "stdout_tail"));
assert(output.some((variable) => variable.name === "stderr_tail"));
await client.close();
} catch (error) {
client.terminate();
throw error;
}
console.log("VS Code F5 smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,172 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const fs = require("fs");
const path = require("path");
const repo = path.resolve(__dirname, "..");
const wasmTarget = path.join(
repo,
"target",
"wasm32-unknown-unknown",
"release",
"launch_build_demo.wasm"
);
cp.execFileSync(
"cargo",
[
"build",
"--release",
"-p",
"launch-build-demo",
"--target",
"wasm32-unknown-unknown",
],
{
cwd: repo,
stdio: "inherit",
env: {
...process.env,
CARGO_PROFILE_RELEASE_OPT_LEVEL: "z",
CARGO_PROFILE_RELEASE_LTO: "thin",
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: "1",
},
}
);
assert(fs.existsSync(wasmTarget), `missing compiled Wasm module at ${wasmTarget}`);
const output = cp.execFileSync(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-node",
"--bin",
"clusterflux-wasmtime-smoke",
"--",
wasmTarget,
"task_add_one",
"41",
"42",
],
{ cwd: repo, encoding: "utf8" }
);
const report = JSON.parse(output);
assert.strictEqual(report.type, "wasmtime_task_smoke");
assert.strictEqual(report.export, "task_add_one");
assert.strictEqual(report.arg, 41);
assert.strictEqual(report.result, 42);
const debugOutput = cp.execFileSync(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-node",
"--bin",
"clusterflux-wasmtime-smoke",
"--",
"--debug-freeze-resume",
wasmTarget,
"task_add_one",
"41",
"42",
],
{ cwd: repo, encoding: "utf8" }
);
const debugReport = JSON.parse(debugOutput);
assert.strictEqual(debugReport.type, "wasmtime_debug_freeze_resume_smoke");
assert.strictEqual(debugReport.export, "task_add_one");
assert.strictEqual(debugReport.task, "task_add_one");
assert.strictEqual(debugReport.frozen_state, "Frozen");
assert.strictEqual(debugReport.resumed_state, "Running");
assert(debugReport.stack_frames.some((frame) => String(frame).includes("task_add_one")));
assert(
debugReport.local_values.some(
([name, value]) => name === "wasm_local_0" && String(value).includes("41")
),
"Wasmtime debug snapshot must expose the real i32 argument as a frame local"
);
assert.strictEqual(debugReport.node_runtime_captured_wasm_locals, true);
assert.strictEqual(debugReport.result, 42);
assert.strictEqual(debugReport.node_runtime_reached_wasm_task, true);
const hostCommandOutput = cp.execFileSync(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-node",
"--bin",
"clusterflux-wasmtime-smoke",
"--",
"--host-command",
wasmTarget,
"compile_linux",
],
{ cwd: repo, encoding: "utf8" }
);
const hostCommandReport = JSON.parse(hostCommandOutput);
assert.strictEqual(hostCommandReport.type, "wasmtime_host_command_smoke");
assert.strictEqual(hostCommandReport.task, "compile_linux");
assert.match(hostCommandReport.export, /^clusterflux_task_v1_[0-9a-f]{64}$/);
assert.strictEqual(hostCommandReport.program, "cc");
assert.deepStrictEqual(hostCommandReport.args, [
"-Os",
"-static",
"-s",
"fixture/hello-clusterflux.c",
"-o",
"/clusterflux/output/hello-clusterflux",
]);
assert.strictEqual(hostCommandReport.working_directory, "/workspace");
assert.deepStrictEqual(hostCommandReport.environment_variables, {
SOURCE_DATE_EPOCH: "0",
});
assert.strictEqual(hostCommandReport.timeout_ms, 180000);
assert.strictEqual(hostCommandReport.network, "disabled");
assert.strictEqual(hostCommandReport.status_code, 0);
assert.strictEqual(hostCommandReport.stdout, "");
assert.strictEqual(hostCommandReport.artifact_name, "hello-clusterflux");
assert.strictEqual(hostCommandReport.artifact_size_bytes, "hello-clusterflux".length);
assert.match(hostCommandReport.artifact_digest, /^sha256:[0-9a-f]{64}$/);
assert.strictEqual(hostCommandReport.node_host_import, "clusterflux.command_run_v1");
assert.strictEqual(hostCommandReport.artifact_host_import, "clusterflux.vfs_operation_v1");
assert.strictEqual(hostCommandReport.flagship_linux_build_task, true);
assert.strictEqual(hostCommandReport.node_executed_host_command, true);
assert.strictEqual(hostCommandReport.hosted_control_plane_ran_command, false);
const artifactOutput = cp.execFileSync(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-node",
"--bin",
"clusterflux-wasmtime-smoke",
"--",
"--task-artifact",
wasmTarget,
"package_release",
],
{ cwd: repo, encoding: "utf8" }
);
const artifactReport = JSON.parse(artifactOutput);
assert.strictEqual(artifactReport.type, "wasmtime_task_artifact_smoke");
assert.strictEqual(artifactReport.task, "package_release");
assert.strictEqual(artifactReport.artifact_name, "release.tar");
assert.strictEqual(artifactReport.artifact_size_bytes, "release.tar".length);
assert.match(artifactReport.artifact_digest, /^sha256:[0-9a-f]{64}$/);
assert.strictEqual(artifactReport.host_import, "clusterflux.vfs_operation_v1");
assert.strictEqual(artifactReport.host_issued_handle_returned, true);
assert.ok(artifactReport.artifact.id.endsWith(artifactReport.artifact_digest.slice("sha256:".length)));
console.log("Wasmtime node smoke passed");

View file

@ -0,0 +1,302 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const crypto = require("crypto");
const fs = require("fs");
const net = require("net");
const path = require("path");
const { coordinatorWireRequest } = require("./coordinator-wire");
const { nodeIdentity, signedNodeRequest } = require("./node-signing");
const repo = path.resolve(__dirname, "..");
const digest = (value) =>
`sha256:${crypto.createHash("sha256").update(value).digest("hex")}`;
const environmentDigest = digest("windows-command-dev-environment");
const sourceDigest = digest("windows-best-effort-source");
const windowsArtifactBytes = Buffer.from("windows-output-data");
const windowsArtifactDigest = digest(windowsArtifactBytes);
const emptyWasm = Buffer.from([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
const emptyWasmDigest = digest(emptyWasm);
const nodeDaemon = fs.readFileSync(path.join(repo, "crates/clusterflux-node/src/daemon.rs"), "utf8");
const taskReports = fs.readFileSync(
path.join(repo, "crates/clusterflux-node/src/task_reports.rs"),
"utf8"
);
const nodeLib = fs.readFileSync(path.join(repo, "crates/clusterflux-node/src/lib.rs"), "utf8");
const windowsDev = fs.readFileSync(
path.join(repo, "crates/clusterflux-node/src/windows_dev.rs"),
"utf8"
);
const executionCore = fs.readFileSync(
path.join(repo, "crates/clusterflux-core/src/execution.rs"),
"utf8"
);
const dapSource = [
fs.readFileSync(path.join(repo, "crates/clusterflux-dap/src/demo_backend.rs"), "utf8"),
fs.readFileSync(path.join(repo, "crates/clusterflux-dap/src/tests.rs"), "utf8"),
].join("\n");
const windowsNode = "windows-node";
const windowsIdentity = nodeIdentity("windows-best-effort-smoke", windowsNode);
function waitForJsonLine(child) {
return new Promise((resolve, reject) => {
let buffer = "";
child.stdout.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
try {
resolve(JSON.parse(buffer.slice(0, newline).trim()));
} catch (error) {
reject(error);
}
});
child.once("exit", (code) => {
reject(new Error(`process exited before JSON line with code ${code}`));
});
});
}
function send(addr, message) {
return new Promise((resolve, reject) => {
const socket = net.connect(addr.port, addr.host, () => {
socket.write(`${JSON.stringify(coordinatorWireRequest(message))}\n`);
});
let buffer = "";
socket.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
socket.end();
try {
resolve(JSON.parse(buffer.slice(0, newline)));
} catch (error) {
reject(error);
}
});
socket.on("error", reject);
});
}
function windowsCapabilities() {
return {
os: "Windows",
arch: "x86_64",
capabilities: ["Command", "VfsArtifacts", "WindowsCommandDev"],
environment_backends: ["WindowsCommandDev"],
source_providers: ["filesystem"]
};
}
function assertWindowsBackendBoundary() {
assert.match(nodeDaemon, /CoordinatorSession::connect\(&args\.coordinator\)/);
assert.match(nodeDaemon, /record_completed_task\(/);
assert.match(taskReports, /"type": "task_completed"/);
assert.doesNotMatch(nodeDaemon, /WindowsCommandDev|windows-command-dev|cfg\(windows\)/);
assert.match(nodeLib, /impl CommandBackend for LinuxRootlessPodmanBackend/);
assert.match(nodeLib, /mod windows_dev/);
assert.match(nodeLib, /pub use windows_dev::\{WindowsCommandDevBackend, WindowsSandboxStubBackend\}/);
assert.match(windowsDev, /impl CommandBackend for WindowsCommandDevBackend/);
assert.match(windowsDev, /impl CommandBackend for WindowsSandboxStubBackend/);
assert.doesNotMatch(windowsDev, /LinuxRootlessPodmanBackend/);
assert.match(executionCore, /\bLinuxRootlessPodman\b/);
assert.match(executionCore, /\bWindowsCommandDev\b/);
assert.match(executionCore, /\bStubbedWindowsSandbox\b/);
assert.match(dapSource, /thread\(WINDOWS_THREAD, "compile-windows", "compile windows"/);
assert.match(dapSource, /fn launch_threads_include_windows_task_in_same_virtual_process\(\)/);
assert.match(dapSource, /fn windows_thread_runtime_variables_share_virtual_process\(\)/);
}
(async () => {
assertWindowsBackendBoundary();
const coordinator = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"--",
"--listen",
"127.0.0.1:0",
"--allow-local-trusted-loopback"
],
{ cwd: repo }
);
let coordinatorStderr = "";
coordinator.stderr.on("data", (chunk) => {
coordinatorStderr += chunk.toString();
});
try {
const ready = await waitForJsonLine(coordinator);
const [host, portText] = ready.listen.split(":");
const addr = { host, port: Number(portText) };
assert.strictEqual((await send(addr, { type: "ping" })).type, "pong");
const attached = await send(addr, {
type: "attach_node",
tenant: "tenant",
project: "project",
node: windowsNode,
public_key: windowsIdentity.publicKey
});
assert.strictEqual(attached.type, "node_attached");
assert.strictEqual(attached.node, windowsNode);
const recorded = await send(addr, signedNodeRequest(windowsNode, windowsIdentity, "report_node_capabilities", {
type: "report_node_capabilities",
tenant: "tenant",
project: "project",
node: windowsNode,
capabilities: windowsCapabilities(),
cached_environment_digests: [environmentDigest],
dependency_cache_digests: [],
source_snapshots: [sourceDigest],
artifact_locations: [],
direct_connectivity: true,
online: true
}));
assert.strictEqual(recorded.type, "node_capabilities_recorded");
assert.strictEqual(recorded.node, windowsNode);
const placement = await send(addr, {
type: "schedule_task",
tenant: "tenant",
project: "project",
environment: {
os: "Windows",
arch: null,
capabilities: ["WindowsCommandDev"]
},
environment_digest: environmentDigest,
required_capabilities: ["Command"],
dependency_cache: null,
source_snapshot: sourceDigest,
required_artifacts: [],
prefer_node: null
});
assert.strictEqual(placement.type, "task_placement");
assert.strictEqual(placement.placement.node, windowsNode);
assert.ok(placement.placement.reasons.includes("warm environment cache"));
assert.ok(placement.placement.reasons.includes("source snapshot already local"));
const started = await send(addr, {
type: "start_process",
tenant: "tenant",
project: "project",
process: "vp-windows"
});
assert.strictEqual(started.type, "process_started");
assert.strictEqual(started.process, "vp-windows");
const reconnected = await send(addr, signedNodeRequest(windowsNode, windowsIdentity, "reconnect_node", {
type: "reconnect_node",
node: windowsNode,
process: "vp-windows",
epoch: started.epoch
}));
assert.strictEqual(reconnected.type, "node_reconnected");
const launched = await send(addr, {
type: "launch_task",
tenant: "tenant",
project: "project",
actor_user: "operator",
task_spec: {
tenant: "tenant",
project: "project",
process: "vp-windows",
task_definition: "windows-command-dev",
task_instance: "windows-command-dev",
dispatch: {
kind: "coordinator_node_wasm",
export: "windows_command_dev",
abi: "task_v1",
},
environment_id: "windows",
environment: {
os: "Windows",
arch: null,
capabilities: ["WindowsCommandDev"],
},
environment_digest: environmentDigest,
required_capabilities: ["Command", "WindowsCommandDev"],
dependency_cache: null,
source_snapshot: sourceDigest,
required_artifacts: [],
args: [],
vfs_epoch: started.epoch,
bundle_digest: emptyWasmDigest,
},
wait_for_node: false,
artifact_path: "/vfs/artifacts/windows-output.txt",
wasm_module_base64: emptyWasm.toString("base64"),
});
assert.strictEqual(launched.type, "task_launched", JSON.stringify(launched));
assert.strictEqual(launched.placement.node, windowsNode);
const recordedTask = await send(addr, signedNodeRequest(windowsNode, windowsIdentity, "task_completed", {
type: "task_completed",
tenant: "tenant",
project: "project",
process: "vp-windows",
node: windowsNode,
task: "windows-command-dev",
status_code: 0,
stdout_bytes: 18,
stderr_bytes: 0,
stdout_tail: "",
stderr_tail: "",
stdout_truncated: false,
stderr_truncated: false,
artifact_path: "/vfs/artifacts/windows-output.txt",
artifact_digest: windowsArtifactDigest,
artifact_size_bytes: windowsArtifactBytes.length
}));
assert.strictEqual(recordedTask.type, "task_recorded");
assert.strictEqual(recordedTask.task, "windows-command-dev");
const events = await send(addr, {
type: "list_task_events",
tenant: "tenant",
project: "project",
actor_user: "user",
process: "vp-windows"
});
assert.strictEqual(events.type, "task_events");
assert.strictEqual(events.events.length, 1);
assert.strictEqual(events.events[0].node, "windows-node");
assert.strictEqual(events.events[0].artifact_path, "/vfs/artifacts/windows-output.txt");
const link = await send(addr, {
type: "create_artifact_download_link",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact: "windows-output.txt",
max_bytes: 1024
});
assert.strictEqual(link.type, "artifact_download_link");
assert.strictEqual(link.link.process, "vp-windows");
assert.deepStrictEqual(link.link.source, { RetainedNode: "windows-node" });
} catch (error) {
if (coordinatorStderr) {
error.message = `${error.message}\ncoordinator stderr:\n${coordinatorStderr}`;
}
throw error;
} finally {
coordinator.kill("SIGTERM");
}
console.log("Windows best-effort smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});

479
scripts/windows-runner-smoke.js Executable file
View file

@ -0,0 +1,479 @@
#!/usr/bin/env node
const assert = require("assert");
const cp = require("child_process");
const crypto = require("crypto");
const fs = require("fs");
const net = require("net");
const path = require("path");
const { coordinatorWireRequest } = require("./coordinator-wire");
const { nodeIdentity, signedNodeRequest } = require("./node-signing");
const repo = path.resolve(__dirname, "..");
const forgejoWindowsNode = "forgejo-windows-node";
const forgejoWindowsIdentity = nodeIdentity("windows-runner-smoke", forgejoWindowsNode);
const windowsEnvironmentDigest = `sha256:${crypto
.createHash("sha256")
.update("clusterflux/windows-command-dev/v1")
.digest("hex")}`;
const sourceSnapshot = `sha256:${crypto
.createHash("sha256")
.update("clusterflux/windows-runner/source/v1")
.digest("hex")}`;
class DapClient {
constructor() {
this.child = cp.spawn(
"cargo",
["run", "-q", "-p", "clusterflux-dap", "--bin", "clusterflux-debug-dap"],
{ cwd: repo }
);
this.seq = 1;
this.buffer = Buffer.alloc(0);
this.messages = [];
this.waiters = [];
this.stderr = "";
this.child.stdout.on("data", (chunk) => {
this.buffer = Buffer.concat([this.buffer, chunk]);
this.parse();
});
this.child.stderr.on("data", (chunk) => {
this.stderr += chunk.toString();
});
this.child.on("exit", () => this.flushWaiters());
}
send(command, args = {}) {
const seq = this.seq++;
const message = { seq, type: "request", command, arguments: args };
const payload = Buffer.from(JSON.stringify(coordinatorWireRequest(message)));
this.child.stdin.write(`Content-Length: ${payload.length}\r\n\r\n`);
this.child.stdin.write(payload);
return seq;
}
async response(seq, command) {
const message = await this.waitFor(
(item) =>
item.type === "response" &&
item.request_seq === seq &&
item.command === command
);
if (!message.success) {
throw new Error(`DAP ${command} failed: ${message.message || JSON.stringify(coordinatorWireRequest(message))}`);
}
return message;
}
waitFor(predicate, timeoutMs = 120000) {
const existing = this.messages.find(predicate);
if (existing) return Promise.resolve(existing);
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
this.child.kill("SIGKILL");
reject(new Error(`timed out waiting for DAP message\n${this.stderr}`));
}, timeoutMs);
this.waiters.push({ predicate, resolve, timer });
});
}
parse() {
while (true) {
const headerEnd = this.buffer.indexOf("\r\n\r\n");
if (headerEnd < 0) return;
const header = this.buffer.slice(0, headerEnd).toString();
const match = header.match(/Content-Length: (\d+)/i);
if (!match) throw new Error(`bad DAP header: ${header}`);
const length = Number(match[1]);
const start = headerEnd + 4;
const end = start + length;
if (this.buffer.length < end) return;
const payload = this.buffer.slice(start, end).toString();
this.buffer = this.buffer.slice(end);
this.messages.push(JSON.parse(payload));
this.flushWaiters();
}
}
flushWaiters() {
for (const waiter of [...this.waiters]) {
const message = this.messages.find(waiter.predicate);
if (!message) continue;
clearTimeout(waiter.timer);
this.waiters.splice(this.waiters.indexOf(waiter), 1);
waiter.resolve(message);
}
}
async close() {
if (this.child.exitCode !== null) return;
const seq = this.send("disconnect");
await this.response(seq, "disconnect");
this.child.stdin.end();
}
}
function waitForJsonLine(child) {
return new Promise((resolve, reject) => {
let buffer = "";
child.stdout.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
try {
resolve(JSON.parse(buffer.slice(0, newline).trim()));
} catch (error) {
reject(error);
}
});
child.once("exit", (code) => {
reject(new Error(`process exited before JSON line with code ${code}`));
});
});
}
function send(addr, message) {
return new Promise((resolve, reject) => {
const socket = net.connect(addr.port, addr.host, () => {
socket.write(`${JSON.stringify(coordinatorWireRequest(message))}\n`);
});
let buffer = "";
socket.on("data", (chunk) => {
buffer += chunk.toString();
const newline = buffer.indexOf("\n");
if (newline < 0) return;
socket.end();
try {
resolve(JSON.parse(buffer.slice(0, newline)));
} catch (error) {
reject(error);
}
});
socket.on("error", reject);
});
}
function runWindowsAttach(addr, grant) {
return new Promise((resolve, reject) => {
const child = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-cli",
"--bin",
"clusterflux",
"--",
"node",
"attach",
"--coordinator",
`${addr.host}:${addr.port}`,
"--tenant",
"tenant",
"--project-id",
"project",
"--node",
forgejoWindowsNode,
"--public-key",
forgejoWindowsIdentity.publicKey,
"--enrollment-grant",
grant,
"--cap",
"windows-command-dev",
"--json"
],
{
cwd: repo,
env: {
...process.env,
CLUSTERFLUX_NODE_PRIVATE_KEY: forgejoWindowsIdentity.privateKey,
},
}
);
let stdout = "";
let stderr = "";
child.stdout.on("data", (chunk) => {
stdout += chunk.toString();
});
child.stderr.on("data", (chunk) => {
stderr += chunk.toString();
});
child.on("exit", (code) => {
if (code !== 0) {
reject(new Error(`Windows node attach failed with code ${code}\n${stderr}`));
return;
}
try {
resolve(JSON.parse(stdout));
} catch (error) {
reject(
new Error(`Windows node attach output was not JSON: ${stdout}\n${error.stack || error.message}`)
);
}
});
});
}
function runWindowsNode(addr, grant) {
return new Promise((resolve, reject) => {
const child = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-node",
"--bin",
"clusterflux-node",
"--",
"--coordinator",
`${addr.host}:${addr.port}`,
"--tenant",
"tenant",
"--project-id",
"project",
"--node",
forgejoWindowsNode,
"--public-key",
forgejoWindowsIdentity.publicKey,
"--enrollment-grant",
grant,
"--process",
"vp-forgejo-windows",
"--task",
"windows-command-dev",
"--command",
"cmd",
"--arg",
"/C",
"--arg",
"echo clusterflux-windows-runner",
"--artifact",
"/vfs/artifacts/windows-runner-output.txt"
],
{
cwd: repo,
env: {
...process.env,
CLUSTERFLUX_NODE_PRIVATE_KEY: forgejoWindowsIdentity.privateKey,
},
}
);
let stdout = "";
let stderr = "";
child.stdout.on("data", (chunk) => {
stdout += chunk.toString();
});
child.stderr.on("data", (chunk) => {
stderr += chunk.toString();
});
child.on("exit", (code) => {
if (code !== 0) {
reject(new Error(`Windows node smoke failed with code ${code}\n${stderr}`));
return;
}
try {
resolve(JSON.parse(stdout.trim().split(/\r?\n/).at(-1)));
} catch (error) {
reject(new Error(`node output was not JSON: ${stdout}\n${error.stack || error.message}`));
}
});
});
}
async function assertDebuggerShowsWindowsThread() {
const client = new DapClient();
try {
const initialize = client.send("initialize", {
adapterID: "clusterflux",
linesStartAt1: true,
columnsStartAt1: true
});
await client.response(initialize, "initialize");
const launch = client.send("launch", {
entry: "build",
project: path.join(repo, "examples/launch-build-demo"),
runtimeBackend: "simulated"
});
await client.response(launch, "launch");
await client.waitFor(
(message) => message.type === "event" && message.event === "initialized"
);
const configurationDone = client.send("configurationDone");
await client.response(configurationDone, "configurationDone");
const threadsRequest = client.send("threads");
const threads = (await client.response(threadsRequest, "threads")).body.threads;
assert(
threads.some((thread) => thread.name.includes("compile windows")),
"debugger must represent the Windows task as a virtual thread"
);
await client.close();
} catch (error) {
client.child.kill("SIGKILL");
throw error;
}
}
(async () => {
if (process.platform !== "win32") {
throw new Error(
`Windows runner validation requires win32; current platform is ${process.platform}`
);
}
const coordinator = cp.spawn(
"cargo",
[
"run",
"-q",
"-p",
"clusterflux-coordinator",
"--bin",
"clusterflux-coordinator",
"--",
"--listen",
"127.0.0.1:0",
"--allow-local-trusted-loopback"
],
{ cwd: repo }
);
let coordinatorStderr = "";
coordinator.stderr.on("data", (chunk) => {
coordinatorStderr += chunk.toString();
});
try {
const ready = await waitForJsonLine(coordinator);
const [host, portText] = ready.listen.split(":");
const addr = { host, port: Number(portText) };
assert.strictEqual((await send(addr, { type: "ping" })).type, "pong");
const attachGrant = await send(addr, {
type: "create_node_enrollment_grant",
tenant: "tenant",
project: "project",
actor_user: "operator",
ttl_seconds: 900
});
assert.strictEqual(attachGrant.type, "node_enrollment_grant_created");
assert.strictEqual(attachGrant.scope, "node:attach");
const attach = await runWindowsAttach(addr, attachGrant.grant);
assert.strictEqual(attach.plan.node, forgejoWindowsNode);
assert.strictEqual(attach.boundary.cli_contacted_coordinator, true);
assert.strictEqual(attach.boundary.used_enrollment_exchange, true);
assert.strictEqual(attach.coordinator_response.type, "node_enrollment_exchanged");
assert.strictEqual(attach.coordinator_response.credential.scope, "node:attach");
assert(attach.plan.capabilities.capabilities.includes("WindowsCommandDev"));
const runtimeGrant = await send(addr, {
type: "create_node_enrollment_grant",
tenant: "tenant",
project: "project",
actor_user: "operator",
ttl_seconds: 900
});
assert.strictEqual(runtimeGrant.type, "node_enrollment_grant_created");
const report = await runWindowsNode(addr, runtimeGrant.grant);
assert.strictEqual(report.node_status, "completed");
assert.strictEqual(report.virtual_thread, "windows-command-dev");
assert.strictEqual(report.status_code, 0);
assert.strictEqual(report.large_bytes_uploaded, false);
assert.strictEqual(
report.staged_artifact.path,
"/vfs/artifacts/windows-runner-output.txt"
);
assert.strictEqual(report.registration_response.type, "node_enrollment_exchanged");
assert.strictEqual(report.registration_response.credential.scope, "node:attach");
assert.strictEqual(report.coordinator_response.type, "task_recorded");
const recorded = await send(addr, signedNodeRequest(forgejoWindowsNode, forgejoWindowsIdentity, "report_node_capabilities", {
type: "report_node_capabilities",
tenant: "tenant",
project: "project",
node: forgejoWindowsNode,
capabilities: {
os: "Windows",
arch: "x86_64",
capabilities: ["Command", "WindowsCommandDev", "VfsArtifacts"],
environment_backends: ["WindowsCommandDev"],
source_providers: ["filesystem"]
},
cached_environment_digests: [windowsEnvironmentDigest],
source_snapshots: [sourceSnapshot],
artifact_locations: ["windows-runner-output.txt"],
direct_connectivity: true,
online: true
}));
assert.strictEqual(recorded.type, "node_capabilities_recorded");
const placement = await send(addr, {
type: "schedule_task",
tenant: "tenant",
project: "project",
environment: {
os: "Windows",
arch: null,
capabilities: ["WindowsCommandDev"]
},
environment_digest: windowsEnvironmentDigest,
required_capabilities: ["Command"],
source_snapshot: sourceSnapshot,
required_artifacts: ["windows-runner-output.txt"],
prefer_node: null
});
assert.strictEqual(placement.type, "task_placement");
assert.strictEqual(placement.placement.node, "forgejo-windows-node");
const link = await send(addr, {
type: "create_artifact_download_link",
tenant: "tenant",
project: "project",
actor_user: "user",
artifact: "windows-runner-output.txt",
max_bytes: 1024
});
assert.strictEqual(link.type, "artifact_download_link");
assert.deepStrictEqual(link.link.source, {
RetainedNode: "forgejo-windows-node"
});
} catch (error) {
if (coordinatorStderr) {
error.message = `${error.message}\ncoordinator stderr:\n${coordinatorStderr}`;
}
throw error;
} finally {
coordinator.kill("SIGTERM");
}
await assertDebuggerShowsWindowsThread();
const outDir = path.join(repo, "target", "acceptance");
fs.mkdirSync(outDir, { recursive: true });
fs.writeFileSync(
path.join(outDir, "windows-runner.json"),
`${JSON.stringify(
{
kind: "clusterflux_windows_runner_validation",
platform: process.platform,
runner: process.env.FORGEJO_RUNNER_NAME || process.env.RUNNER_NAME || null,
validated: true
},
null,
2
)}\n`
);
console.log("Windows runner smoke passed");
})().catch((error) => {
console.error(error.stack || error.message);
process.exit(1);
});