From d3d2684b114e12d2c38c893f0e8ad161a0ea3bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Tue, 31 Mar 2026 09:25:52 +0200 Subject: [PATCH] fix(openclaw): add warn log and tests for CLI mode no-op in waitForReady (#799) Follow-up to #764. Upgrades the silent debug log in waitForReady to log.warn so unexpected calls before service.start() are visible, and adds tests covering the CLI mode no-op path. --- .../openclaw/src/index.test.ts | 20 +++++++++++++++++++ hindsight-integrations/openclaw/src/index.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hindsight-integrations/openclaw/src/index.test.ts b/hindsight-integrations/openclaw/src/index.test.ts index ee03ecbd..bc75cc19 100644 --- a/hindsight-integrations/openclaw/src/index.test.ts +++ b/hindsight-integrations/openclaw/src/index.test.ts @@ -425,3 +425,23 @@ describe('truncateRecallQuery', () => { expect(truncated.length).toBeLessThanOrEqual(180); }); }); + +// --------------------------------------------------------------------------- +// waitForReady — CLI mode no-op (initPromise is null before service.start()) +// --------------------------------------------------------------------------- + +describe('waitForReady (CLI mode)', () => { + it('returns without error when initPromise is null (service.start not called)', async () => { + // The module sets up global.__hindsightClient on import. + // In test context, service.start() is never called so initPromise remains null. + const hindsight = (global as any).__hindsightClient; + expect(hindsight).toBeDefined(); + // Should resolve without throwing + await expect(hindsight.waitForReady()).resolves.toBeUndefined(); + }); + + it('getClient returns null when service.start not called', () => { + const hindsight = (global as any).__hindsightClient; + expect(hindsight.getClient()).toBeNull(); + }); +}); diff --git a/hindsight-integrations/openclaw/src/index.ts b/hindsight-integrations/openclaw/src/index.ts index aa6dc782..fdbcd43e 100644 --- a/hindsight-integrations/openclaw/src/index.ts +++ b/hindsight-integrations/openclaw/src/index.ts @@ -134,7 +134,7 @@ if (typeof global !== 'undefined') { // If initPromise is null, it means service.start() hasn't been called yet // (CLI mode, not gateway mode). Hooks should gracefully no-op. if (!initPromise) { - debug('[Hindsight] waitForReady called but initPromise is null (gateway not started)'); + log.warn('waitForReady called before service.start() — hooks will no-op (expected in CLI mode)'); return; } try {