agenthub/tests/update.test.ts
chahinebrini 074b75f909 feat(cli): add agenthub update self-updater + non-blocking update hint
agenthub update: fetch + reset install to origin/<branch> + reinstall + rebuild, so users never touch git or pnpm. Robust to a dirty working tree (the 'commit before pull' wall) by resetting to remote; guards unpushed local commits and refuses to discard them. Adds a daily, non-blocking update hint on startup (detached background fetch + instant local comparison, like gh/npm/brew) that never auto-applies. Tests for the non-git-install path.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 22:24:53 +02:00

29 lines
925 B
TypeScript

import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { mkdtempSync, rmSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { update, maybeNotifyUpdate } from '../src/cli/commands/update.js';
describe('update', () => {
let dir: string;
beforeEach(() => {
dir = mkdtempSync(join(tmpdir(), 'ah-upd-'));
});
afterEach(() => {
rmSync(dir, { recursive: true, force: true });
});
it('points at the package manager when the install is not a git checkout', async () => {
const logs: string[] = [];
const original = console.log;
console.log = (msg: string) => logs.push(msg);
await update(dir);
console.log = original;
expect(logs.some((m) => m.includes('package manager'))).toBe(true);
});
it('maybeNotifyUpdate is a silent no-op outside a git checkout', () => {
expect(() => maybeNotifyUpdate(dir)).not.toThrow();
});
});