Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(facts): pin the keyless gateway in write-single-dedup and recall-question so the keyed nightly lane asserts the right branch (#6040)
garrytan8cbb277f82fe
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 159dc3c6a7..a22f053859 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,15 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [0.60.173.0] - 2026-10-11++**Two memory tests stop failing on the scheduled full E2E run, which keeps real provider keys.** Both asserted the keyless branch (`degraded_dedup: true` on `writeSingleFact`, `facts_degraded.reason: keyword_only_no_embedding_provider` on `recall`) while reading the gateway's key state from the process environment, so the nightly lane, which runs with `GBRAIN_TEST_KEEP_PROVIDER_KEYS=1` and an `OPENAI_API_KEY`, embedded for real and reported the keyed result. No product behaviour changes; both branches are now pinned on every lane.++### Itemized changes++- `test/write-single-dedup.test.ts`: the gateway is configured keyless (`env: {}`) before each test, so a provider key in the environment cannot turn the degraded branch on; a new case installs a stubbed embed transport and asserts the keyed branch (`degraded_dedup: false`, the text embedded once per write, an exact repeat still `duplicate`). Forced probe: `GBRAIN_TEST_KEEP_PROVIDER_KEYS=1 bun test test/write-single-dedup.test.ts` fails on the previous file (1 of 6) and passes now (7 of 7).+- `test/recall-question.test.ts`: the `keyless()` helper configures a keyless gateway instead of resetting it, so the keyword-only ranking assertions hold with provider keys present; the same probe fails before (2 of 54, both engines) and passes after.+## [0.60.172.0] - 2026-10-11**Two decide timing tests stop failing on slow runners.** Each one measured wall-clock time that included work outside the budget under test. Both budgets are unchanged.diff --git a/test/recall-question.test.ts b/test/recall-question.test.tsindex 378ea954c7..c954a49e2b 100644--- a/test/recall-question.test.ts+++ b/test/recall-question.test.ts@@ -78,8 +78,11 @@ for (const kind of testBackends()) {providerCalls = [];}function keyless(): void {+ // Keyless by construction, not by environment: a provider key the lane+ // keeps (the full E2E runs with GBRAIN_TEST_KEEP_PROVIDER_KEYS=1) must+ // not turn the keyword-only branch into a real embed.__setEmbedTransportForTests(null);- resetGateway();+ configureGateway({ embedding_model: 'openai:text-embedding-3-large', embedding_dimensions: dims, env: {} });}async function fact(name: string, f: {@@ -127,7 +130,7 @@ for (const kind of testBackends()) {entity: null, daysAgo: 3, embed: false,});}, 180_000);- afterAll(async () => { keyless(); await close?.(); });+ afterAll(async () => { __setEmbedTransportForTests(null); resetGateway(); await close?.(); });beforeEach(() => { notices = []; __resetPrivateVisibilityCacheForTests(); keyed(); });test('without question: facts stay newest first and facts_order says so', async () => {diff --git a/test/write-single-dedup.test.ts b/test/write-single-dedup.test.tsindex 1c8cf48e8c..ea09869e9a 100644--- a/test/write-single-dedup.test.ts+++ b/test/write-single-dedup.test.ts@@ -13,7 +13,11 @@* already dedups an entity-less repeat.* Fails when: the helper runs cosine-only dedup gated on entity + embedding* (two rows), or writes the slugified fallback as the entity.- * Seams: none. PGLite always, Postgres when DATABASE_URL is set.+ * Seams: the gateway is configured keyless (`env: {}`) so `degraded_dedup:+ * true` is pinned even on lanes that keep real provider keys (the scheduled+ * full E2E runs with `GBRAIN_TEST_KEEP_PROVIDER_KEYS=1`); the keyed branch+ * uses `__setEmbedTransportForTests`. PGLite always, Postgres when+ * DATABASE_URL is set.* Dedup is sequential: the exact check runs before, not inside, the insert* transaction, so two identical submissions racing each other may both insert.*/@@ -21,7 +25,7 @@ import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:tesimport type { BrainEngine } from '../src/core/engine.ts';import { PGLiteEngine } from '../src/core/pglite-engine.ts';import { PostgresEngine } from '../src/core/postgres-engine.ts';-import { resetGateway } from '../src/core/ai/gateway.ts';+import { __setEmbedTransportForTests, configureGateway, resetGateway } from '../src/core/ai/gateway.ts';import { writeSingleFact } from '../src/core/facts/write-single.ts';import { dispatchToolCall } from '../src/mcp/dispatch.ts';import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';@@ -45,7 +49,15 @@ for (const backend of testBackends()) {await engine.initSchema();}, 180_000);+ beforeEach(() => {+ // Keyless by construction: a provider key in the process environment+ // (the full E2E lane keeps them) must not turn the degraded branch on.+ __setEmbedTransportForTests(null);+ configureGateway({ embedding_model: 'openai:text-embedding-3-small', embedding_dimensions: 1536, env: {} });+ });+afterAll(async () => {+ __setEmbedTransportForTests(null);resetGateway();await engine.disconnect();});@@ -76,6 +88,22 @@ for (const backend of testBackends()) {expect(await rows()).toHaveLength(1);});+ test('with an embedding provider the write embeds and reports degraded_dedup: false; an exact repeat is still a duplicate', async () => {+ const embedded: string[] = [];+ configureGateway({ embedding_model: 'openai:text-embedding-3-small', embedding_dimensions: 1536, env: { OPENAI_API_KEY: 'sk-test' } });+ __setEmbedTransportForTests((async ({ values }: { values: string[] }) => {+ embedded.push(...values);+ return { embeddings: values.map(() => [1, ...new Array(1535).fill(0)]) };+ }) as never);+ await engine.putPage('people/alice-example', { type: 'person', title: 'Alice Example', compiled_truth: 'Alice.' }, { sourceId: 'default' });+ const first = await writeSingleFact(engine, 'default', { fact: CLAIM, provenance: 'fixture', entity: 'people/alice-example', remote: false });+ const second = await writeSingleFact(engine, 'default', { fact: CLAIM, provenance: 'fixture', entity: 'people/alice-example', remote: false });+ expect(first).toMatchObject({ status: 'inserted', entity_slug: 'people/alice-example', degraded_dedup: false });+ expect(second).toMatchObject({ status: 'duplicate', id: first.id, degraded_dedup: false });+ expect(embedded).toEqual([CLAIM, CLAIM]);+ expect(await rows()).toHaveLength(1);+ });+test('a different visibility is a different fact', async () => {const a = await writeSingleFact(engine, 'default', { fact: CLAIM, provenance: 'fixture', visibility: 'private', remote: false });const b = await writeSingleFact(engine, 'default', { fact: CLAIM, provenance: 'fixture', visibility: 'world', remote: false });