Public release release-b8454b34d38c
Source commit: b8454b34d38cc2ba0bd278e842060db45d091e1c Public tree identity: sha256:69d6c8143bf6227e1bb07852aa94e8af9c26793eca252bb46788894f728cb6d2
This commit is contained in:
commit
d2e84229c5
221 changed files with 80960 additions and 0 deletions
299
scripts/windows-best-effort-smoke.js
Executable file
299
scripts/windows-best-effort-smoke.js
Executable file
|
|
@ -0,0 +1,299 @@
|
|||
#!/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: [{ SourceSnapshot: sourceDigest }],
|
||||
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, "error", JSON.stringify(launched));
|
||||
assert.match(launched.message, /external callers may launch only EntrypointV1/);
|
||||
|
||||
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, "error");
|
||||
assert.match(recordedTask.message, /coordinator-issued task instance|issued active task|active task/);
|
||||
|
||||
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, 0);
|
||||
|
||||
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, "error");
|
||||
assert.match(link.message, /does not exist|not found|unavailable/);
|
||||
} 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);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue