refactor(ito): share invocation command detection

This commit is contained in:
Affaan Mustafa
2026-07-24 00:48:13 -04:00
parent 2e3696ae50
commit 4bd94695b1
3 changed files with 14 additions and 2 deletions
+2 -1
View File
@@ -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(),
+6 -1
View File
@@ -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,
});
+6
View File
@@ -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");