Public dry run dryrun-1714a9eedd5b
Source commit: 1714a9eedd5b1e30c6c9aceb7a999f2f695ba83c Public tree identity: sha256:e5daffad23fa7c7f1822adccd3c3b4ee0bc7f1a45e0d321eb9a6fb8282b269db
This commit is contained in:
commit
20c72e6066
102 changed files with 32054 additions and 0 deletions
270
scripts/node-attach-smoke.js
Executable file
270
scripts/node-attach-smoke.js
Executable file
|
|
@ -0,0 +1,270 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const assert = require("assert");
|
||||
const cp = require("child_process");
|
||||
const net = require("net");
|
||||
const path = require("path");
|
||||
|
||||
const repo = path.resolve(__dirname, "..");
|
||||
const demoProject = path.join(repo, "examples/launch-build-demo");
|
||||
|
||||
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(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 runAttach(addr, grant) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = cp.spawn(
|
||||
"cargo",
|
||||
[
|
||||
"run",
|
||||
"-q",
|
||||
"-p",
|
||||
"disasmer-cli",
|
||||
"--bin",
|
||||
"disasmer",
|
||||
"--",
|
||||
"node",
|
||||
"attach",
|
||||
"--coordinator",
|
||||
`${addr.host}:${addr.port}`,
|
||||
"--tenant",
|
||||
"tenant",
|
||||
"--project-id",
|
||||
"project",
|
||||
"--node",
|
||||
"node-attach",
|
||||
"--public-key",
|
||||
"node-attach-public-key",
|
||||
"--enrollment-grant",
|
||||
grant,
|
||||
"--cap",
|
||||
"quic-direct",
|
||||
],
|
||||
{ cwd: repo }
|
||||
);
|
||||
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}`)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function runAttachedNodeWork(addr) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = cp.spawn(
|
||||
"cargo",
|
||||
[
|
||||
"run",
|
||||
"-q",
|
||||
"-p",
|
||||
"disasmer-node",
|
||||
"--bin",
|
||||
"disasmer-node",
|
||||
"--",
|
||||
"--coordinator",
|
||||
`${addr.host}:${addr.port}`,
|
||||
"--tenant",
|
||||
"tenant",
|
||||
"--project-id",
|
||||
"project",
|
||||
"--node",
|
||||
"node-attach",
|
||||
"--process",
|
||||
"vp-node-attach",
|
||||
"--task",
|
||||
"compile-linux",
|
||||
"--project",
|
||||
demoProject,
|
||||
"--artifact",
|
||||
"/vfs/artifacts/node-attach-output.txt",
|
||||
],
|
||||
{ cwd: repo }
|
||||
);
|
||||
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(`attached node work failed with code ${code}\n${stderr}`));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
resolve(JSON.parse(stdout.trim().split("\n").at(-1)));
|
||||
} catch (error) {
|
||||
reject(
|
||||
new Error(
|
||||
`attached node work output was not JSON: ${stdout}\n${error.stack || error.message}`
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const coordinator = cp.spawn(
|
||||
"cargo",
|
||||
[
|
||||
"run",
|
||||
"-q",
|
||||
"-p",
|
||||
"disasmer-coordinator",
|
||||
"--bin",
|
||||
"disasmer-coordinator",
|
||||
"--",
|
||||
"--listen",
|
||||
"127.0.0.1:0",
|
||||
],
|
||||
{ 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",
|
||||
grant: "grant-node-attach",
|
||||
now_epoch_seconds: 0,
|
||||
ttl_seconds: 900
|
||||
});
|
||||
assert.strictEqual(grant.type, "node_enrollment_grant_created");
|
||||
assert.strictEqual(grant.tenant, "tenant");
|
||||
assert.strictEqual(grant.project, "project");
|
||||
assert.strictEqual(grant.grant, "grant-node-attach");
|
||||
assert.strictEqual(grant.scope, "node:attach");
|
||||
assert.strictEqual(grant.expires_at_epoch_seconds, 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-node-attach");
|
||||
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.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",
|
||||
});
|
||||
assert.strictEqual(heartbeat.type, "node_heartbeat");
|
||||
assert.strictEqual(heartbeat.node, "node-attach");
|
||||
|
||||
const work = await runAttachedNodeWork(addr);
|
||||
assert.strictEqual(work.node_status, "completed");
|
||||
assert.strictEqual(work.virtual_thread, "compile-linux");
|
||||
assert.strictEqual(work.status_code, 0);
|
||||
assert.strictEqual(work.large_bytes_uploaded, false);
|
||||
assert.strictEqual(
|
||||
work.staged_artifact.path,
|
||||
"/vfs/artifacts/node-attach-output.txt"
|
||||
);
|
||||
assert.strictEqual(work.coordinator_response.type, "task_recorded");
|
||||
|
||||
const events = await send(addr, {
|
||||
type: "list_task_events",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
actor_user: "operator",
|
||||
process: "vp-node-attach",
|
||||
});
|
||||
assert.strictEqual(events.type, "task_events");
|
||||
assert.strictEqual(events.events.length, 1);
|
||||
assert.strictEqual(events.events[0].node, "node-attach");
|
||||
assert.strictEqual(events.events[0].task, "compile-linux");
|
||||
assert.strictEqual(
|
||||
events.events[0].artifact_path,
|
||||
"/vfs/artifacts/node-attach-output.txt"
|
||||
);
|
||||
} finally {
|
||||
coordinator.kill("SIGTERM");
|
||||
}
|
||||
|
||||
console.log("Node attach smoke passed");
|
||||
})().catch((error) => {
|
||||
console.error(error.stack || error.message);
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue