mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-27 22:15:33 +00:00
* feat: add `gbrain check-update` command for auto-update notifications Deterministic collector that checks GitHub Releases for new versions, compares semver (minor+ only, skips patches), and fetches changelog diffs. Exports `detectInstallMethod()` from upgrade.ts for reuse. Includes 15 unit tests covering version comparison, CLI wiring, and error handling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * test: add E2E upgrade tests against real GitHub API Exercises check-update CLI end-to-end: valid JSON output, human-readable mode, help text, graceful no-releases handling, and version comparison wiring. Skips gracefully when network is unavailable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * docs: add SKILLPACK Section 17 — auto-update notifications Full agent playbook for the update lifecycle: check, notify, consent, upgrade, skills refresh, schema sync, report. Includes standalone self-update for skillpack-only users via version markers and raw GitHub URL fetching. Adds version markers to both SKILLPACK and RECOMMENDED_SCHEMA headers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add auto-update step 7 to install paste, setup Phase G, migrations dir Adds step 7 to the OpenClaw install paste (default-on update checks). Setup skill gets Phase G (conditional offer for manual installs) and schema state tracking via ~/.gbrain/update-state.json. Creates skills/migrations/ directory for version-specific upgrade directives. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * docs: update CLAUDE.md with E2E test DB lifecycle, migration conventions Adds E2E test DB lifecycle instructions (spin up, run, tear down). Documents version migration convention (skills/migrations/v[version].md) and schema state tracking (~/.gbrain/update-state.json). Updates test file counts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: broken semver comparison in extractChangelogBetween The version range check compared minor versions without guarding on major being equal, causing incorrect changelog entries to be captured (e.g., v0.5.0 would match when upgrading from v1.2.0). Extracted semverGt/semverLte helpers for correct comparisons. Added 5 tests for extractChangelogBetween covering cross-major, same-version, and malformed input cases. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * chore: bump version and changelog (v0.4.1) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
99 lines
3.3 KiB
TypeScript
99 lines
3.3 KiB
TypeScript
/**
|
|
* E2E Upgrade Tests — Tier 1 (no API keys required, needs network)
|
|
*
|
|
* Tests the check-update command against the real GitHub API.
|
|
* Skips gracefully if network is unavailable.
|
|
*
|
|
* Run: bun test test/e2e/upgrade.test.ts
|
|
*/
|
|
|
|
import { describe, test, expect } from 'bun:test';
|
|
import { VERSION } from '../../src/version.ts';
|
|
import { isMinorOrMajorBump } from '../../src/commands/check-update.ts';
|
|
|
|
// Check if we can reach GitHub
|
|
async function hasNetwork(): Promise<boolean> {
|
|
try {
|
|
const res = await fetch('https://api.github.com', { signal: AbortSignal.timeout(5_000) });
|
|
return res.ok;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
const skip = !(await hasNetwork());
|
|
const describeE2E = skip ? describe.skip : describe;
|
|
|
|
if (skip) {
|
|
console.log('Skipping E2E upgrade tests (network unavailable)');
|
|
}
|
|
|
|
describeE2E('E2E: Check-Update', () => {
|
|
test('check-update --json returns valid JSON with current version', async () => {
|
|
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'check-update', '--json'], {
|
|
cwd: new URL('../..', import.meta.url).pathname,
|
|
stdout: 'pipe',
|
|
stderr: 'pipe',
|
|
});
|
|
const stdout = await new Response(proc.stdout).text();
|
|
const exitCode = await proc.exited;
|
|
|
|
expect(exitCode).toBe(0);
|
|
const output = JSON.parse(stdout);
|
|
expect(output.current_version).toBe(VERSION);
|
|
expect(output.current_source).toBe('package-json');
|
|
expect(typeof output.update_available).toBe('boolean');
|
|
expect(typeof output.upgrade_command).toBe('string');
|
|
});
|
|
|
|
test('check-update without --json prints human-readable output', async () => {
|
|
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'check-update'], {
|
|
cwd: new URL('../..', import.meta.url).pathname,
|
|
stdout: 'pipe',
|
|
stderr: 'pipe',
|
|
});
|
|
const stdout = await new Response(proc.stdout).text();
|
|
const exitCode = await proc.exited;
|
|
|
|
expect(exitCode).toBe(0);
|
|
expect(stdout).toContain('GBrain');
|
|
});
|
|
|
|
test('check-update --help prints usage', async () => {
|
|
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'check-update', '--help'], {
|
|
cwd: new URL('../..', import.meta.url).pathname,
|
|
stdout: 'pipe',
|
|
stderr: 'pipe',
|
|
});
|
|
const stdout = await new Response(proc.stdout).text();
|
|
const exitCode = await proc.exited;
|
|
|
|
expect(exitCode).toBe(0);
|
|
expect(stdout).toContain('check-update');
|
|
expect(stdout).toContain('--json');
|
|
});
|
|
|
|
test('handles no-releases gracefully (current repo state)', async () => {
|
|
const proc = Bun.spawn(['bun', 'run', 'src/cli.ts', 'check-update', '--json'], {
|
|
cwd: new URL('../..', import.meta.url).pathname,
|
|
stdout: 'pipe',
|
|
stderr: 'pipe',
|
|
});
|
|
const stdout = await new Response(proc.stdout).text();
|
|
const exitCode = await proc.exited;
|
|
|
|
expect(exitCode).toBe(0);
|
|
const output = JSON.parse(stdout);
|
|
// With no releases, should return false and an error
|
|
expect(output.update_available).toBe(false);
|
|
});
|
|
|
|
test('version comparison wiring works end-to-end', () => {
|
|
// Smoke test that the exported function works correctly
|
|
expect(isMinorOrMajorBump('0.4.0', '0.5.0')).toBe(true);
|
|
expect(isMinorOrMajorBump('0.4.0', '0.4.1')).toBe(false);
|
|
expect(isMinorOrMajorBump('0.4.0', '1.0.0')).toBe(true);
|
|
expect(isMinorOrMajorBump('0.4.0', '0.4.0')).toBe(false);
|
|
});
|
|
});
|