Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(search): compare retrieval meta without the per-call timings

garrytan22ddac286cad
diff --git a/test/evidence-delivery.test.ts b/test/evidence-delivery.test.ts
index c684349373..50d96809ca 100644
--- a/test/evidence-delivery.test.ts
+++ b/test/evidence-delivery.test.ts
@@ -808,6 +808,13 @@ afterAll(async () => {
await engine.disconnect();
}, 240_000);
+/** The retrieval meta with its per-call stage timings removed (they differ on every call; present on every one). */
+function sansTimings(meta: Record<string, any> | null): Record<string, any> {
+ const { timings, ...rest } = meta ?? {};
+ expect(timings?.total_ms).toBeGreaterThanOrEqual(0);
+ return rest;
+}
+
describe('ops', () => {
test('omitted return_unit with no conversation hit is exactly the chunk response', async () => {
lastMeta = null;
@@ -819,7 +826,7 @@ describe('ops', () => {
const offMeta = lastMeta;
const chunk = await op('search').handler(ctxOf(), { query: 'pricing', return_unit: 'chunk' }) as SearchResult[];
expect(JSON.stringify(rows)).toBe(JSON.stringify(chunk));
- expect(JSON.stringify(offMeta)).toBe(JSON.stringify(lastMeta));
+ expect(JSON.stringify(sansTimings(offMeta))).toBe(JSON.stringify(sansTimings(lastMeta)));
});
test('omitted return_unit delivers conversation pages whole and keeps other hits as their chunks', async () => {
@@ -1146,9 +1153,9 @@ describe('ops', () => {
test('search.auto_packing selects the packing; the library override wins per call; neither touches a call without a budget', async () => {
const baseline = async () => {
const out: string[] = [];
- out.push(JSON.stringify(await op('search').handler(ctxOf(), { query: 'narwhal' })), JSON.stringify(lastMeta));
- out.push(JSON.stringify(await op('query').handler(ctxOf(), { query: 'narwhal', expand: false })), JSON.stringify(lastMeta));
- out.push(JSON.stringify(await op('query').handler(ctxOf(), { query: 'narwhal', return_unit: 'auto', expand: false })), JSON.stringify(lastMeta));
+ out.push(JSON.stringify(await op('search').handler(ctxOf(), { query: 'narwhal' })), JSON.stringify(sansTimings(lastMeta)));
+ out.push(JSON.stringify(await op('query').handler(ctxOf(), { query: 'narwhal', expand: false })), JSON.stringify(sansTimings(lastMeta)));
+ out.push(JSON.stringify(await op('query').handler(ctxOf(), { query: 'narwhal', return_unit: 'auto', expand: false })), JSON.stringify(sansTimings(lastMeta)));
out.push(JSON.stringify(await op('recall').handler(ctxOf(), { query: 'narwhal' })));
const hits = await op('search').handler(ctxOf(), { query: 'narwhal', return_unit: 'chunk' }) as SearchResult[];
out.push(JSON.stringify(await op('assemble_evidence').handler(ctxOf(), { hits: hits.map(h => ({ source_id: h.source_id, slug: h.slug, chunk_id: h.chunk_id })), return_unit: 'auto' })));
diff --git a/test/helpers/evidence-delivery-fixture.ts b/test/helpers/evidence-delivery-fixture.ts
index de7d111064..d9e0033fcf 100644
--- a/test/helpers/evidence-delivery-fixture.ts
+++ b/test/helpers/evidence-delivery-fixture.ts
@@ -28,10 +28,20 @@ export const OFF_PATH_PAGES: Array<{ slug: string; body: string; timeline?: stri
{ slug: 'notes/short', body: 'A short ocelot note.' },
];
+/**
+ * Per-call stage timings (`retrieval.timings`) are additive and differ on every call; they are pinned in
+ * test/search/stage-timings-ops.test.ts, and the off path compares the rest.
+ */
+function withoutTimings(value: unknown): unknown {
+ if (value === null || typeof value !== 'object' || !('timings' in value)) return value;
+ const { timings: _timings, ...rest } = value as Record<string, unknown>;
+ return rest;
+}
+
function ctxOf(engine: BrainEngine, meta: Record<string, unknown>[], overrides: Partial<OperationContext> = {}): OperationContext {
return {
engine: engine as never, config: {} as never, logger: console as never, dryRun: false, remote: false, sourceId: 'default',
- emitResponseMeta: (key: string, value: unknown) => { meta.push({ key, value }); },
+ emitResponseMeta: (key: string, value: unknown) => { meta.push({ key, value: key === 'retrieval' ? withoutTimings(value) : value }); },
...overrides,
} as OperationContext;
}
@@ -89,6 +99,7 @@ export async function captureOffPath(engine: BrainEngine): Promise<Record<string
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 ?? {};
+ if (meta.retrieval) meta.retrieval = withoutTimings(meta.retrieval);
return JSON.stringify({ ...res, content, ...(res._meta ? { _meta: Object.keys(meta).length > 0 ? meta : undefined } : {}) });
}
diff --git a/test/search-c5-identical.test.ts b/test/search-c5-identical.test.ts
index 878f50fcdd..5574653553 100644
--- a/test/search-c5-identical.test.ts
+++ b/test/search-c5-identical.test.ts
@@ -68,7 +68,10 @@ async function capture(engine: PGLiteEngine): Promise<Record<string, unknown>> {
const out: Record<string, unknown> = {};
for (const [name, args] of CALLS) {
const res = await withEnv({ GBRAIN_BACKUP_CHECK: '0' }, () => dispatchToolCall(engine, name, args, REMOTE));
- out[`${name} ${args.query}`] = { content: res.content.map(c => c.text), retrieval: res._meta?.retrieval };
+ // Per-call stage timings vary run to run (pinned in test/search/stage-timings-ops.test.ts); the rest is compared.
+ const { timings, ...retrieval } = (res._meta?.retrieval ?? {}) as Record<string, unknown>;
+ expect(timings).toBeDefined();
+ out[`${name} ${args.query}`] = { content: res.content.map(c => c.text), retrieval };
}
return out;
}