Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(upgrade): exit 1 instead of "[ok] ix is up to date" when a step failed

KageBinary89c5f01462d1
diff --git a/ix-cli/src/cli/__tests__/upgrade-check-closing-line.test.ts b/ix-cli/src/cli/__tests__/upgrade-check-closing-line.test.ts
index af5a005c..3b8aeb15 100644
--- a/ix-cli/src/cli/__tests__/upgrade-check-closing-line.test.ts
+++ b/ix-cli/src/cli/__tests__/upgrade-check-closing-line.test.ts
@@ -41,6 +41,14 @@ describe("closingStatus", () => {
expect(closingStatus(false, ["CLI 0.9.2 → 0.10.0"]).upToDate).toBe(true);
expect(closingStatus(undefined, ["CLI 0.9.2 → 0.10.0"]).upToDate).toBe(true);
});
+
+ it("does not sign off an install run as up to date when a step failed", () => {
+ const status = closingStatus(false, ["backend 1.0.16 → 1.0.17"], ["backend image pull", "compass download"]);
+ expect(status.upToDate).toBe(false);
+ expect(status).toMatchObject({ failed: true, summary: "backend image pull, compass download" });
+ // And under --check, a failure still outranks the outstanding list.
+ expect(closingStatus(true, ["CLI 0.9.2 → 0.10.0"], ["@ix/pro refresh"])).toMatchObject({ failed: true });
+ });
});
describe("ix upgrade --check output", () => {
diff --git a/ix-cli/src/cli/commands/upgrade.ts b/ix-cli/src/cli/commands/upgrade.ts
index d9d2d675..00dc136d 100644
--- a/ix-cli/src/cli/commands/upgrade.ts
+++ b/ix-cli/src/cli/commands/upgrade.ts
@@ -1361,12 +1361,20 @@ function printUpdateNotice(
* An install run keeps the flat line, and that is not an oversight: by the time
* it prints, every branch that added to `outstanding` has already acted on it,
* so there the list says what was found and handled, not what is left. Reusing
- * it there would report the work that just succeeded as still pending.
+ * it there would report the work that just succeeded as still pending. What it
+ * must not do is sign off `[ok]` over a step that FAILED -- a pull, a restart,
+ * the compass install -- which `failures` reports ahead of everything else.
*/
export function closingStatus(
check: boolean | undefined,
outstanding: readonly string[],
-): { upToDate: true } | { upToDate: false; summary: string } {
+ failures: readonly string[] = [],
+): { upToDate: true; failed?: false } | { upToDate: false; failed?: boolean; summary: string } {
+ // A step that failed outranks everything: the run is neither up to date nor
+ // merely behind.
+ if (failures.length > 0) {
+ return { upToDate: false, failed: true, summary: failures.join(", ") };
+ }
if (check && outstanding.length > 0) {
return { upToDate: false, summary: outstanding.join(", ") };
}
@@ -1416,6 +1424,11 @@ export function registerUpgradeCommand(program: Command): void {
// --check: an install pass acts on each of these as it goes, so there the
// list describes what was found, not what is left. See the closing line.
const outstanding: string[] = [];
+ // Steps an install run attempted and could not complete. Each one printed
+ // its own `[!!]` line and the run carried on -- then closed with `[ok] ix
+ // is up to date` and exit 0, which is what a script or a user skimming
+ // the last line believed.
+ const failures: string[] = [];
const cliUpToDate = !isNewer(latest, current);
if (cliUpToDate) {
@@ -1611,6 +1624,7 @@ export function registerUpgradeCommand(program: Command): void {
});
console.log("[ok] @ix/pro refreshed");
} catch {
+ failures.push("@ix/pro refresh");
console.error("[!!] Could not refresh @ix/pro. Run: npm update --prefix ~/.ix @ix/pro");
}
}
@@ -1665,26 +1679,36 @@ export function registerUpgradeCommand(program: Command): void {
console.error(chalk.yellow(stampFailureMessage()));
}
} catch {
+ failures.push("backend image pull");
console.error("[!!] Could not pull latest backend image. Run: ix docker restart");
}
// Restart backend if running
+ let backendRunning = false;
try {
execFileSync("curl", ["-sf", "http://localhost:8090/v1/health"], {
stdio: "ignore",
timeout: 3000,
});
+ backendRunning = true;
+ } catch {
+ // Backend not running, that's fine
+ }
+ if (backendRunning && existsSync(backendComposeFile)) {
console.log("Restarting backend...");
- if (existsSync(backendComposeFile)) {
+ try {
execFileSync(
"docker",
["compose", "-f", backendComposeFile, "up", "-d", "--pull", "always"],
{ stdio: "inherit" }
);
console.log("[ok] Backend restarted with latest image");
+ } catch {
+ // The backend WAS running, so this is a failed restart, not the
+ // "not running" case the old shared catch reported it as.
+ failures.push("backend restart");
+ console.error("[!!] Could not restart the backend. Run: ix docker restart");
}
- } catch {
- // Backend not running, that's fine
}
}
} else if (backendLatest && !backendUpgradeSkipped) {
@@ -1787,6 +1811,7 @@ export function registerUpgradeCommand(program: Command): void {
writeFileSync(COMPASS_VERSION_FILE, `${compassLatest}\n`);
console.log(`[ok] Compass upgraded to ${compassLatest}`);
} catch (err) {
+ failures.push(`compass ${stage}`);
console.error(`[!!] Compass ${stage} failed: ${describeExecFailure(err)}`);
// Whether this is a degraded upgrade or a broken `ix view` depends
// on what survived, and only the second is worth alarming about.
@@ -1832,8 +1857,11 @@ export function registerUpgradeCommand(program: Command): void {
// `closingStatus` only reports outstanding work under `--check`. The
// skipped-backend case is checked first because it describes work this
// run declined to do, which outranks work it merely found.
- const closing = closingStatus(opts.check, outstanding);
- if (backendUpgradeSkipped) {
+ const closing = closingStatus(opts.check, outstanding, failures);
+ if (closing.failed) {
+ console.log(`[!!] ix upgrade did not complete: ${closing.summary} failed (see above)`);
+ process.exitCode = 1;
+ } else if (backendUpgradeSkipped) {
console.log("[!!] ix upgrade finished with the backend unchanged");
} else if (closing.upToDate) {
console.log("[ok] ix is up to date");