mirror of
https://github.com/affaan-m/ECC.git
synced 2026-09-10 19:57:57 +02:00
refactor(ito): share invocation command detection
This commit is contained in:
+2
-1
@@ -7,6 +7,7 @@ const path = require("path");
|
||||
const { spawnSync } = require("child_process");
|
||||
const {
|
||||
createSafeItoInvocationEnvironment,
|
||||
getInvocationCommand,
|
||||
} = require("./lib/ito-environment");
|
||||
|
||||
const SUPPORTED_COMMANDS = Object.freeze(["auth", "find", "status", "evals"]);
|
||||
@@ -252,7 +253,7 @@ function buildInvocation(executable, args) {
|
||||
|
||||
function invokeIto(executable, args, environment = process.env) {
|
||||
const invocation = buildInvocation(executable, args);
|
||||
const command = args[0] === "--json" ? args[1] : args[0];
|
||||
const command = getInvocationCommand(args);
|
||||
const isNodeQualification = command === "evals";
|
||||
const result = spawnSync(invocation.executable, invocation.args, {
|
||||
cwd: process.cwd(),
|
||||
|
||||
@@ -80,12 +80,16 @@ function createSafeItoEnvironment(source = process.env, options = {}) {
|
||||
return Object.freeze(safe);
|
||||
}
|
||||
|
||||
function getInvocationCommand(args = []) {
|
||||
return args.filter((value) => value !== "--json")[0];
|
||||
}
|
||||
|
||||
function createSafeItoInvocationEnvironment(
|
||||
source = process.env,
|
||||
args = [],
|
||||
options = {},
|
||||
) {
|
||||
const command = args.filter((value) => value !== "--json")[0];
|
||||
const command = getInvocationCommand(args);
|
||||
return createSafeItoEnvironment(source, {
|
||||
includeControls: options.includeControls === true,
|
||||
includeItoRuntime: ITO_RUNTIME_COMMANDS.has(command),
|
||||
@@ -100,4 +104,5 @@ module.exports = Object.freeze({
|
||||
SYSTEM_ENVIRONMENT_KEYS,
|
||||
createSafeItoEnvironment,
|
||||
createSafeItoInvocationEnvironment,
|
||||
getInvocationCommand,
|
||||
});
|
||||
|
||||
@@ -20,6 +20,7 @@ const {
|
||||
} = require("../../scripts/ito");
|
||||
const {
|
||||
createSafeItoInvocationEnvironment,
|
||||
getInvocationCommand,
|
||||
} = require("../../scripts/lib/ito-environment");
|
||||
|
||||
function runCli(args, environment = {}) {
|
||||
@@ -323,6 +324,11 @@ function main() {
|
||||
assert.strictEqual(safe.ITO_API_KEY, undefined);
|
||||
assert.strictEqual(safe.SIXTYTWO_TOKEN, undefined);
|
||||
}],
|
||||
["detects the Itō command consistently with or without the global JSON flag", () => {
|
||||
assert.strictEqual(getInvocationCommand(["auth"]), "auth");
|
||||
assert.strictEqual(getInvocationCommand(["--json", "evals"]), "evals");
|
||||
assert.strictEqual(getInvocationCommand([]), undefined);
|
||||
}],
|
||||
["bounds the outer node-qualification process beyond the canonical timeout", () => {
|
||||
assert.strictEqual(NODE_QUALIFICATION_TIMEOUT_MS, 31 * 60 * 1000);
|
||||
const source = fs.readFileSync(ITO_SCRIPT, "utf8");
|
||||
|
||||
Reference in New Issue
Block a user