Apply stable CLI failure exit codes
This commit is contained in:
parent
50d298ead7
commit
b808dad0e5
8 changed files with 224 additions and 7 deletions
93
scripts/cli-error-exit-smoke.js
Executable file
93
scripts/cli-error-exit-smoke.js
Executable file
|
|
@ -0,0 +1,93 @@
|
|||
#!/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 runDisasmer(args) {
|
||||
return new Promise((resolve) => {
|
||||
const child = cp.spawn(
|
||||
"cargo",
|
||||
["run", "-q", "-p", "disasmer-cli", "--bin", "disasmer", "--", ...args],
|
||||
{
|
||||
cwd: repo,
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
}
|
||||
);
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
child.stdout.setEncoding("utf8");
|
||||
child.stderr.setEncoding("utf8");
|
||||
child.stdout.on("data", (chunk) => {
|
||||
stdout += chunk;
|
||||
});
|
||||
child.stderr.on("data", (chunk) => {
|
||||
stderr += chunk;
|
||||
});
|
||||
child.on("close", (code, signal) => {
|
||||
resolve({ code, signal, stdout, stderr });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
let request = "";
|
||||
const server = net.createServer((socket) => {
|
||||
socket.setEncoding("utf8");
|
||||
socket.on("data", (chunk) => {
|
||||
request += chunk;
|
||||
if (!request.includes("\n")) return;
|
||||
socket.write(
|
||||
JSON.stringify({
|
||||
type: "error",
|
||||
message: "quota unavailable: resource limit exceeded for api_calls",
|
||||
}) + "\n"
|
||||
);
|
||||
socket.end();
|
||||
server.close();
|
||||
});
|
||||
});
|
||||
|
||||
const address = await new Promise((resolve) => {
|
||||
server.listen(0, "127.0.0.1", () => resolve(server.address()));
|
||||
});
|
||||
const coordinator = `http://${address.address}:${address.port}`;
|
||||
|
||||
const result = await runDisasmer([
|
||||
"run",
|
||||
"build",
|
||||
"--project",
|
||||
project,
|
||||
"--coordinator",
|
||||
coordinator,
|
||||
"--json",
|
||||
]);
|
||||
|
||||
assert.strictEqual(result.signal, null, result.stderr);
|
||||
assert.strictEqual(result.code, 22, result.stderr);
|
||||
assert.match(request, /"type":"start_process"/);
|
||||
const report = JSON.parse(result.stdout);
|
||||
assert.strictEqual(report.status, "coordinator_rejected");
|
||||
assert.strictEqual(report.run_start.machine_error.category, "quota");
|
||||
assert.strictEqual(report.run_start.machine_error.stable_exit_code, 22);
|
||||
assert.strictEqual(
|
||||
report.run_start.machine_error.process_exit_code_applied,
|
||||
true
|
||||
);
|
||||
assert(
|
||||
report.run_start.machine_error.next_actions.includes("disasmer quota status")
|
||||
);
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => {
|
||||
console.log("CLI error exit smoke passed");
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue