Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(connectors): reject missing source value

masashiono06119e9d35465755
diff --git a/src/commands/connectors/sync.ts b/src/commands/connectors/sync.ts
index db945ec2b7..2b29778a93 100644
--- a/src/commands/connectors/sync.ts
+++ b/src/commands/connectors/sync.ts
@@ -49,6 +49,12 @@ function parseFlags(args: string[]): { provider: string; flags: SyncFlags } {
}
export async function runConnectorSyncCmd(engine: BrainEngine, args: string[]): Promise<void> {
+ if (args.some((arg, i) => arg === '--source' && (!args[i + 1] || args[i + 1].startsWith('-')))) {
+ console.error('Usage: gbrain connectors sync <chatgpt|claude>|--all [--full] [--dry-run] [--limit N] [--source id]');
+ setCliExitVerdict(1);
+ return;
+ }
+
const { provider, flags } = parseFlags(args);
// Resolve the target provider set.
diff --git a/test/connectors-sync-cli.test.ts b/test/connectors-sync-cli.test.ts
new file mode 100644
index 0000000000..ba59f6cc35
--- /dev/null
+++ b/test/connectors-sync-cli.test.ts
@@ -0,0 +1,44 @@
+import { afterEach, describe, expect, test } from 'bun:test';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { runConnectorSyncCmd } from '../src/commands/connectors/sync.ts';
+import { _resetCliExitVerdictForTests, currentExitCode } from '../src/core/cli-force-exit.ts';
+import { withEnv } from './helpers/with-env.ts';
+
+const tempHomes: string[] = [];
+
+afterEach(() => {
+ for (const home of tempHomes.splice(0)) rmSync(home, { recursive: true, force: true });
+ _resetCliExitVerdictForTests();
+ process.exitCode = 0;
+});
+
+describe('connectors sync --source CLI validation', () => {
+ for (const args of [
+ ['claude', '--source'],
+ ['claude', '--source', '--dry-run'],
+ ]) {
+ test(`rejects a missing source value: ${args.join(' ')}`, async () => {
+ const home = mkdtempSync(join(tmpdir(), 'gbrain-connectors-sync-cli-'));
+ tempHomes.push(home);
+ await withEnv({
+ GBRAIN_HOME: home,
+ GBRAIN_CONNECTOR_CLAUDE_COOKIE: undefined,
+ GBRAIN_CONNECTOR_CLAUDE_TOKEN: undefined,
+ }, async () => {
+ const errors: string[] = [];
+ const originalError = console.error;
+ console.error = (...values: unknown[]) => errors.push(values.join(' '));
+ try {
+ await runConnectorSyncCmd({ getConfig: async () => 'configured-source' } as never, args);
+ } finally {
+ console.error = originalError;
+ }
+
+ expect(errors.join('\n')).toContain('Usage: gbrain connectors sync');
+ expect(currentExitCode()).toBe(1);
+ });
+ });
+ }
+});