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>
35 lines
1.8 KiB
TypeScript
35 lines
1.8 KiB
TypeScript
/**
|
|
* #2084 class pin — every exit-code write in src/ routes through
|
|
* setCliExitVerdict.
|
|
*
|
|
* A RAW `process.exitCode = N` is silently ZEROED by the deliberate
|
|
* flush-exit: currentExitCode() reads only gbrain's owned verdict (the
|
|
* PGLite-Emscripten-pollution defense), so a command that bypasses the
|
|
* setter reports success on failure. Caught live twice in one day: doctor's
|
|
* FAIL path exited 0 after a merge introduced a raw write. Runtime variants
|
|
* are pinned in test/cli-finish-teardown.test.ts; this is the structural
|
|
* guard that catches the NEXT raw write at review time.
|
|
*/
|
|
|
|
import { describe, test, expect } from 'bun:test';
|
|
import { execSync } from 'child_process';
|
|
|
|
describe('exit-verdict ownership — no raw process.exitCode assignments', () => {
|
|
test('every exit-code write in src/ routes through setCliExitVerdict', () => {
|
|
// Two legitimate writers are exempt:
|
|
// - cli-force-exit.ts: setCliExitVerdict's own mirror-write.
|
|
// - pglite-engine.ts preservingProcessExitCode: #2141's containment
|
|
// RESTORE around PGlite.create() — it keeps the GLOBAL tidy for
|
|
// external readers and is explicitly not a verdict write (the owned
|
|
// channel never reads process.exitCode).
|
|
// Whitespace/operator-tolerant: catches `process.exitCode=1`,
|
|
// `process.exitCode ??= 1`, `process.exitCode ||= 1`, and the bracket
|
|
// form — every shape is equally zeroed by the owned-verdict read.
|
|
const hits = execSync(
|
|
String.raw`grep -rnE "process(\.|\[')exitCode('\])?[[:space:]]*([?|&]{2})?=[^=]" src --include='*.ts' | grep -v "core/cli-force-exit.ts" | grep -v "core/pglite-engine.ts" || true`,
|
|
{ encoding: 'utf-8', cwd: new URL('..', import.meta.url).pathname },
|
|
).trim();
|
|
expect(hits).toBe('');
|
|
});
|
|
});
|