Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(entity): hyphenated surnames in variants, title stubs and text mentions; verify freshness (ARS E7/E8)

garrytanfad240004ee6
diff --git a/llms-full.txt b/llms-full.txt
index 876bf92711..5e5ac31ac1 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -4370,6 +4370,7 @@ that work in this conversation.
| 3 | `confirmation_required`, nothing ran | stop, relay `user_message`, run `fix.command` only after the user agrees |
| 10 | write accepted, still pending | poll the receipt (`gbrain write-request -- <id>`) |
| 11 | partial, resumable budget stop | run `resume_command` |
+| 12 | `no_results`: a recall or entity lookup matched nothing (only with `GBRAIN_FAIL_ON_EMPTY=1`) | treat it as a miss, not a failure |
| 13 | `pending_verify`: a harness wired, verification waits for the serve | start the serve, then run `fix.command` |
| 14 | `bootstrap_cleanup_pending`: a harness is wired; old shared-skills enrollments or token ids still await cleanup | follow `fix.next` (re-run, or relay the owner's revoke step), then re-run |
| 75 | another runner holds the migration lock | wait, then retry |
@@ -11199,6 +11200,7 @@ the exit code first, then reads the JSON document (`--json`) for the details:
| 3 | `confirmation_required`: nothing ran | consent payload (`effects`, `user_message`, `fix`) | stop, relay `user_message` to the user, run `fix.command` only after they agree |
| 10 | the write was accepted and is still pending | write receipt | poll the receipt (`gbrain write-request -- <id>`); `--accept-pending` maps this to 0 |
| 11 | partial, resumable budget stop | result with `remaining_*` and `resume_command` | run `resume_command` (it is safe to re-run) |
+| 12 | `no_results`: `gbrain recall` (an entity, text, `--grep`, `--question` or `--query` lookup) or `gbrain entity` matched nothing. Opt-in: only with `GBRAIN_FAIL_ON_EMPTY=1`; otherwise a miss exits 0 | recall's list output: `status: "no_results"`; entity: `found: false` | treat it as a miss, not a failure; a script that filters stdout can branch on it |
| 13 | `pending_verify`: `gbrain bootstrap harness --token` wired a PGLite brain while no serve answered; nothing failed, nothing verified yet | the harness result with `status: "pending_verify"` and `fix` | tell the user to start `gbrain serve --http`, then run `fix.command` with the same token; `bootstrap harness --status` stays partial until it passes ([pending verify](bootstrap.md#pending-verify)) |
| 14 | `bootstrap_cleanup_pending`: `gbrain bootstrap harness` (or `--status`) wired and verified the harness, but earlier shared-skills enrollments or carried token ids are not cleaned up yet | the harness result with `status: "cleanup_pending"`, a per-id `cleanup` list and `fix` | follow `fix.next`: `run` re-runs the same command; `tell_user_to_run` relays the owner's revoke or restore step, then re-run ([cleanup pending](bootstrap.md#cleanup-pending)) |
| 69 | `gbrain serve` exited on its own after its persistence consumer reported `restart_required` for `GBRAIN_SERVE_RESTART_REQUIRED_EXIT_SECONDS` (`serve_unhealthy_exit`; opt-in) | `[gbrain serve] error code=serve_unhealthy_exit` line on stderr | nothing: the supervisor (the installed service restarts on failure) starts a fresh serve; if it repeats, follow [the unhealthy exit](../ENGINES.md#serve-unhealthy-exit) |
diff --git a/plugin-variants/gbrain-coding/skills/conventions/agent-operator-protocol.md b/plugin-variants/gbrain-coding/skills/conventions/agent-operator-protocol.md
index 58d347384e..3cc8e84130 100644
--- a/plugin-variants/gbrain-coding/skills/conventions/agent-operator-protocol.md
+++ b/plugin-variants/gbrain-coding/skills/conventions/agent-operator-protocol.md
@@ -999,6 +999,7 @@ that work in this conversation.
| 3 | `confirmation_required`, nothing ran | stop, relay `user_message`, run `fix.command` only after the user agrees |
| 10 | write accepted, still pending | poll the receipt (`gbrain write-request -- <id>`) |
| 11 | partial, resumable budget stop | run `resume_command` |
+| 12 | `no_results`: a recall or entity lookup matched nothing (only with `GBRAIN_FAIL_ON_EMPTY=1`) | treat it as a miss, not a failure |
| 13 | `pending_verify`: a harness wired, verification waits for the serve | start the serve, then run `fix.command` |
| 14 | `bootstrap_cleanup_pending`: a harness is wired; old shared-skills enrollments or token ids still await cleanup | follow `fix.next` (re-run, or relay the owner's revoke step), then re-run |
| 75 | another runner holds the migration lock | wait, then retry |
diff --git a/plugin-variants/gbrain-daily/skills/conventions/agent-operator-protocol.md b/plugin-variants/gbrain-daily/skills/conventions/agent-operator-protocol.md
index 58d347384e..3cc8e84130 100644
--- a/plugin-variants/gbrain-daily/skills/conventions/agent-operator-protocol.md
+++ b/plugin-variants/gbrain-daily/skills/conventions/agent-operator-protocol.md
@@ -999,6 +999,7 @@ that work in this conversation.
| 3 | `confirmation_required`, nothing ran | stop, relay `user_message`, run `fix.command` only after the user agrees |
| 10 | write accepted, still pending | poll the receipt (`gbrain write-request -- <id>`) |
| 11 | partial, resumable budget stop | run `resume_command` |
+| 12 | `no_results`: a recall or entity lookup matched nothing (only with `GBRAIN_FAIL_ON_EMPTY=1`) | treat it as a miss, not a failure |
| 13 | `pending_verify`: a harness wired, verification waits for the serve | start the serve, then run `fix.command` |
| 14 | `bootstrap_cleanup_pending`: a harness is wired; old shared-skills enrollments or token ids still await cleanup | follow `fix.next` (re-run, or relay the owner's revoke step), then re-run |
| 75 | another runner holds the migration lock | wait, then retry |
diff --git a/plugin/README.md b/plugin/README.md
index 75280f9122..1a1ba182f3 100644
--- a/plugin/README.md
+++ b/plugin/README.md
@@ -8,7 +8,7 @@ addition/exclusion).
## MCP surface note (read once)
-The plugin's MCP server runs `gbrain serve --surface full` — 178
+The plugin's MCP server runs `gbrain serve --surface full` — 179
operations, the same surface every stdio registration gbrain writes pins.
Every gbrain operation the bundled skills name is on it. A harness that caps
its tool count can narrow this machine's plugin surface with
diff --git a/plugin/skills/conventions/agent-operator-protocol.md b/plugin/skills/conventions/agent-operator-protocol.md
index 58d347384e..3cc8e84130 100644
--- a/plugin/skills/conventions/agent-operator-protocol.md
+++ b/plugin/skills/conventions/agent-operator-protocol.md
@@ -999,6 +999,7 @@ that work in this conversation.
| 3 | `confirmation_required`, nothing ran | stop, relay `user_message`, run `fix.command` only after the user agrees |
| 10 | write accepted, still pending | poll the receipt (`gbrain write-request -- <id>`) |
| 11 | partial, resumable budget stop | run `resume_command` |
+| 12 | `no_results`: a recall or entity lookup matched nothing (only with `GBRAIN_FAIL_ON_EMPTY=1`) | treat it as a miss, not a failure |
| 13 | `pending_verify`: a harness wired, verification waits for the serve | start the serve, then run `fix.command` |
| 14 | `bootstrap_cleanup_pending`: a harness is wired; old shared-skills enrollments or token ids still await cleanup | follow `fix.next` (re-run, or relay the owner's revoke step), then re-run |
| 75 | another runner holds the migration lock | wait, then retry |
diff --git a/scripts/page-body-readers-baseline.tsv b/scripts/page-body-readers-baseline.tsv
index c315df6c79..185739e1c2 100644
--- a/scripts/page-body-readers-baseline.tsv
+++ b/scripts/page-body-readers-baseline.tsv
@@ -564,7 +564,7 @@ src/core/utils.ts contentHashLegacy field META legacy formula over an inline pag
src/core/utils.ts rowToPage field INLINE installs throwing body getters on a segmented row (guardSegmentedBody); inline rows copy the columns
src/core/utils.ts rowToStalePage field STREAM listStalePagesForExtraction lists inline pages only (segmented skipped in SQL, still counted stale)
src/core/verbs/entity-card-identity.ts excerptSource field LEAD inline pages only; a segmented page reads truthLead (EXCERPT_LEAD_BYTES)
-src/core/verbs/entity-card.ts selectEntityCandidates sql LEAD boundedBodyPrefixSql AS compiled_truth
+src/core/verbs/entity-card.ts CARD_ROW_COLUMNS sql LEAD boundedBodyPrefixSql AS compiled_truth
src/core/verbs/entity-names.ts lookupOne field LEAD bounded prefix rows
src/core/verbs/entity-names.ts lookupOne sql LEAD boundedBodyPrefixSql AS compiled_truth
src/core/write-gate-scan.ts SPECS field STREAM
diff --git a/skills/skills.lock.json b/skills/skills.lock.json
index 843b6c5d7b..7f96493773 100644
--- a/skills/skills.lock.json
+++ b/skills/skills.lock.json
@@ -44,7 +44,7 @@
"concept-synthesis/routing-eval.jsonl": "96dbd7d9c1b606e9e06262d0c06282399741e2bccb8eeb7b9ca88c20f44cda0e",
"context-audit/SKILL.md": "6d786629d40544ddaab4f4e6e333569d270bcb8b581589dc16fb9f8bcb4f6207",
"context-audit/routing-eval.jsonl": "fb1832e24cc1b04163a74c5cde72bca53050a66246ca902e1a5f40303f52b5ab",
- "conventions/agent-operator-protocol.md": "d7cfc7e4c84f61392658cbe969058b1e8237b7d44c3ebdeec352569ffddbe001",
+ "conventions/agent-operator-protocol.md": "4331a4ec8d3d58c54a1dd0c50f1b15e4e1d1fdf3273849ac1694df61d6bc0f2b",
"conventions/brain-first.md": "987223ce443b3e8cdcd22975aafabce778016f238deddf544c346238dbde1bd9",
"conventions/brain-routing.md": "392998d9a109b330c9225af4ca5c8798b0ff02eba4d441c93fdb7c263687d0c6",
"conventions/calibration.md": "500dc26bd7c8400f50dc4c16fd83f1a588f3e7e68c59050a21fd8a0f69e4d198",
diff --git a/src/commands/doctor/checks/entity-duplicates.ts b/src/commands/doctor/checks/entity-duplicates.ts
index 14536bb389..c8ee9e8eb9 100644
--- a/src/commands/doctor/checks/entity-duplicates.ts
+++ b/src/commands/doctor/checks/entity-duplicates.ts
@@ -18,7 +18,7 @@
* (PAIR_SCAN_CAP per brain), one variant read each, one batched link count.
*/
import type { Check } from '../../doctor.ts';
-import { NAME_TITLE_TOKENS, parsePersonName } from '../../../core/entities/name-variants.ts';
+import { NAME_TITLE_TOKENS, hasLeadingTitle, stripLeadingTitles } from '../../../core/entities/name-variants.ts';
import { resolveNameVariant } from '../../../core/verbs/entity-variants.ts';
import { retiredPageSql } from '../../../core/entities/resolve.ts';
import { doctorVerify } from '../check-fix.ts';
@@ -54,7 +54,8 @@ async function runPersonTitleDuplicates(ctx: DoctorContext): Promise<Check[]> {
if (stubs.length > PAIR_SCAN_CAP - scanned) capped = true;
for (const stub of stubs.slice(0, PAIR_SCAN_CAP - scanned)) {
scanned++;
- const remainder = parsePersonName((stub.slug.split('/').pop() ?? '').replace(/-/g, ' ')).core.join(' ');
+ const named = [stub.title ?? '', (stub.slug.split('/').pop() ?? '').replace(/-/g, ' ')].find(hasLeadingTitle);
+ const remainder = named ? stripLeadingTitles(named) : '';
if (!remainder) continue;
const res = await resolveNameVariant(engine, sourceId, remainder, {
selectColumns: 'slug, title, type, frontmatter', privatePredicate: '', retirementPrivacy: '', entityTypes: new Set(['person']), exclude: [stub.slug],
diff --git a/src/core/entities/name-variants.ts b/src/core/entities/name-variants.ts
index 181d0832ee..30137f604c 100644
--- a/src/core/entities/name-variants.ts
+++ b/src/core/entities/name-variants.ts
@@ -103,9 +103,16 @@ export interface PersonName {
titles: string[];
}
+/** nameWords, keeping a hyphenated word whole ("Smith-Jones" is one surname, not two names); a slug basename (`alice-example`, no space, lowercase) splits. */
+function personTokens(text: string): string[] {
+ if (!/\s/.test(text ?? '') && text === (text ?? '').toLowerCase()) return nameWords(text);
+ const folded = foldNonDecomposingLatin((text ?? '').normalize('NFKD').replace(/\p{M}/gu, '').toLowerCase());
+ return folded.split(/[^\p{L}\p{N}-]+/u).map(t => t.replace(/^-+|-+$/g, '')).filter(Boolean);
+}
+
/** Split a name into its core words and the titles in front of it; a name that is only titles keeps them as its core. */
export function parsePersonName(text: string): PersonName {
- const words = nameWords(text);
+ const words = personTokens(text);
let start = 0;
while (start < words.length - 1 && NAME_TITLE_TOKENS.has(words[start]!)) start++;
let end = words.length;
@@ -113,6 +120,14 @@ export function parsePersonName(text: string): PersonName {
return { core: words.slice(start, end), titles: words.slice(0, start) };
}
+/** The name as written, without its leading title words ("Mayor Quill-Example" -> "Quill-Example"). */
+export function stripLeadingTitles(text: string): string {
+ const parts = (text ?? '').trim().split(/\s+/);
+ let start = 0;
+ while (start < parts.length - 1 && nameWords(parts[start]!).every(w => NAME_TITLE_TOKENS.has(w))) start++;
+ return parts.slice(start).join(' ');
+}
+
/** True when the page name starts with a title word ("Mayor Example", `people/dr-alice-example`). */
export function hasLeadingTitle(text: string): boolean {
return parsePersonName(text).titles.length > 0;
diff --git a/src/core/operation-manifest.generated.ts b/src/core/operation-manifest.generated.ts
index cf20d7a1c5..bcef326afe 100644
--- a/src/core/operation-manifest.generated.ts
+++ b/src/core/operation-manifest.generated.ts
@@ -143,7 +143,8 @@ export const OPERATION_MANIFEST: OperationMeta[] = [
},
"variants": {
"type": "boolean",
- "description": "Default true: when no exact name matches, resolve one unambiguous name variant (nickname, initial, title, order, surname typo, unique surname; card.match says which). false: exact names only."
+ "description": "false: exact names only. Default true: with no exact match, one unambiguous name variant (card.match says which).",
+ "fullSurfaceOnly": true
}
},
"scope": "read",
diff --git a/src/core/verbs/entity-text-mentions.ts b/src/core/verbs/entity-text-mentions.ts
index ba43f5ed0a..d52f9439df 100644
--- a/src/core/verbs/entity-text-mentions.ts
+++ b/src/core/verbs/entity-text-mentions.ts
@@ -79,7 +79,7 @@ async function probe(
const words = nameWords(name);
let rows: SearchResult[];
try {
- rows = await engine.searchKeyword(`"${words.join(' ')}"`, {
+ rows = await engine.searchKeyword(`"${name.replace(/"/g, ' ').trim()}"`, {
limit: TEXT_MENTION_POOL,
...(sources.length === 1 ? { sourceId: sources[0] } : { sourceIds: [...sources] }),
excludePrivate: opts.excludePrivate,
diff --git a/src/core/verbs/entity-variants.ts b/src/core/verbs/entity-variants.ts
index 4a1d9b40f1..087229f951 100644
--- a/src/core/verbs/entity-variants.ts
+++ b/src/core/verbs/entity-variants.ts
@@ -16,7 +16,7 @@
import type { BrainEngine } from '../engine.ts';
import { isQuarantined } from '../quarantine.ts';
import { followRetirement, isIdentityEntity } from '../entities/resolve.ts';
-import { NAME_MATCH_RANK, NAME_TITLE_TOKENS, WEAK_NAME_MATCHES, hasLeadingTitle, matchNameVariant, parsePersonName, probeWords, type NameMatchKind } from '../entities/name-variants.ts';
+import { NAME_MATCH_RANK, NAME_TITLE_TOKENS, WEAK_NAME_MATCHES, hasLeadingTitle, matchNameVariant, parsePersonName, probeWords, stripLeadingTitles, type NameMatchKind } from '../entities/name-variants.ts';
/** Candidate rows read per source; a full read means another page may have matched, so nothing resolves. */
export const VARIANT_CANDIDATE_CAP = 200;
@@ -44,6 +44,7 @@ const basenameName = (slug: string) => (slug.split('/').pop() ?? '').replace(/[-
/** The strongest variant under which `name` names this page (by title or slug basename). */
function bestKind(name: string, row: VariantRow): NameMatchKind | null {
+ if (isTitleStub(row.title || basenameName(row.slug))) return null;
const kinds = [row.title ?? '', basenameName(row.slug)]
.filter(candidate => !isTitleStub(candidate))
.map(candidate => matchNameVariant(name, candidate))
@@ -139,7 +140,7 @@ export async function readPossibleDuplicates<R extends VariantRow>(
const resolveRemainder = async (stub: VariantRow): Promise<string | null> => {
const name = [stub.title ?? '', basenameName(stub.slug)].find(hasLeadingTitle);
if (!name) return null;
- const res = await resolveNameVariant<R>(engine, sourceId, parsePersonName(name).core.join(' '), { ...opts, exclude: [stub.slug] });
+ const res = await resolveNameVariant<R>(engine, sourceId, stripLeadingTitles(name), { ...opts, exclude: [stub.slug] });
return res.hit?.row.slug ?? null;
};
try {
diff --git a/test/doctor-person-title-duplicates.test.ts b/test/doctor-person-title-duplicates.test.ts
index f709b9d614..3cad551286 100644
--- a/test/doctor-person-title-duplicates.test.ts
+++ b/test/doctor-person-title-duplicates.test.ts
@@ -39,6 +39,18 @@ async function check() {
}
describe('person_title_duplicates', () => {
+ test('a hyphenated surname pairs too, in both title styles', async () => {
+ await person('people/ada-quill-example', 'Ada Quill-Example');
+ await person('people/mayor-quill-example', 'Mayor Quill-Example');
+ await person('people/ceo-fen-example', 'CEO Fen-Example');
+ await person('people/cy-fen-example', 'Cy Fen-Example');
+ const c = await check();
+ expect(c.details.pairs.map((p: any) => [p.stub, p.canonical])).toEqual([
+ ['people/ceo-fen-example', 'people/cy-fen-example'],
+ ['people/mayor-quill-example', 'people/ada-quill-example'],
+ ]);
+ });
+
test('ok when no titled person page exists', async () => {
const c = await check();
expect(c).toMatchObject({ name: 'person_title_duplicates', status: 'ok' });
diff --git a/test/entity-card-name-variants.test.ts b/test/entity-card-name-variants.test.ts
index eecc3a839e..4f021acd16 100644
--- a/test/entity-card-name-variants.test.ts
+++ b/test/entity-card-name-variants.test.ts
@@ -106,6 +106,15 @@ describe('title-prefixed duplicates are reported, never substituted', () => {
expect(res.card!.possible_duplicates).toEqual([{ slug: 'people/mayor-thistlewood', title: 'Mayor Thistlewood', reason: 'title_prefix' }]);
});
+ test('a hyphenated surname pairs both ways', async () => {
+ await person('people/ada-quill-example', 'Ada Quill-Example');
+ await person('people/mayor-quill-example', 'Mayor Quill-Example');
+ const stub = await buildEntityCard(engine, 'default', 'Mayor Quill-Example', { remote: false, includeReferences: true, variants: true });
+ expect(stub.card!.possible_duplicates).toEqual([{ slug: 'people/ada-quill-example', title: 'Ada Quill-Example', reason: 'title_prefix' }]);
+ const real = await buildEntityCard(engine, 'default', 'Ada Quill-Example', { remote: false, includeReferences: true, variants: true });
+ expect(real.card!.possible_duplicates).toEqual([{ slug: 'people/mayor-quill-example', title: 'Mayor Quill-Example', reason: 'title_prefix' }]);
+ });
+
test('a surname two people share pairs the stub with nobody', async () => {
await person('people/margaret-thistlewood', 'Margaret Thistlewood');
const res = await buildEntityCard(engine, 'default', 'Mayor Thistlewood', { remote: false, includeReferences: true, variants: true });
diff --git a/test/entity-card-text-mentions.test.ts b/test/entity-card-text-mentions.test.ts
index 03ce95c060..1d63265c0d 100644
--- a/test/entity-card-text-mentions.test.ts
+++ b/test/entity-card-text-mentions.test.ts
@@ -52,6 +52,12 @@ describe('a name with no page', () => {
expect(res.text_mentions!.pages.map(p => p.slug)).toEqual(['notes/2026-04-02', 'notes/2026-03-01']);
});
+ test('a hyphenated surname is found as written', async () => {
+ await note('notes/2026-07-01', 'Coffee with Bea Marsh-Example and Cy Fen-Example about the harbor grant.');
+ const res = await card('Bea Marsh-Example');
+ expect(res.text_mentions!.pages.map(p => p.slug)).toEqual(['notes/2026-07-01']);
+ });
+
test('a name nobody wrote has no text_mentions', async () => {
const res = await card('Quentin Nobody');
expect(res.found).toBe(false);
diff --git a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
index 3a374732cd..1f6bc0dde0 100644
--- a/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
+++ b/test/fixtures/goldens/doctor/hot-checks-postgres-json.json
@@ -3806,6 +3806,18 @@
"name": "fence_integrity",
"status": "warn"
},
+ {
+ "category": "brain",
+ "details": {
+ "capped": false,
+ "pairs": [],
+ "scanned": 0
+ },
+ "elapsed_ms": "<volatile>",
+ "message": "No title-prefixed person page pairs with an unprefixed page (0 titled page(s) examined).",
+ "name": "person_title_duplicates",
+ "status": "ok"
+ },
{
"category": "ops",
"elapsed_ms": "<volatile>",
@@ -8242,6 +8254,18 @@
"name": "fence_integrity",
"status": "warn"
},
+ {
+ "category": "brain",
+ "details": {
+ "capped": false,
+ "pairs": [],
+ "scanned": 0
+ },
+ "elapsed_ms": "<volatile>",
+ "message": "No title-prefixed person page pairs with an unprefixed page (0 titled page(s) examined).",
+ "name": "person_title_duplicates",
+ "status": "ok"
+ },
{
"category": "ops",
"elapsed_ms": "<volatile>",
diff --git a/test/fixtures/goldens/doctor/json-postgres-fresh.json b/test/fixtures/goldens/doctor/json-postgres-fresh.json
index 91ec18d1a6..2185628724 100644
--- a/test/fixtures/goldens/doctor/json-postgres-fresh.json
+++ b/test/fixtures/goldens/doctor/json-postgres-fresh.json
@@ -3147,6 +3147,18 @@
"name": "fence_integrity",
"status": "ok"
},
+ {
+ "category": "brain",
+ "details": {
+ "capped": false,
+ "pairs": [],
+ "scanned": 0
+ },
+ "elapsed_ms": "<volatile>",
+ "message": "No title-prefixed person page pairs with an unprefixed page (0 titled page(s) examined).",
+ "name": "person_title_duplicates",
+ "status": "ok"
+ },
{
"category": "ops",
"elapsed_ms": "<volatile>",
diff --git a/test/no-results-exit-7177.test.ts b/test/no-results-exit-7177.test.ts
index b3cbc7c450..3286540bd5 100644
--- a/test/no-results-exit-7177.test.ts
+++ b/test/no-results-exit-7177.test.ts
@@ -13,6 +13,9 @@ import { formatEntityResult, markEntityMiss } from '../src/cli/entity-format.ts'
import { currentExitCode, _resetCliExitVerdictForTests } from '../src/core/cli-force-exit.ts';
import { NO_RESULTS_EXIT_CODE } from '../src/core/exit-codes.ts';
import { resetPgliteState } from './helpers/reset-pglite.ts';
+import { withEnv } from './helpers/with-env.ts';
+
+const failOnEmpty = <T>(fn: () => T | Promise<T>) => withEnv({ GBRAIN_FAIL_ON_EMPTY: '1' }, fn);
let engine: PGLiteEngine;
const origOut = process.stdout.write.bind(process.stdout);
@@ -55,7 +58,6 @@ beforeEach(async () => {
await engine.insertFact({ fact: 'prefers morning meetings', kind: 'preference', entity_slug: 'people/alice-example', source: 'test', visibility: 'world' } as never, { source_id: 'default' });
});
afterEach(() => {
- delete process.env.GBRAIN_FAIL_ON_EMPTY;
_resetCliExitVerdictForTests();
process.exitCode = 0;
});
@@ -74,27 +76,25 @@ describe('recall, default', () => {
});
describe('recall, GBRAIN_FAIL_ON_EMPTY=1', () => {
- beforeEach(() => { process.env.GBRAIN_FAIL_ON_EMPTY = '1'; });
-
- test('a hit exits 0', async () => {
+ test('a hit exits 0', () => failOnEmpty(async () => {
expect(await recall(['people/alice-example'])).toBe(0);
expect(await recall(['--grep', 'morning'])).toBe(0);
- });
+ }));
- test('an entity, text or --grep lookup that matches nothing exits 12 with one stderr line', async () => {
+ test('an entity, text or --grep lookup that matches nothing exits 12 with one stderr line', () => failOnEmpty(async () => {
for (const args of [['people/carol-example'], ['zebra'], ['--grep', 'zebra'], ['people/alice-example', '--grep', 'zebra']]) {
expect(await recall(args)).toBe(NO_RESULTS_EXIT_CODE);
expect(err).toContain('[recall] exit 12 (no_results): nothing matched (GBRAIN_FAIL_ON_EMPTY=1).');
}
- });
+ }));
- test('a --json miss exits 12 too', async () => {
+ test('a --json miss exits 12 too', () => failOnEmpty(async () => {
expect(await recall(['people/carol-example', '--json'])).toBe(NO_RESULTS_EXIT_CODE);
- });
+ }));
- test('a feed read with nothing new is not a miss', async () => {
+ test('a feed read with nothing new is not a miss', () => failOnEmpty(async () => {
expect(await recall(['--grep', 'zebra', '--since-last-run'])).toBe(0);
- });
+ }));
});
describe('entity', () => {
@@ -106,17 +106,15 @@ describe('entity', () => {
expect(currentExitCode()).toBe(0);
});
- test('with GBRAIN_FAIL_ON_EMPTY=1 a miss exits 12; the miss line is plain, timing and coverage on their own lines', () => {
- process.env.GBRAIN_FAIL_ON_EMPTY = '1';
+ test('with GBRAIN_FAIL_ON_EMPTY=1 a miss exits 12; the miss line is plain, timing and coverage on their own lines', () => failOnEmpty(() => {
_resetCliExitVerdictForTests();
silenced(() => markEntityMiss('entity', miss));
expect(currentExitCode()).toBe(NO_RESULTS_EXIT_CODE);
expect(err).toContain('[entity] exit 12 (no_results)');
expect(formatEntityResult(miss).split('\n')).toEqual(['No entity found.', ' mention coverage: pending, 40 page(s) pending', ' (2613ms)', '']);
- });
+ }));
- test('a found card, a miss with text mentions and other ops exit 0', () => {
- process.env.GBRAIN_FAIL_ON_EMPTY = '1';
+ test('a found card, a miss with text mentions and other ops exit 0', () => failOnEmpty(() => {
for (const [op, r] of [
['entity', { found: true, card: {} }],
['entity', { ...miss, text_mentions: { total: 2, pages: [] } }],
@@ -126,5 +124,5 @@ describe('entity', () => {
silenced(() => markEntityMiss(op, r));
expect(currentExitCode()).toBe(0);
}
- });
+ }));
});