mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-29 19:01:39 +00:00
* 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.
122 lines
4.4 KiB
TypeScript
122 lines
4.4 KiB
TypeScript
/**
|
|
* E2E — doctor --progress-json streaming.
|
|
*
|
|
* Spawns the real CLI against a real Postgres+pgvector instance. Asserts:
|
|
* - stderr contains one JSON event per DB check (start + heartbeats)
|
|
* - stdout stays clean of progress (agents that parse stdout don't see
|
|
* progress garbage mixed with the check results)
|
|
*
|
|
* Tier 1 (no API keys). Requires DATABASE_URL or .env.testing.
|
|
* Run: DATABASE_URL=... bun test test/e2e/doctor-progress.test.ts
|
|
*/
|
|
|
|
import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
|
|
import { spawnSync } from 'child_process';
|
|
import { join } from 'path';
|
|
import {
|
|
hasDatabase, setupDB, teardownDB, importFixtures,
|
|
} from './helpers.ts';
|
|
|
|
const skip = !hasDatabase();
|
|
const describeE2E = skip ? describe.skip : describe;
|
|
|
|
if (skip) {
|
|
console.log('Skipping E2E doctor --progress-json tests (DATABASE_URL not set)');
|
|
}
|
|
|
|
const CLI = join(import.meta.dir, '..', '..', 'src', 'cli.ts');
|
|
|
|
describeE2E('gbrain doctor --progress-json (E2E)', () => {
|
|
beforeAll(async () => {
|
|
await setupDB();
|
|
// Seed a handful of pages so the DB checks have something to scan.
|
|
await importFixtures();
|
|
}, 30_000);
|
|
|
|
afterAll(async () => {
|
|
await teardownDB();
|
|
});
|
|
|
|
test('stderr has JSONL progress events, stdout stays clean', () => {
|
|
const res = spawnSync('bun', [CLI, '--progress-json', 'doctor', '--json'], {
|
|
encoding: 'utf-8',
|
|
env: { ...process.env, NO_COLOR: '1' },
|
|
timeout: 30_000,
|
|
});
|
|
|
|
// Even if some checks warn, doctor runs to completion. Failures would
|
|
// exit non-zero, which is OK — we're testing progress wiring.
|
|
// Require that some output happened on both streams.
|
|
expect(res.stderr.length).toBeGreaterThan(0);
|
|
expect(res.stdout.length).toBeGreaterThan(0);
|
|
|
|
// Parse stderr as JSONL. Extract every line that looks like a JSON
|
|
// object; tolerate stray non-JSON lines (warnings, dependency noise).
|
|
const lines = res.stderr.split('\n').filter(l => l.trim().startsWith('{'));
|
|
const events: Array<Record<string, unknown>> = [];
|
|
for (const line of lines) {
|
|
try {
|
|
events.push(JSON.parse(line));
|
|
} catch {
|
|
// Not a progress event — could be a legacy stderr logger line.
|
|
}
|
|
}
|
|
|
|
expect(events.length).toBeGreaterThan(0);
|
|
|
|
// We expect at least one 'start' for doctor.db_checks.
|
|
const starts = events.filter(e => e.event === 'start');
|
|
const phases = starts.map(e => e.phase);
|
|
expect(phases).toContain('doctor.db_checks');
|
|
|
|
// We expect at least one 'finish' for it too.
|
|
const finishes = events.filter(e => e.event === 'finish');
|
|
expect(finishes.some(e => e.phase === 'doctor.db_checks')).toBe(true);
|
|
|
|
// Every event has the canonical schema (event, phase, ts).
|
|
for (const ev of events) {
|
|
expect(typeof ev.event).toBe('string');
|
|
expect(typeof ev.phase).toBe('string');
|
|
expect(typeof ev.ts).toBe('string');
|
|
}
|
|
|
|
// Stdout should be doctor's --json payload (array of checks) and nothing
|
|
// that looks like a progress event. Parse it as JSON to ensure no stray
|
|
// progress-line pollution on stdout.
|
|
const parsed = JSON.parse(res.stdout);
|
|
expect(Array.isArray(parsed.checks) || Array.isArray(parsed)).toBe(true);
|
|
});
|
|
|
|
test('default (no --progress-json) writes human-plain progress to stderr only', () => {
|
|
const res = spawnSync('bun', [CLI, 'doctor'], {
|
|
encoding: 'utf-8',
|
|
env: { ...process.env, NO_COLOR: '1' },
|
|
timeout: 30_000,
|
|
});
|
|
|
|
// Stdout may contain the check summary (human-readable) but should NOT
|
|
// contain `[doctor.db_checks]` — that's stderr territory.
|
|
expect(res.stdout).not.toContain('[doctor.db_checks]');
|
|
|
|
// Stderr should contain the phase bracket marker at least once.
|
|
// Skip assertion if the DB had no pages and doctor short-circuits fast.
|
|
if (res.stderr.length > 0) {
|
|
expect(res.stderr).toContain('doctor.db_checks');
|
|
}
|
|
});
|
|
|
|
test('--quiet suppresses progress entirely', () => {
|
|
const res = spawnSync('bun', [CLI, '--quiet', 'doctor'], {
|
|
encoding: 'utf-8',
|
|
env: { ...process.env, NO_COLOR: '1' },
|
|
timeout: 30_000,
|
|
});
|
|
|
|
// With --quiet the reporter emits no start/finish/tick lines on stderr.
|
|
// Stderr may still contain warnings/errors from doctor's own logger,
|
|
// just no progress phases.
|
|
expect(res.stderr).not.toContain('[doctor.db_checks]');
|
|
expect(res.stderr).not.toContain('"event":"start"');
|
|
});
|
|
});
|