Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(facts): the embedding-contract replays wait under the product's publish deadline, not the 250 ms probe override

garrytan70234510bbaa
diff --git a/test/helpers/managed-facts-embedding-contract.ts b/test/helpers/managed-facts-embedding-contract.ts
index d29a634bf0..cff82247f7 100644
--- a/test/helpers/managed-facts-embedding-contract.ts
+++ b/test/helpers/managed-facts-embedding-contract.ts
@@ -89,6 +89,11 @@ export async function exerciseManagedEmbedding(engine: BrainEngine, scenario: Ca
const failure = ['invalid_policy', 'invalid_model', 'invalid_dimensions', 'changed_before_embedding', 'disabled_before_embedding', 'changed_after_embedding', 'cancelled'].includes(scenario);
if (deferred) {
await expect(run()).rejects.toMatchObject({ code: 'write_pending' });
+ // The short wait exists only so this first call reports write_pending fast. Every replay below is the thing
+ // under test (the retained batch committing once the worktree is active again) and waits under the product's
+ // own MAINTENANCE_PUBLISH_WAIT_MS: a cold replay takes 210-370 ms, so the 250 ms override made it a coin flip
+ // (F2, `unchanged_replay` → write_pending under shard load). The outer finally still covers the throw path.
+ restoreWait(); restoreWait = () => {};
await disposePersistenceConsumer(engine);
await engine.executeRaw("UPDATE persistence_worktrees SET state='active' WHERE id=$1::uuid", [binding.worktree_id]);
if (scenario === 'changed_before_publication') {
@@ -105,12 +110,16 @@ export async function exerciseManagedEmbedding(engine: BrainEngine, scenario: Ca
if (scenario === 'unsigned_replay') await engine.executeRaw("UPDATE persistence_requests SET intent=intent-'embedding' WHERE source_id=$1 AND intent->>'kind'='managed_facts_entity'", [sourceId]);
else if (scenario === 'file_disabled_before_replay') config.embedding_disabled = true;
else await engine.setConfig(scenario === 'disabled_before_replay' ? 'embedding_disabled' : 'embedding_model', scenario === 'disabled_before_replay' ? 'true' : hostModel);
- await expect(run()).rejects.toBeDefined();
- const beforeReceipt = await engine.executeRaw('SELECT state,error_code,outcome FROM persistence_requests WHERE source_id=$1 AND slug=$2', [sourceId, slug]);
+ // The typed refusal, not any rejection: a write_pending here would otherwise satisfy both asserts and the
+ // "same receipt twice" comparison below vacuously.
+ await expect(run()).rejects.toMatchObject({ code: 'embedding_configuration' });
+ const beforeReceipt = await engine.executeRaw<{ state: string; error_code: string | null }>('SELECT state,error_code,outcome FROM persistence_requests WHERE source_id=$1 AND slug=$2', [sourceId, slug]);
+ expect(beforeReceipt).toHaveLength(1);
+ expect(beforeReceipt[0].state).toBe('failed');
await engine.setConfig('embedding_model', selectedModel);
await engine.setConfig('embedding_disabled', 'false');
config.embedding_disabled = false;
- await expect(run()).rejects.toBeDefined();
+ await expect(run()).rejects.toMatchObject({ code: 'embedding_configuration' });
expect(await engine.executeRaw('SELECT state,error_code,outcome FROM persistence_requests WHERE source_id=$1 AND slug=$2', [sourceId, slug])).toEqual(beforeReceipt);
}
expect(generations).toBe(1);