fix(ito): harden canonical workload bridge

This commit is contained in:
Affaan Mustafa
2026-08-07 15:52:52 -04:00
parent 0830f1823f
commit 1d10ff9e4d
4 changed files with 48 additions and 27 deletions
+12 -12
View File
@@ -15,11 +15,9 @@ const SUPPORTED_COMMANDS = Object.freeze([
"serve", "train", "workload-status", "workload-cancel", "workload-cleanup",
]);
const CANONICAL_PACKAGE_PATH = "cli/ito-compute-cli";
const CANONICAL_ENTRY_SEGMENTS = Object.freeze([
...CANONICAL_PACKAGE_PATH.split("/"),
"dist",
"bin",
"ito.js",
const CANONICAL_ENTRY_TAILS = Object.freeze([
Object.freeze([...CANONICAL_PACKAGE_PATH.split("/"), "dist", "bin", "ito.js"]),
Object.freeze(["ito-compute-cli", "dist", "bin", "ito.js"]),
]);
const EXECUTABLE_OVERRIDE = "ECC_ITO_CLI_EXECUTABLE";
const MAX_OUTPUT_BYTES = 10 * 1024 * 1024;
@@ -213,6 +211,9 @@ function parseArgs(argv, environment = process.env) {
"--entitlement", "--artifact-ref", "--image-digest",
"--max-runtime-seconds", "--max-incremental-cost-usd", "--idempotency-key",
], ["--checkpoint-ref"]);
if (requiredOptionValue(withoutJson, "--max-incremental-cost-usd") !== "0") {
throw new Error("--max-incremental-cost-usd must be exactly 0 until workload accounting is enabled.");
}
}
if (command === "workload-status" || command === "workload-cancel" || command === "workload-cleanup") {
validateRunLifecycleArgs(withoutJson);
@@ -275,13 +276,12 @@ function isCanonicalItoEntry(candidate) {
.normalize(candidate)
.split(path.sep)
.filter(Boolean);
if (pathSegments.length < CANONICAL_ENTRY_SEGMENTS.length) return false;
const candidateTail = pathSegments.slice(-CANONICAL_ENTRY_SEGMENTS.length);
return candidateTail.every((segment, index) => {
const expected = CANONICAL_ENTRY_SEGMENTS[index];
return process.platform === "win32"
? segment.toLowerCase() === expected.toLowerCase()
: segment === expected;
return CANONICAL_ENTRY_TAILS.some((expectedTail) => {
if (pathSegments.length < expectedTail.length) return false;
const candidateTail = pathSegments.slice(-expectedTail.length);
return candidateTail.every((segment, index) => process.platform === "win32"
? segment.toLowerCase() === expectedTail[index].toLowerCase()
: segment === expectedTail[index]);
});
}