mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-28 14:59:47 +00:00
* fix(autopilot,eval): nightly quality probe enable path works end-to-end + wire conversation-parser probe Takeover of #2629 and #2630 (rebased onto master; dropped the test/engine-find-trajectory.test.ts hunk both PRs carried — master already ships the equivalent gateway-dims fix). #2629 — nightly quality probe enable path: - autopilot + doctor read the probe flag dual-plane (DB config row from 'gbrain config set' wins, ~/.gbrain/config.json fallback) via new resolveProbeEnabled/resolveProbeMaxUsd helpers - resolveRepoRoot prefers the gbrain package root where the committed fixture lives, not the brain repoPath - rate_limited skips no longer write an audit row every autopilot cycle - eval-longmemeval strips 'provider:' recipe ids before raw Anthropic SDK calls and emits the gold answer for downstream judges - cross-modal batch folds the gold answer into the judge task; probe passes QA-shaped dimensions instead of the agent-response rubric - DEFAULT_SLOTS slot A moves to openai:gpt-5.2 (gpt-4o left the recipe); new consistency test pins every default slot to its recipe #2630 — conversation-parser nightly probe wire-up: - autopilot step 4.6 invokes runConversationParserNightlyProbe (dual-plane flag + D10 tokenmax mode-gate, package-root fixtures, 24h gate, audit trail via new src/core/audit-parser-probe.ts) - doctor's conversation_parser_probe_health replaces the hardcoded 'Skipped' stub with a real pure-function check over the audit trail Co-authored-by: p3ob7o <p3ob7o@users.noreply.github.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(pricing): add openai:gpt-5.2 canonical entry for the new default slot A DEFAULT_SLOTS slot A moved to openai:gpt-5.2, which had no CANONICAL_PRICING entry — estimateCost silently dropped slot A from the --max-usd pre-flight and est_cost_usd audit rows (~1/3 under-count on the default panel). Rates from the OpenAI recipe chat touchpoint (verified 2026-04-20). Also refresh the --slot-a-model help text default and pin a pricing-presence assertion in the DEFAULT_SLOTS consistency test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Sinabina <sinabina@Sinabinas-MacBook-Pro-4.local> Co-authored-by: p3ob7o <p3ob7o@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Garry Tan <garrytan@gmail.com>
103 lines
3.4 KiB
TypeScript
103 lines
3.4 KiB
TypeScript
/**
|
|
* Tests for the parser-probe audit trail + the 24h rate-limit gate.
|
|
*
|
|
* Uses GBRAIN_AUDIT_DIR override pointed at a tmpdir for hermeticity
|
|
* (same pattern as audit-slug-fallback.serial.test.ts). Serial because
|
|
* the env override is process-global.
|
|
*/
|
|
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
import { mkdtempSync, rmSync, readdirSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
|
|
import {
|
|
computeParserProbeAuditFilename,
|
|
logParserProbeEvent,
|
|
parserProbeRanWithin,
|
|
readRecentParserProbeEvents,
|
|
type ParserProbeAuditEvent,
|
|
} from '../src/core/audit-parser-probe.ts';
|
|
|
|
let auditDir: string;
|
|
let savedEnv: string | undefined;
|
|
|
|
beforeEach(() => {
|
|
auditDir = mkdtempSync(join(tmpdir(), 'parser-probe-audit-'));
|
|
savedEnv = process.env.GBRAIN_AUDIT_DIR;
|
|
process.env.GBRAIN_AUDIT_DIR = auditDir;
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (savedEnv === undefined) delete process.env.GBRAIN_AUDIT_DIR;
|
|
else process.env.GBRAIN_AUDIT_DIR = savedEnv;
|
|
rmSync(auditDir, { recursive: true, force: true });
|
|
});
|
|
|
|
function makeEvent(overrides: Partial<ParserProbeAuditEvent> = {}): ParserProbeAuditEvent {
|
|
return {
|
|
schema_version: 1,
|
|
ts: new Date().toISOString(),
|
|
outcome: 'pass',
|
|
fixtures_total: 12,
|
|
fixtures_passed: 12,
|
|
recall_mean: 0.98,
|
|
participants_recall_mean: 0.97,
|
|
adversarial_false_positives: 0,
|
|
failed_fixture_ids: [],
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe('parser-probe audit trail', () => {
|
|
test('log + readRecent round-trip', () => {
|
|
logParserProbeEvent(makeEvent({ outcome: 'fail', reason: '2 fixture(s) failed' }));
|
|
const events = readRecentParserProbeEvents(7);
|
|
expect(events.length).toBe(1);
|
|
expect(events[0]!.outcome).toBe('fail');
|
|
expect(events[0]!.reason).toBe('2 fixture(s) failed');
|
|
const files = readdirSync(auditDir);
|
|
expect(files.length).toBe(1);
|
|
expect(files[0]).toMatch(/^parser-probe-\d{4}-W\d{2}\.jsonl$/);
|
|
});
|
|
|
|
test('filename uses ISO-week rotation with the parser-probe prefix', () => {
|
|
// Year-boundary edge pinned by the shared writer's own tests; here we
|
|
// pin the prefix wiring.
|
|
expect(computeParserProbeAuditFilename(new Date('2026-07-06T12:00:00Z'))).toBe(
|
|
'parser-probe-2026-W28.jsonl',
|
|
);
|
|
});
|
|
|
|
test('readRecent filters by window', () => {
|
|
const old = new Date(Date.now() - 10 * 86400000).toISOString();
|
|
logParserProbeEvent(makeEvent({ ts: old }));
|
|
expect(readRecentParserProbeEvents(7).length).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('parserProbeRanWithin — 24h rate-limit gate', () => {
|
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
|
|
test('false when no runs are audited', () => {
|
|
expect(parserProbeRanWithin(DAY_MS)).toBe(false);
|
|
});
|
|
|
|
test('true when a run landed within the window', () => {
|
|
logParserProbeEvent(makeEvent({ ts: new Date(Date.now() - 60_000).toISOString() }));
|
|
expect(parserProbeRanWithin(DAY_MS)).toBe(true);
|
|
});
|
|
|
|
test('false when the last run is older than the window', () => {
|
|
logParserProbeEvent(makeEvent({ ts: new Date(Date.now() - 25 * 3600_000).toISOString() }));
|
|
expect(parserProbeRanWithin(DAY_MS)).toBe(false);
|
|
});
|
|
|
|
test('non-pass outcomes also hold the window (mirrors quality-probe semantics)', () => {
|
|
logParserProbeEvent(makeEvent({
|
|
outcome: 'no_embedding_key',
|
|
ts: new Date(Date.now() - 3600_000).toISOString(),
|
|
}));
|
|
expect(parserProbeRanWithin(DAY_MS)).toBe(true);
|
|
});
|
|
});
|