Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(sources): managed google source add keeps contacts-dir, future-days and loops-exclude-labels (#6717)
garrytan7417edc3264b
diff --git a/src/core/persistence/managed-sources.ts b/src/core/persistence/managed-sources.tsindex d7dafbc2ab..a75c321323 100644--- a/src/core/persistence/managed-sources.ts+++ b/src/core/persistence/managed-sources.ts@@ -4,7 +4,7 @@ import type { BrainEngine } from '../engine.ts';import { OperationError } from '../ops/contract.ts';import { msysToNativePath } from '../path-confine.ts';import { defaultCloneDir, type AddSourceOpts, type SourceRow } from '../sources-ops.ts';-import { DEFAULT_CALENDAR_ID } from '../google/types.ts';+import { googleTuningConfig } from '../google/source-config.ts';import { runManagedSourceLifecycle, type SourceLifecycleInput } from './source-lifecycle.ts';import { isValidSourceId } from '../source-id.ts';import { WRITE_ERROR_CODES, type WriteErrorCode } from './types.ts';@@ -41,7 +41,7 @@ export function managedSourceAddInput(opts:AddSourceOpts):SourceLifecycleInput{if(opts.google){const google=opts.google;path=resolve(msysToNativePath(google.dir));config={kind:'google',g_account:google.account,g_services:google.services.join(','),g_history_days:google.historyDays,- ...(google.calendarId&&google.calendarId!==DEFAULT_CALENDAR_ID?{g_calendar_id:google.calendarId}:{}),+ ...googleTuningConfig(google),...(google.access&&google.access!=='vault'?{g_access:google.access}:{}),...(google.tokenCommand?{g_token_command:google.tokenCommand}:{}),...(google.tokenEnv?{g_token_env:google.tokenEnv}:{}),g_managed:path===defaultCloneDir(`${opts.id}-google`),federated:opts.federated??true};}diff --git a/test/managed-sources-google-tuning-6717.test.ts b/test/managed-sources-google-tuning-6717.test.tsnew file mode 100644index 0000000000..49a8b1625f--- /dev/null+++ b/test/managed-sources-google-tuning-6717.test.ts@@ -0,0 +1,52 @@+/**+ * #6717: managed `sources add --kind google` keeps the per-source tuning flags+ * (--contacts-dir, --future-days, --loops-exclude-labels, --calendar-id). The+ * managed intent builder writes the same google config as the legacy+ * (unmanaged) add path, which serializes them through googleTuningConfig.+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { mkdtempSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { managedSourceAddInput } from '../src/core/persistence/managed-sources.ts';+import { googleTuningConfig } from '../src/core/google/source-config.ts';+import { addSource, type AddSourceOpts } from '../src/core/sources-ops.ts';+import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';++let engine: PGLiteEngine;+beforeAll(async () => {+ engine = new PGLiteEngine();+ await engine.connect({});+ await engine.initSchema();+ await engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1');+});+afterAll(async () => { await disposePersistenceConsumer(engine); await engine.disconnect(); });++const tuning = { calendarId: '[email protected]', contactsDir: 'contacts', futureDays: 30, loopsExcludeLabels: ['a', 'b'] };+const googleOpts = (id: string, dir: string): AddSourceOpts => ({+ id,+ google: { account: '[email protected]', services: ['contacts', 'calendar'], historyDays: 90, dir,+ access: 'command', tokenCommand: 'example-token-command', ...tuning },+} as AddSourceOpts);++describe('managed google source add keeps the tuning config (#6717)', () => {+ test('managedSourceAddInput writes every googleTuningConfig key', () => {+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-6717-'));+ const { config } = managedSourceAddInput(googleOpts('g-managed', dir));+ expect(googleTuningConfig(tuning)).toEqual({ g_calendar_id: '[email protected]', g_contacts_dir: 'contacts', g_future_days: 30, g_loops_exclude_labels: 'a,b' });+ expect(config).toEqual({+ kind: 'google', g_account: '[email protected]', g_services: 'contacts,calendar', g_history_days: 90,+ ...googleTuningConfig(tuning),+ g_access: 'command', g_token_command: 'example-token-command', g_managed: false, federated: true,+ });+ });++ test('the managed intent config equals what the legacy add path stores', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-6717-legacy-'));+ await addSource(engine, googleOpts('g-legacy', dir));+ const [row] = await engine.executeRaw<{ config: unknown }>(`SELECT config FROM sources WHERE id = 'g-legacy'`);+ const stored = typeof row!.config === 'string' ? JSON.parse(row!.config) : row!.config;+ expect(managedSourceAddInput(googleOpts('g-legacy', dir)).config).toEqual(stored as Record<string, unknown>);+ });+});