mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-27 22:15:33 +00:00
* fix: dream --source/--source-id plumbs sourceId to runCycle (supersedes #1559) Closes the silent-no-op class where `gbrain dream --source <id>` ran the cycle but never wrote `last_full_cycle_at`, leaving `gbrain doctor`'s cycle_freshness check stuck red forever. Changes to src/commands/dream.ts: - DreamArgs.source field; parseArgs recognizes --source <id> AND the --source-id alias (matches v0.37.7.0 #1167 naming across import/extract/graph-query) - Argv validation: missing value → exit 2; repeated different values → exit 2; --source X --source-id Y conflict → exit 2; same-value repetition → accepted - --help short-circuit ordering preserved with IRON-RULE comment + structural test guard - runDream engine-null guard: --source requires a connected brain - runDream resolveSourceId → archived-source guard via fetchSource from src/core/sources-load.ts (single-row SELECT that projects archived + handles pre-v0.26.5 schema via isUndefinedColumnError) - Typed-error try/catch via isResolverUserError predicate: only swallows known resolver-user errors; TypeError / postgres errors propagate uncaught with stack trace so genuine programmer bugs aren't hidden behind operator-error UX - Forwarded sourceId to runCycle; existing v0.38 writeback at cycle.ts:1947-1967 now actually fires - --help text documents both flag names Tests: - test/dream-cli-flags.test.ts: structural assertions for new flags, help text, IRON-RULE comment guard, resolver/predicate wiring - test/dream.test.ts: 13 PGLite integration cases covering happy path (the regression that closes PR #1559), back-compat, alias equivalence, all argv edge cases, engine-null, archived, --help short-circuit ordering, T3 typed-error propagation, and D5 end-to-end dream→checkCycleFreshness column-name drift guard Plan + 11 decisions: ~/.claude/plans/system-instruction-you-are-working-starry-papert.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix: judgeSignificance uses canonical safeSplitIndex (closes #1559/#1561 emoji crash) Closes the 2026-05-24 production SYNTH_PHASE_FAIL: 🤖 (U+1F916, surrogate pair U+D83E U+DD16) at offset 3999 in a long telegram transcript made the raw 4000-char slice produce a lone high surrogate; Anthropic's JSON parser rejected the payload with "no low surrogate in string"; the synthesize phase failed. Changes to src/core/cycle/synthesize.ts: - judgeSignificance head+tail slice routed through safeSplitIndex from src/core/text-safe.ts (already imported) - Did NOT introduce safeSliceEnd from PRs #1559+#1561 — that helper re-introduces the case-3 bug src/core/text-safe.ts:18-21 documents - Did NOT touch findBoundary — master already routes through safeSplitIndex per the v0.42.0.0 wave Tests in test/cycle-synthesize.test.ts: - New describe('judgeSignificance — UTF-16 safety') block - test.each over head boundaries (offsets 3998-4001) AND tail boundaries (offsets 3999-4002) for an 8001-char content with the robot emoji placed at each - Primary assertion: explicit unpaired-surrogate scan over the captured prompt (NOT JSON.stringify per codex C-11 — V8/JSCore do not throw on lone surrogates, so that assertion was weak) - Sub-8000 short-content branch case: no slicing, emoji passes through unchanged Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix: expand error_page_title + add cloudflare_challenge_title (supersedes #1561) Closes the bug class where scraper error pages with titles like "Forbidden", "Access Denied", "Service Unavailable", "Robot Check", and "Just a moment..." were slipping through the ingest gate because the matcher only caught bare numeric codes (403/404/500...) and "page not found". 232+ pages observed (202+ from straylight- brain) were inflating page counts and tripping content_sanity_audit_recent on every doctor run. Changes to src/core/content-sanity.ts BUILT_IN_JUNK_PATTERNS: - Expanded error_page_title regex to also catch forbidden, access denied, service unavailable, robot check, verify you are human (case-insensitive, anchored — so long-form essays about these topics still ingest fine) - New cloudflare_challenge_title pattern with DISTINCT name from error_page_title (PR #1561 collapsed both into one name and lost audit signal — the new name preserves diagnosability in ~/.gbrain/audit/content-sanity-YYYY-Www.jsonl and doctor's content_sanity_audit_recent aggregation) - Dropped PR #1561's bare-`error` matcher — too aggressive on legitimate concept/taxonomy pages titled exactly "Error" Tests: - test/content-sanity.test.ts: pattern-count locked at 7, new matches via test.each, over-match regression guard (legitimate prose titled "How to Handle Access Denied Errors" / "Error Boundary in React" etc. must pass), audit-name distinctness pinned - test/import-file-content-sanity.test.ts: end-to-end ContentSanityBlockError via importFromContent for each new pattern family (D6 — assessor wiring coverage, not just regex) Out of scope, filed in TODOS.md as TODO-V13-C: gbrain pages audit-junk-titles legacy-cleanup command. Dropped from this PR per codex outside-voice tension (T1) for ship-and-validate- matchers-first discipline. The 200+ pre-existing scraper pages already in the DB will get the destructive-cleanup operator surface after ~1 week of production observation against this matcher. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: bump v0.41.23.0 + CHANGELOG + follow-up TODOs VERSION + package.json bump to 0.41.23.0. CHANGELOG voice: ELI10 lead naming the bug ("`gbrain dream --source <id>` finally counts as a cycle"), then per-fix detail, then a "To take advantage of v0.41.23.0" operator-action block and itemized changes. TODOS.md v0.41.23.x follow-ups: - TODO-V13-A (P2): --max-pages plumbing (PR #1559's flag, deferred because CycleOpts has no maxPages field today) - TODO-V13-B (P3): --source vs --source-id flag-name unification across all CLI commands - TODO-V13-C (P2): gbrain pages audit-junk-titles legacy cleanup (deferred for ~1 week of matcher production observation) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: bump v0.41.25.0 → v0.41.26.0 (leave headroom for in-flight PR) Master shipped v0.41.23.0 + v0.41.24.0 mid-review; this branch originally bumped to v0.41.25.0 post-merge. User flagged v0.41.26.0 to leave a slot open for another in-flight PR. No code changes; VERSION + package.json + CHANGELOG header + "To take advantage" section updated in lockstep. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
109 lines
3.9 KiB
TypeScript
109 lines
3.9 KiB
TypeScript
/**
|
|
* Structural tests for `gbrain dream` argv parsing (v0.21).
|
|
*
|
|
* Verifies the help text + parser source contains the new flags
|
|
* (--input, --date, --from, --to) and that conflict detection is wired.
|
|
* The actual parseArgs is internal; we exercise it via the source file
|
|
* structure to avoid spinning up a process per test.
|
|
*/
|
|
|
|
import { describe, test, expect } from 'bun:test';
|
|
import { readFileSync } from 'fs';
|
|
|
|
const dreamSrc = readFileSync(new URL('../src/commands/dream.ts', import.meta.url), 'utf-8');
|
|
|
|
describe('dream CLI flag wiring', () => {
|
|
test('declares --input flag with file argument', () => {
|
|
expect(dreamSrc).toContain("'--input'");
|
|
expect(dreamSrc).toContain('inputFile');
|
|
});
|
|
|
|
test('declares --date / --from / --to flags', () => {
|
|
expect(dreamSrc).toContain("'--date'");
|
|
expect(dreamSrc).toContain("'--from'");
|
|
expect(dreamSrc).toContain("'--to'");
|
|
});
|
|
|
|
test('validates ISO date format', () => {
|
|
expect(dreamSrc).toMatch(/ISO_DATE_RE/);
|
|
expect(dreamSrc).toContain('YYYY-MM-DD');
|
|
});
|
|
|
|
test('--input + --date conflict detection', () => {
|
|
expect(dreamSrc).toContain('--input cannot be combined with --date');
|
|
});
|
|
|
|
test('--input implies --phase synthesize', () => {
|
|
expect(dreamSrc).toContain("phase = 'synthesize'");
|
|
});
|
|
|
|
test('--from > --to range validation', () => {
|
|
expect(dreamSrc).toContain('empty range');
|
|
});
|
|
|
|
test('forwards synth fields to runCycle', () => {
|
|
expect(dreamSrc).toContain('synthInputFile');
|
|
expect(dreamSrc).toContain('synthDate');
|
|
expect(dreamSrc).toContain('synthFrom');
|
|
expect(dreamSrc).toContain('synthTo');
|
|
});
|
|
|
|
test('totals line includes synth + patterns counters', () => {
|
|
expect(dreamSrc).toContain('synth_transcripts');
|
|
expect(dreamSrc).toContain('synth_pages');
|
|
expect(dreamSrc).toContain('patterns=');
|
|
});
|
|
|
|
test('help text documents dry-run synthesis semantics (Codex finding #8)', () => {
|
|
expect(dreamSrc).toContain('skips the Sonnet');
|
|
expect(dreamSrc.toLowerCase()).toContain('zero llm calls');
|
|
});
|
|
|
|
// v0.41.13: --source / --source-id flag wiring (supersedes PR #1559).
|
|
// Structural-only tests; behavioral tests live in test/dream.test.ts.
|
|
describe('--source / --source-id wiring (v0.41.13)', () => {
|
|
test('declares --source flag in argv parsing', () => {
|
|
expect(dreamSrc).toContain("'--source'");
|
|
});
|
|
|
|
test('declares --source-id alias in argv parsing', () => {
|
|
expect(dreamSrc).toContain("'--source-id'");
|
|
});
|
|
|
|
test('forwards resolved sourceId to runCycle', () => {
|
|
// The runCycle call must pass sourceId; gate name "sourceId"
|
|
// not "source" because CycleOpts.sourceId is the contract.
|
|
expect(dreamSrc).toMatch(/sourceId:\s*resolvedSourceId/);
|
|
});
|
|
|
|
test('imports resolveSourceId from canonical source-resolver helper', () => {
|
|
expect(dreamSrc).toContain("from '../core/source-resolver.ts'");
|
|
expect(dreamSrc).toContain('resolveSourceId');
|
|
});
|
|
|
|
test('declares isResolverUserError predicate for typed-error catch (T3 from eng review)', () => {
|
|
expect(dreamSrc).toContain('function isResolverUserError');
|
|
});
|
|
|
|
test('documents --source in --help output', () => {
|
|
expect(dreamSrc).toContain('--source <id>');
|
|
expect(dreamSrc).toContain('--source-id <id>');
|
|
});
|
|
|
|
test('preserves --help short-circuit ordering comment (IRON RULE)', () => {
|
|
// The comment lives in runDream BEFORE the engine-null gate.
|
|
// Future refactors that reorder these blocks will trip this guard.
|
|
expect(dreamSrc).toContain('IRON RULE: --help short-circuits BEFORE');
|
|
});
|
|
|
|
test('declares engine-null guard for --source', () => {
|
|
expect(dreamSrc).toContain('requires a connected brain');
|
|
});
|
|
|
|
test('declares archived-source guard', () => {
|
|
expect(dreamSrc).toMatch(/source.*is archived/);
|
|
expect(dreamSrc).toContain('gbrain sources restore');
|
|
});
|
|
});
|
|
});
|