mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-27 22:15:33 +00:00
Five specialist reviewers (testing/maintainability/security/performance/ data-migration) on the reconciled diff; every finding applied: Performance: the alias arm now resolves all granted sources CONCURRENTLY (a federated caller paid M sequential RTTs per turn — ~355ms at 5 sources cross-region, inside the reflex's 1.5s budget); watch's session dedupe is O(1) Set membership instead of a monotonically growing priorContext string (O(T²) over a long-lived session); getWindowTurns iterates from the tail (per-turn cost no longer grows with session length); the resolver's provenance maps fold into the existing candidate pass. Security: volunteer_context clamps caller-supplied attribution at the trust boundary — session_id capped at 256 chars (a read-scoped token could bank ~1MiB TEXT per request, retained 90 days), turn logged only when a safe integer (a non-integer threw inside the batched INSERT and silently dropped the whole batch). The privacy comments now state precisely what rationale may contain (the matched entity's surface form — which by construction resolved to an existing alias/title/slug — never free conversation text). Maintainability: TURN_PREFIX_RE + formatVolunteeredPage exported from volunteer.ts and shared by watch/cli (the two surfaces can no longer drift); volunteerEventRowsFrom is the single VolunteerEventRow assembly site for all three channels; watch's window default now honors the same retrieval_reflex_window_turns config knob the reflex reads; the stale pre-v116 comments swept to pre-v117. Testing: the two flake-class CRITICALs fixed (pipe test asserts the backstop banner instead of a cold-CI-hostile 9s wall bound; the SIGINT test waits on watch's new machine-readable ready line instead of a fixed 15s sleep — 2.5s and deterministic now); new coverage for the sink's timeout branch + ghost-reference drop, watch per-turn fail-open, untrusted knob clamps (min_confidence/max_pages/days), window-cap ordering (newest user mention survives), serve-IPC suppression passthrough + channel=reflex logging, windowTurnCount edge semantics, and structural pins for the sink registration + cycle purge wiring. The exit-verdict pin's grep is now operator/whitespace-tolerant. Deferred with TODOs: resolver index shapes for the per-turn query; batched first-prune after a long dream-cycle gap. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
48 lines
2.1 KiB
TypeScript
48 lines
2.1 KiB
TypeScript
/**
|
|
* v0.43 (#2084) — real-CLI pipe completeness pin (the incident #1959 class).
|
|
*
|
|
* The synthetic flush-mechanism coverage lives in
|
|
* test/flush-then-exit-harness.test.ts (4MB late-reader byte-complete pin).
|
|
* This file keeps the IMPLEMENTATION-AGNOSTIC check: the actual CLI, run the
|
|
* way agents run it (piped stdout), produces complete, parseable, byte-stable
|
|
* output and exits deliberately — well under the teardown backstop.
|
|
*/
|
|
|
|
import { describe, test, expect } from 'bun:test';
|
|
import { spawnSync } from 'child_process';
|
|
import { join, resolve } from 'path';
|
|
|
|
const REPO = resolve(import.meta.dir, '..');
|
|
const CLI = join(REPO, 'src', 'cli.ts');
|
|
|
|
describe('cli pipe completeness — deliberate exit never truncates piped stdout (#2084)', () => {
|
|
test('real CLI: --tools-json over a pipe is complete, parseable, byte-stable, and prompt', () => {
|
|
const run = () => {
|
|
const t0 = Date.now();
|
|
const res = spawnSync('bun', [CLI, '--tools-json'], {
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
encoding: 'utf-8',
|
|
timeout: 60_000,
|
|
env: { ...process.env, GBRAIN_SKIP_STARTUP_HOOKS: '1' },
|
|
maxBuffer: 64 * 1024 * 1024,
|
|
});
|
|
return { stdout: res.stdout ?? '', stderr: res.stderr ?? '', status: res.status, ms: Date.now() - t0 };
|
|
};
|
|
const first = run();
|
|
expect(first.status).toBe(0);
|
|
expect(Buffer.byteLength(first.stdout, 'utf-8')).toBeGreaterThan(16 * 1024);
|
|
// Truncated JSON does not parse — the strongest single-run completeness check.
|
|
const parsed = JSON.parse(first.stdout);
|
|
expect(Array.isArray(parsed)).toBe(true);
|
|
// Deliberate exit, not the teardown backstop. A wall-clock bound is flaky
|
|
// on cold CI (bun parse alone runs 10-20s there) — the backstop's banner
|
|
// is the truthful signal, same assertion the pgbouncer e2e uses.
|
|
expect(first.stderr).not.toContain('force-exiting');
|
|
expect(first.stderr).not.toContain('did not return within');
|
|
|
|
const second = run();
|
|
expect(second.status).toBe(0);
|
|
expect(second.stdout).toBe(first.stdout);
|
|
}, 180_000);
|
|
});
|