Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(evidence): compare off-path bytes only after the query has paid its embedding
garrytan7b8b9dbbdfaf
diff --git a/test/e2e/evidence-long-page.test.ts b/test/e2e/evidence-long-page.test.tsindex e99fd55b1e..f06684a532 100644--- a/test/e2e/evidence-long-page.test.ts+++ b/test/e2e/evidence-long-page.test.ts@@ -17,8 +17,10 @@ import { readFileSync } from 'node:fs';import { join } from 'node:path';import type { PostgresEngine } from '../../src/core/postgres-engine.ts';import type { SearchResult } from '../../src/core/types.ts';+import { __setEmbedTransportForTests, configureGateway, resetGateway } from '../../src/core/ai/gateway.ts';import { assembleEvidenceForHits } from '../../src/core/search/evidence-delivery.ts';import { buildMcpInstructions, readInstructionContent } from '../../src/mcp/instructions.ts';+import { LEGACY_EMBEDDING_CONFIG } from '../helpers/legacy-embedding-config.ts';import { isolatedPersistencePostgres } from '../helpers/persistence-postgres.ts';import { DECIDING, LONG_SLUG, MEDIUM_SLUG, mcpCall, opCall, seedLongPages, withConfig } from '../helpers/long-page-fixture.ts';@@ -39,12 +41,34 @@ afterAll(async () => { await close(); }, 120_000);const long = (rows: Array<Record<string, unknown>>) => rows.find(r => r.slug === LONG_SLUG)!;+async function expectOffPathIsChunk(): Promise<Record<string, unknown>[]> {+ const metas: Record<string, unknown>[] = [];+ for (const [name, params] of [['search', { query: 'renewal fee' }], ['query', { query: 'renewal fee', expand: false }]] as const) {+ await mcpCall(engine, name, params);+ const chunk = await mcpCall(engine, name, { ...params, return_unit: 'chunk' });+ expect((await mcpCall(engine, name, params)).bytes).toBe(chunk.bytes);+ expect((await withConfig(engine, { [KEY]: 'off' }, () => mcpCall(engine, name, params))).bytes).toBe(chunk.bytes);+ metas.push((JSON.parse(chunk.bytes) as { _meta: { retrieval: Record<string, unknown> } })._meta.retrieval);+ }+ return metas;+}+run('long-page delivery on Postgres', () => {test('off (unset or `off`) is byte-identical to return_unit chunk', async () => {- for (const [name, params] of [['search', { query: 'renewal fee' }], ['query', { query: 'renewal fee', expand: false }]] as const) {- const chunk = await mcpCall(engine, name, { ...params, return_unit: 'chunk' });- expect((await mcpCall(engine, name, params)).bytes).toBe(chunk.bytes);- expect((await withConfig(engine, { [KEY]: 'off' }, () => mcpCall(engine, name, params))).bytes).toBe(chunk.bytes);+ await expectOffPathIsChunk();+ });++ test('off is byte-identical to return_unit chunk with an embedding provider configured, where only the first call of a query pays its embedding', async () => {+ configureGateway({ embedding_model: LEGACY_EMBEDDING_CONFIG.embedding_model, embedding_dimensions: LEGACY_EMBEDDING_CONFIG.embedding_dimensions, env: { OPENAI_API_KEY: 'sk-fixture' } });+ __setEmbedTransportForTests((async ({ values }: { values: string[] }) => ({+ embeddings: values.map(() => Array.from({ length: LEGACY_EMBEDDING_CONFIG.embedding_dimensions }, () => 0.1)), values, usage: { tokens: 4 },+ })) as never);+ try {+ const [, query] = await expectOffPathIsChunk();+ expect(query.vector_enabled).toBe(true);+ } finally {+ __setEmbedTransportForTests(null);+ resetGateway();}});