Source commit: 1714a9eedd5b1e30c6c9aceb7a999f2f695ba83c Public tree identity: sha256:e5daffad23fa7c7f1822adccd3c3b4ee0bc7f1a45e0d321eb9a6fb8282b269db
235 lines
7.6 KiB
JavaScript
Executable file
235 lines
7.6 KiB
JavaScript
Executable file
#!/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 nodeMain = fs.readFileSync(path.join(repo, "crates/disasmer-node/src/main.rs"), "utf8");
|
|
const nodeLib = fs.readFileSync(path.join(repo, "crates/disasmer-node/src/lib.rs"), "utf8");
|
|
const executionCore = fs.readFileSync(
|
|
path.join(repo, "crates/disasmer-core/src/execution.rs"),
|
|
"utf8"
|
|
);
|
|
const dapMain = fs.readFileSync(path.join(repo, "crates/disasmer-dap/src/main.rs"), "utf8");
|
|
|
|
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 windowsCapabilities() {
|
|
return {
|
|
os: "Windows",
|
|
arch: "x86_64",
|
|
capabilities: ["Command", "WindowsCommandDev", "VfsArtifacts"],
|
|
environment_backends: ["WindowsCommandDev"],
|
|
source_providers: ["filesystem"]
|
|
};
|
|
}
|
|
|
|
function assertWindowsBackendBoundary() {
|
|
assert.match(nodeMain, /CoordinatorSession::connect\(&args\.coordinator\)/);
|
|
assert.match(nodeMain, /"type": "task_completed"/);
|
|
assert.doesNotMatch(nodeMain, /WindowsCommandDev|windows-command-dev|cfg\(windows\)/);
|
|
|
|
const linuxStart = nodeLib.indexOf("impl CommandBackend for LinuxRootlessPodmanBackend");
|
|
const windowsStart = nodeLib.indexOf("pub struct WindowsCommandDevBackend");
|
|
assert(linuxStart >= 0, "Linux backend implementation must be present");
|
|
assert(windowsStart > linuxStart, "Windows backend must be separate from Linux backend");
|
|
const linuxBackend = nodeLib.slice(linuxStart, windowsStart);
|
|
assert.doesNotMatch(linuxBackend, /WindowsCommandDev|WindowsSandbox|windows-command-dev/);
|
|
assert.match(nodeLib, /impl CommandBackend for WindowsCommandDevBackend/);
|
|
assert.match(nodeLib, /impl CommandBackend for WindowsSandboxStubBackend/);
|
|
assert.match(executionCore, /\bLinuxRootlessPodman\b/);
|
|
assert.match(executionCore, /\bWindowsCommandDev\b/);
|
|
assert.match(executionCore, /\bStubbedWindowsSandbox\b/);
|
|
|
|
assert.match(dapMain, /thread\(WINDOWS_THREAD, "compile-windows", "compile windows"/);
|
|
assert.match(dapMain, /fn launch_threads_include_windows_task_in_same_virtual_process\(\)/);
|
|
assert.match(dapMain, /fn windows_thread_runtime_variables_share_virtual_process\(\)/);
|
|
}
|
|
|
|
(async () => {
|
|
assertWindowsBackendBoundary();
|
|
|
|
const coordinator = cp.spawn(
|
|
"cargo",
|
|
[
|
|
"run",
|
|
"-q",
|
|
"-p",
|
|
"disasmer-coordinator",
|
|
"--bin",
|
|
"disasmer-coordinator",
|
|
"--",
|
|
"--listen",
|
|
"127.0.0.1:0"
|
|
],
|
|
{ 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: "windows-node",
|
|
public_key: "windows-node-public-key"
|
|
});
|
|
assert.strictEqual(attached.type, "node_attached");
|
|
assert.strictEqual(attached.node, "windows-node");
|
|
|
|
const recorded = await send(addr, {
|
|
type: "report_node_capabilities",
|
|
tenant: "tenant",
|
|
project: "project",
|
|
node: "windows-node",
|
|
capabilities: windowsCapabilities(),
|
|
cached_environment_digests: ["sha256:env-windows-command-dev"],
|
|
source_snapshots: ["sha256:source-tree"],
|
|
artifact_locations: [],
|
|
direct_connectivity: true,
|
|
online: true
|
|
});
|
|
assert.strictEqual(recorded.type, "node_capabilities_recorded");
|
|
assert.strictEqual(recorded.node, "windows-node");
|
|
|
|
const placement = await send(addr, {
|
|
type: "schedule_task",
|
|
tenant: "tenant",
|
|
project: "project",
|
|
environment: {
|
|
os: "Windows",
|
|
arch: null,
|
|
capabilities: ["WindowsCommandDev"]
|
|
},
|
|
environment_digest: "sha256:env-windows-command-dev",
|
|
required_capabilities: ["Command"],
|
|
source_snapshot: "sha256:source-tree",
|
|
required_artifacts: [],
|
|
prefer_node: null
|
|
});
|
|
assert.strictEqual(placement.type, "task_placement");
|
|
assert.strictEqual(placement.placement.node, "windows-node");
|
|
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, {
|
|
type: "reconnect_node",
|
|
node: "windows-node",
|
|
process: "vp-windows",
|
|
epoch: started.epoch
|
|
});
|
|
assert.strictEqual(reconnected.type, "node_reconnected");
|
|
|
|
const recordedTask = await send(addr, {
|
|
type: "task_completed",
|
|
tenant: "tenant",
|
|
project: "project",
|
|
process: "vp-windows",
|
|
node: "windows-node",
|
|
task: "windows-command-dev",
|
|
status_code: 0,
|
|
stdout_bytes: 18,
|
|
stderr_bytes: 0,
|
|
artifact_path: "/vfs/artifacts/windows-output.txt",
|
|
artifact_digest: "sha256:windows-artifact",
|
|
artifact_size_bytes: 18
|
|
});
|
|
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,
|
|
token_nonce: "nonce"
|
|
});
|
|
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);
|
|
});
|