Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(evidence-delivery): off-path capture drops a notice-only _meta instead of leaving {}

garrytan7588a35a26c2
diff --git a/test/evidence-delivery-golden.test.ts b/test/evidence-delivery-golden.test.ts
index b9a474584f..d22d8dee64 100644
--- a/test/evidence-delivery-golden.test.ts
+++ b/test/evidence-delivery-golden.test.ts
@@ -21,7 +21,10 @@ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import type { SearchResult } from '../src/core/types.ts';
-import { captureOffPath, OFF_PATH_PAGES, seedOffPath, withCostWave } from './helpers/evidence-delivery-fixture.ts';
+import { dispatchToolCall } from '../src/mcp/dispatch.ts';
+import { __resetProcessNoticeLedgerForTests } from '../src/core/notice-ledger.ts';
+import { captureOffPath, offPathMcpBytes, OFF_PATH_PAGES, seedOffPath, withCostWave } from './helpers/evidence-delivery-fixture.ts';
+import { withEnv } from './helpers/with-env.ts';
const FIXTURE = join(import.meta.dir, 'fixtures/goldens/evidence-delivery/off-path.json');
const CONVERSATION = 'chat/session-a';
@@ -103,4 +106,13 @@ describe('evidence delivery off path', () => {
}
expect(expanded).toBeGreaterThan(0);
});
+
+ test('a once-per-process notice landing on recall leaves the frozen recall bytes intact', async () => {
+ const want = JSON.parse(readFileSync(FIXTURE, 'utf8')) as Record<string, string>;
+ __resetProcessNoticeLedgerForTests();
+ const res = await withChunkConfig(engine, () => withEnv({ GBRAIN_BACKUP_CHECK: '0' }, () =>
+ dispatchToolCall(engine, 'recall', { query: 'ocelot' }, { remote: true, transport: 'stdio', sourceId: 'default' })));
+ expect(res._meta?.gbrain_notices).toBeDefined();
+ expect(offPathMcpBytes(res)).toBe(withCostWave('mcp-recall', want['mcp-recall']));
+ });
});
diff --git a/test/helpers/evidence-delivery-fixture.ts b/test/helpers/evidence-delivery-fixture.ts
index 163291ee32..55c10b5ca9 100644
--- a/test/helpers/evidence-delivery-fixture.ts
+++ b/test/helpers/evidence-delivery-fixture.ts
@@ -64,9 +64,7 @@ export async function captureOffPath(engine: BrainEngine): Promise<Record<string
{ remote: true, transport: 'stdio', sourceId: 'default' });
// Agent contract v1 notices (extra prefixed blocks + _meta.gbrain_notices, e.g. degraded_recall on this
// keyless corpus) are additive and pinned in test/mcp-notice-channels.test.ts; the off path compares the rest.
- const content = res.content.filter(c => !c.text.startsWith('[gbrain notice '));
- const { gbrain_notices: _notices, ...meta } = res._meta ?? {};
- out[`mcp-${name}`] = JSON.stringify({ ...res, content, ...(res._meta ? { _meta: meta } : {}) });
+ out[`mcp-${name}`] = offPathMcpBytes(res);
}
});
const prompts: string[] = [];
@@ -81,6 +79,19 @@ export async function captureOffPath(engine: BrainEngine): Promise<Record<string
return out;
}
+/**
+ * One MCP result as the off path compares it: notice blocks and
+ * `_meta.gbrain_notices` removed. Which call carries a once-per-process
+ * notice depends on what ran earlier in the process (dedupe ledger, queued
+ * hop and drain notices), so a `_meta` holding only notices is dropped
+ * rather than left as `{}`.
+ */
+export function offPathMcpBytes(res: { content: { type: string; text: string }[]; _meta?: Record<string, unknown> }): string {
+ const content = res.content.filter(c => !c.text.startsWith('[gbrain notice '));
+ const { gbrain_notices: _notices, ...meta } = res._meta ?? {};
+ return JSON.stringify({ ...res, content, ...(res._meta ? { _meta: Object.keys(meta).length > 0 ? meta : undefined } : {}) });
+}
+
const leanRetrieval = (meta: Record<string, unknown>) => ({ ...meta, rows: 'lean' });
/**