test: merge update cli dry run cases

This commit is contained in:
Peter Steinberger 2026-03-17 10:03:59 +00:00
parent 4a95e6529f
commit 9e29511316

View File

@ -376,21 +376,48 @@ describe("update-cli", () => {
setStdoutTty(false);
});
it("updateCommand --dry-run previews without mutating", async () => {
vi.mocked(defaultRuntime.log).mockClear();
serviceLoaded.mockResolvedValue(true);
it("updateCommand dry-run previews without mutating and bypasses downgrade confirmation", async () => {
const cases = [
{
name: "preview mode",
run: async () => {
vi.mocked(defaultRuntime.log).mockClear();
serviceLoaded.mockResolvedValue(true);
await updateCommand({ dryRun: true, channel: "beta" });
},
assert: () => {
expect(writeConfigFile).not.toHaveBeenCalled();
expect(runGatewayUpdate).not.toHaveBeenCalled();
expect(runDaemonInstall).not.toHaveBeenCalled();
expect(runRestartScript).not.toHaveBeenCalled();
expect(runDaemonRestart).not.toHaveBeenCalled();
await updateCommand({ dryRun: true, channel: "beta" });
const logs = vi.mocked(defaultRuntime.log).mock.calls.map((call) => String(call[0]));
expect(logs.join("\n")).toContain("Update dry-run");
expect(logs.join("\n")).toContain("No changes were applied.");
},
},
{
name: "downgrade bypass",
run: async () => {
await setupNonInteractiveDowngrade();
vi.mocked(defaultRuntime.exit).mockClear();
await updateCommand({ dryRun: true });
},
assert: () => {
expect(vi.mocked(defaultRuntime.exit).mock.calls.some((call) => call[0] === 1)).toBe(
false,
);
expect(runGatewayUpdate).not.toHaveBeenCalled();
},
},
] as const;
expect(writeConfigFile).not.toHaveBeenCalled();
expect(runGatewayUpdate).not.toHaveBeenCalled();
expect(runDaemonInstall).not.toHaveBeenCalled();
expect(runRestartScript).not.toHaveBeenCalled();
expect(runDaemonRestart).not.toHaveBeenCalled();
const logs = vi.mocked(defaultRuntime.log).mock.calls.map((call) => String(call[0]));
expect(logs.join("\n")).toContain("Update dry-run");
expect(logs.join("\n")).toContain("No changes were applied.");
for (const testCase of cases) {
vi.clearAllMocks();
await testCase.run();
testCase.assert();
}
});
it("updateStatusCommand renders table and json output", async () => {
@ -921,16 +948,6 @@ describe("update-cli", () => {
).toBe(shouldRunPackageUpdate);
});
it("dry-run bypasses downgrade confirmation checks in non-interactive mode", async () => {
await setupNonInteractiveDowngrade();
vi.mocked(defaultRuntime.exit).mockClear();
await updateCommand({ dryRun: true });
expect(vi.mocked(defaultRuntime.exit).mock.calls.some((call) => call[0] === 1)).toBe(false);
expect(runGatewayUpdate).not.toHaveBeenCalled();
});
it("updateWizardCommand requires a TTY", async () => {
setTty(false);
vi.mocked(defaultRuntime.error).mockClear();