From 1c9ceaffda01e59e80621b0a35b7af1f14a55b18 Mon Sep 17 00:00:00 2001 From: Hiten Shah Date: Sun, 17 May 2026 12:31:53 -0700 Subject: [PATCH] fix(sync): scope auto-embed to source --- src/commands/sync.ts | 16 +++++++--------- test/sync.test.ts | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/commands/sync.ts b/src/commands/sync.ts index b297a434d..4f602dd09 100644 --- a/src/commands/sync.ts +++ b/src/commands/sync.ts @@ -212,6 +212,10 @@ export function buildGitInvocation(repoPath: string, args: string[], configs: st return [...cfg, '-C', repoPath, ...args]; } +export function buildAutoEmbedArgs(slugs: string[], sourceId?: string): string[] { + return sourceId ? ['--source', sourceId, '--slugs', ...slugs] : ['--slugs', ...slugs]; +} + /** * Shell out to git with a generous maxBuffer. * @@ -962,19 +966,13 @@ async function performSyncInner(engine: BrainEngine, opts: SyncOpts): Promise 0 && pagesAffected.length <= 100) { try { const { runEmbed } = await import('./embed.ts'); - await runEmbed(engine, ['--slugs', ...pagesAffected]); + await runEmbed(engine, buildAutoEmbedArgs(pagesAffected, opts.sourceId)); // Before commit 2 lands: runEmbed is void. Best estimate is pagesAffected, // since runEmbed re-embeds every requested slug. Commit 2 sharpens this // with EmbedResult.embedded. diff --git a/test/sync.test.ts b/test/sync.test.ts index a7d0d67cc..7fcc0490c 100644 --- a/test/sync.test.ts +++ b/test/sync.test.ts @@ -1,6 +1,6 @@ import { describe, test, expect, beforeAll, afterAll, beforeEach, afterEach } from 'bun:test'; import { buildSyncManifest, isSyncable, pathToSlug } from '../src/core/sync.ts'; -import { buildGitInvocation } from '../src/commands/sync.ts'; +import { buildAutoEmbedArgs, buildGitInvocation } from '../src/commands/sync.ts'; import { mkdtempSync, writeFileSync, rmSync, mkdirSync } from 'fs'; import { join } from 'path'; import { execSync } from 'child_process'; @@ -560,3 +560,18 @@ describe('git() helper invocation order (CJK wave v0.32.7)', () => { ]); }); }); + +describe('sync auto-embed arguments', () => { + test('scopes incremental source sync embedding to the same source', () => { + expect(buildAutoEmbedArgs(['hello-js'], 'source-a')).toEqual([ + '--source', + 'source-a', + '--slugs', + 'hello-js', + ]); + }); + + test('keeps default-source sync embed arguments unchanged', () => { + expect(buildAutoEmbedArgs(['people/alice'])).toEqual(['--slugs', 'people/alice']); + }); +});