Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@ export default class UpdateCommand extends NemoClawCommand {
static summary = `Run the maintained ${CLI_DISPLAY_NAME} installer update flow`;
static description =
`Check for a ${CLI_DISPLAY_NAME} CLI update and run the maintained installer flow.`;
static usage = ["update [--check] [--yes|-y]"];
static usage = ["update [--check] [--fresh] [--yes|-y]"];
static examples = [
"<%= config.bin %> update --check",
"<%= config.bin %> update",
"<%= config.bin %> update --fresh",
"<%= config.bin %> update --yes",
];
static flags = {
check: Flags.boolean({
description: "Check update availability without running the installer",
}),
fresh: Flags.boolean({
description:
"Reinstall the maintained build even when already up to date (clean re-clone; useful to repair a broken install)",
}),
yes: yesFlag(),
};

Expand All @@ -34,6 +39,7 @@ export default class UpdateCommand extends NemoClawCommand {
const result = await runUpdateAction(
{
check: flags.check === true,
fresh: flags.fresh === true,
yes: flags.yes === true,
},
{
Expand Down
67 changes: 67 additions & 0 deletions src/lib/actions/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,73 @@ describe("runUpdateAction", () => {
}
});

it("does not run the installer when already up to date without --fresh", async () => {
const spawnSyncImpl = vi.fn();
const log = vi.fn();

const result = await runUpdateAction(
{ yes: true },
{
currentVersion: () => "0.2.0",
getLatestVersion: () => "0.2.0",
isSourceCheckout: () => false,
log,
spawnSyncImpl,
},
);

expect(result.updateAvailable).toBe(false);
expect(result.ranInstaller).toBe(false);
expect(spawnSyncImpl).not.toHaveBeenCalled();
expect(log).toHaveBeenCalledWith(expect.stringContaining("already up to date"));
});

it("reinstalls even when already up to date with --fresh (#5960)", async () => {
const spawnSyncImpl = vi.fn(
() => ({ status: 0, stdout: "", stderr: "", signal: null }) as never,
);
const log = vi.fn();

const result = await runUpdateAction(
{ fresh: true, yes: true },
{
currentVersion: () => "0.2.0",
getLatestVersion: () => "0.2.0",
isSourceCheckout: () => false,
log,
spawnSyncImpl,
},
);

expect(result.updateAvailable).toBe(false);
expect(result.ranInstaller).toBe(true);
expect(spawnSyncImpl).toHaveBeenCalledWith(
"bash",
["-o", "pipefail", "-lc", NEMOCLAW_UPDATE_COMMAND],
expect.objectContaining({ stdio: "inherit" }),
);
expect(log).toHaveBeenCalledWith(expect.stringContaining("reinstalling anyway (--fresh)"));
});

it("still refuses --fresh from a developer source checkout (no reinstall)", async () => {
const spawnSyncImpl = vi.fn();

const result = await runUpdateAction(
{ fresh: true, yes: true },
{
currentVersion: () => "0.2.0",
error: vi.fn(),
getLatestVersion: () => "0.2.0",
isSourceCheckout: () => true,
log: vi.fn(),
spawnSyncImpl,
},
);

expect(result.ranInstaller).toBe(false);
expect(spawnSyncImpl).not.toHaveBeenCalled();
});

it("prompts before running the maintained installer", async () => {
const prompt = vi.fn(async () => "yes");
const spawnSyncImpl = vi.fn(
Expand Down
17 changes: 15 additions & 2 deletions src/lib/actions/update.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { spawnSync, type SpawnSyncReturns } from "node:child_process";
import { type SpawnSyncReturns, spawnSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
Expand All @@ -24,6 +24,13 @@ type SpawnSyncFn = (

export interface RunUpdateOptions {
check?: boolean;
/**
* Reinstall the maintained build even when already up to date. The installer
* re-clones `~/.nemoclaw/source`, so this repairs a broken-but-current
* install. Does not reset onboarding state (distinct from the installer's
* onboard-scoped `--fresh`/`NEMOCLAW_FRESH`).
*/
fresh?: boolean;
yes?: boolean;
}

Expand Down Expand Up @@ -256,7 +263,7 @@ export async function runUpdateAction(
};
}

if (available === false) {
if (available === false && !options.fresh) {
log(` ${branding.displayName} is already up to date.`);
return {
currentVersion,
Expand All @@ -268,6 +275,12 @@ export async function runUpdateAction(
};
}

if (available === false && options.fresh) {
log(
` ${branding.displayName} is already up to date; reinstalling anyway (--fresh) for a clean re-clone.`,
);
}

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if (!options.yes) {
if (env.NEMOCLAW_NON_INTERACTIVE === "1") {
error(" Refusing to prompt in non-interactive mode. Re-run with --yes to update.");
Expand Down
Loading