Files
gbrain/test/e2e/upgrade.test.ts
T
Aurora CapitalandGitHub 2c96787867 test(e2e): harden suite — kill flakes, no-op assertions, cross-test coupling (#1704)
* test(e2e): drop flaky wall-clock bounds in minions-resilience

The runaway-dead-letter and cascade-kill tests asserted tight real-clock
upper bounds (<2000ms, <3000ms) on top of already-complete terminal-state
checks. Those bounds carry no correctness signal — the dead/cancelled status
and abortedChildren==10 assertions fully prove behavior — and flake on loaded
CI runners where the stall/timeout sweep cadence varies. Removed both bounds,
kept the diagnostic values, de-promised the test titles.

* test(e2e): kill order-dependence + no-op assertions in mechanical

- traverse_graph: self-contained (re-adds its own idempotent link) and asserts
  the linked company is reachable, instead of depending on a prior it() and
  only checking array shape.
- file_list-without-slug: seeds its own >100 rows instead of relying on the
  previous test's 150 surviving in the DB; asserts the cap is exercised.
- precision@5: add a loose floor (every known-item query surfaces >=1 truth doc
  in top-5) so a 0% retrieval regression no longer passes silently.
- get_health: assert value bounds (page_count==16, embed_coverage 0..1) not just
  typeof; get_chunks: assert non-empty text, numeric non-decreasing chunk_index,
  and that the page name appears, instead of toBeTruthy on chunks[0].

* test(e2e): strengthen graph/search quality assertions + close coverage gaps

graph-quality: truncate+reseed 'config' in truncateAll (kills config leak where a
setConfig test throwing before its finally bleeds into later tests); replace
toBeGreaterThan(0) link/timeline floors with fixture-derived minimums; assert exact
attendee slugs are 'attended' instead of a vacuous .every; pin autoLinks.created to
the provable 2 (Alice+Acme); add direction out/both + depth:2 multi-hop and a
cycle-safety (A->B->A terminates) test.
search-quality: fix the vacuous detail=low vector test; assert pedro returns >=2
chunks; assert detail=high includes the timeline chunk; add empty-query and
zero-vector no-throw edge tests.

* test(e2e): self-contain multi-source sync test + assert ledger cascade

Break the sequential dependency where 'performSync no sourceId' relied on a prior
test writing sync.repo_path — it now sets its own config. Add the missing
file_migration_ledger COUNT(*)==0 cascade assertion. Tighten the source_id default
check from toContain('default') to exact "'default'::text".

* test(e2e): make migration-flow HOME/PATH swap throw-safe

The suite repoints process.env.HOME/PATH to a temp dir and only restored them in
afterAll, so a mid-test throw left HOME dead for the rest of the bun process and
silently broke sibling suites. Wrap each test body in try/finally restore + a
defensive restore at the top of beforeEach.

* test(e2e): loud-skip jsonb-roundtrip + doctor-progress

Both skipped silently with no DATABASE_URL, giving zero signal the regression guard
never ran. Add the console.log skip line matching the sibling e2e files.

* test(e2e): robust check-update contract + find_orphans tool coverage

upgrade: the 'no-releases' test hard-asserted update_available===false, which flips
to failing the moment the repo has a real release. Assert the JSON contract shape
(boolean update_available, current_version===VERSION, typed optional fields) instead.
mcp: add find_orphans to the asserted generated tool names.
2026-07-22 18:46:44 -07:00

107 lines
3.7 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('check-update --json contract holds regardless of real release 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);
// Don't pin update_available to a literal value — the repo may or may not
// have a published release. Assert the JSON shape instead.
expect(typeof output.update_available).toBe('boolean');
expect(output.current_version).toBe(VERSION);
if (output.latest_version != null) {
expect(typeof output.latest_version).toBe('string');
}
if (output.release_url != null) {
expect(typeof output.release_url).toBe('string');
}
});
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);
});
});