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
414
scripts/artifact-download-smoke.js
Executable file
414
scripts/artifact-download-smoke.js
Executable file
|
|
@ -0,0 +1,414 @@
|
|||
#!/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 project = 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 runNode(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-download",
|
||||
"--process",
|
||||
"vp-download",
|
||||
"--task",
|
||||
"compile-linux",
|
||||
"--project",
|
||||
project,
|
||||
"--artifact",
|
||||
"/vfs/artifacts/download-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(`node process failed with code ${code}\n${stderr}`));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
resolve(JSON.parse(stdout.trim().split("\n").at(-1)));
|
||||
} catch (error) {
|
||||
reject(new Error(`node output was not JSON: ${stdout}\n${error.stack || error.message}`));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function downloadNodeCapabilities() {
|
||||
return {
|
||||
os: "Linux",
|
||||
arch: "x86_64",
|
||||
capabilities: ["Command", "VfsArtifacts"],
|
||||
environment_backends: [],
|
||||
source_providers: ["filesystem"],
|
||||
};
|
||||
}
|
||||
|
||||
(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 report = await runNode(addr);
|
||||
assert.strictEqual(report.node_status, "completed");
|
||||
assert.strictEqual(report.status_code, 0);
|
||||
assert.strictEqual(report.large_bytes_uploaded, false);
|
||||
assert.strictEqual(report.staged_artifact.path, "/vfs/artifacts/download-output.txt");
|
||||
|
||||
const disconnectedReport = await send(addr, {
|
||||
type: "report_node_capabilities",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
node: "node-download",
|
||||
capabilities: downloadNodeCapabilities(),
|
||||
cached_environment_digests: [],
|
||||
dependency_cache_digests: [],
|
||||
source_snapshots: [],
|
||||
artifact_locations: [],
|
||||
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: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "disconnected",
|
||||
now_epoch_seconds: 10,
|
||||
ttl_seconds: 60,
|
||||
});
|
||||
assert.strictEqual(disconnectedLink.type, "error");
|
||||
assert.match(disconnectedLink.message, /direct connectivity unavailable/);
|
||||
|
||||
const connectedReport = await send(addr, {
|
||||
type: "report_node_capabilities",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
node: "node-download",
|
||||
capabilities: downloadNodeCapabilities(),
|
||||
cached_environment_digests: [],
|
||||
dependency_cache_digests: [],
|
||||
source_snapshots: [],
|
||||
artifact_locations: [],
|
||||
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: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "nonce",
|
||||
now_epoch_seconds: 10,
|
||||
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, "vp-download");
|
||||
assert.deepStrictEqual(link.link.actor, { User: "user" });
|
||||
assert.match(link.link.policy_context_digest, /^sha256:[0-9a-f]{64}$/);
|
||||
assert.strictEqual(link.link.expires_at_epoch_seconds, 70);
|
||||
assert.match(link.link.url_path, /\/artifacts\/tenant\/project\/vp-download\/download-output\.txt$/);
|
||||
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: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "nonce",
|
||||
now_epoch_seconds: 10,
|
||||
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: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "nonce",
|
||||
now_epoch_seconds: 10,
|
||||
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: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "nonce",
|
||||
token_digest: link.link.scoped_token_digest,
|
||||
now_epoch_seconds: 11,
|
||||
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: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "nonce",
|
||||
token_digest: link.link.scoped_token_digest,
|
||||
now_epoch_seconds: 11,
|
||||
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: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "nonce",
|
||||
token_digest: "sha256:guessed",
|
||||
now_epoch_seconds: 11,
|
||||
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: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "nonce",
|
||||
token_digest: link.link.scoped_token_digest,
|
||||
now_epoch_seconds: 11,
|
||||
chunk_bytes: 1,
|
||||
});
|
||||
assert.strictEqual(crossActorOpen.type, "error");
|
||||
assert.match(crossActorOpen.message, /token is invalid/);
|
||||
|
||||
const expired = await send(addr, {
|
||||
type: "open_artifact_download_stream",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
actor_user: "user",
|
||||
artifact: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "nonce",
|
||||
token_digest: link.link.scoped_token_digest,
|
||||
now_epoch_seconds: 71,
|
||||
chunk_bytes: 1,
|
||||
});
|
||||
assert.strictEqual(expired.type, "error");
|
||||
assert.match(expired.message, /expired/);
|
||||
|
||||
await send(addr, {
|
||||
type: "report_node_capabilities",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
node: "node-download",
|
||||
capabilities: downloadNodeCapabilities(),
|
||||
cached_environment_digests: [],
|
||||
dependency_cache_digests: [],
|
||||
source_snapshots: [],
|
||||
artifact_locations: [],
|
||||
direct_connectivity: false,
|
||||
online: true,
|
||||
});
|
||||
const disconnectedOpen = await send(addr, {
|
||||
type: "open_artifact_download_stream",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
actor_user: "user",
|
||||
artifact: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "nonce",
|
||||
token_digest: link.link.scoped_token_digest,
|
||||
now_epoch_seconds: 11,
|
||||
chunk_bytes: 1,
|
||||
});
|
||||
assert.strictEqual(disconnectedOpen.type, "error");
|
||||
assert.match(disconnectedOpen.message, /direct connectivity unavailable/);
|
||||
|
||||
await send(addr, {
|
||||
type: "report_node_capabilities",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
node: "node-download",
|
||||
capabilities: downloadNodeCapabilities(),
|
||||
cached_environment_digests: [],
|
||||
dependency_cache_digests: [],
|
||||
source_snapshots: [],
|
||||
artifact_locations: [],
|
||||
direct_connectivity: true,
|
||||
online: true,
|
||||
});
|
||||
|
||||
const stream = await send(addr, {
|
||||
type: "open_artifact_download_stream",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
actor_user: "user",
|
||||
artifact: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "nonce",
|
||||
token_digest: link.link.scoped_token_digest,
|
||||
now_epoch_seconds: 11,
|
||||
chunk_bytes: 16,
|
||||
});
|
||||
assert.strictEqual(stream.type, "artifact_download_stream");
|
||||
assert.strictEqual(stream.streamed_bytes, 16);
|
||||
assert.strictEqual(stream.charged_download_bytes, 16);
|
||||
assert.strictEqual(stream.link.artifact, "download-output.txt");
|
||||
|
||||
const crossActorRevoke = await send(addr, {
|
||||
type: "revoke_artifact_download_link",
|
||||
tenant: "tenant",
|
||||
project: "project",
|
||||
actor_user: "other-user",
|
||||
artifact: "download-output.txt",
|
||||
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: "download-output.txt",
|
||||
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: "download-output.txt",
|
||||
max_bytes: 1024 * 1024,
|
||||
token_nonce: "nonce",
|
||||
token_digest: link.link.scoped_token_digest,
|
||||
now_epoch_seconds: 12,
|
||||
chunk_bytes: 1,
|
||||
});
|
||||
assert.strictEqual(revokedOpen.type, "error");
|
||||
assert.match(revokedOpen.message, /revoked/);
|
||||
} finally {
|
||||
coordinator.kill("SIGTERM");
|
||||
}
|
||||
|
||||
console.log("Artifact download smoke passed");
|
||||
})().catch((error) => {
|
||||
console.error(error.stack || error.message);
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue