Source commit: 6d1a121b0a8a636aac95998fe5d15c24c78eb7d0 Public tree identity: sha256:2bc22807f5b838286678b65d3f550b8ae4714ae673622041d4c2516a7c5b7926
148 lines
4.4 KiB
JavaScript
148 lines
4.4 KiB
JavaScript
#!/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, 11);
|
|
assert.strictEqual(build.bundle_artifact.entrypoint_count, 6);
|
|
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", "identity", "long-join", "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");
|