Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(connectors): honor declared database-only prefixes
garrytancca3467436c4
diff --git a/src/core/github-source.ts b/src/core/github-source.tsindex 20b476321f..b3b53c8016 100644--- a/src/core/github-source.ts+++ b/src/core/github-source.ts@@ -52,6 +52,7 @@ import { replaceableFile } from './facts/file-body-guard.ts';import { assertInlineBody } from './page-body/page-shape.ts';import { OperationError } from './ops/contract.ts';import { isWriteThroughDisabled } from './write-through.ts';+import { isSourceDbOnlySlug } from './persistence/source-storage.ts';// ── Types ────────────────────────────────────────────────────────────────────@@ -972,7 +973,7 @@ async function materializePage(deps: GitHubSyncDeps, filePath: string, content:const slug = slugifyPath(rel);const existing = await deps.engine.getPage(slug, { sourceId: deps.sourceId });if (existing) assertInlineBody(existing, 'GitHub connector materialization');- const databaseOnly = await isWriteThroughDisabled(deps.engine);+ const databaseOnly = await isWriteThroughDisabled(deps.engine) || isSourceDbOnlySlug(deps.cfg.dir, slug, 'refuse');if (databaseOnly) return { ...await importPage(deps, filePath, activePack, rel, content), created: !existing };const guard = await replaceableFile(deps.engine, deps.sourceId, slug, filePath);const drift = () => new OperationError('file_database_drift',@@ -993,8 +994,10 @@ async function materializePage(deps: GitHubSyncDeps, filePath: string, content:}async function storedPage(deps: GitHubSyncDeps, filePath: string, apiUpdatedAt: string) {- if (!deps.managed && !await isWriteThroughDisabled(deps.engine)) return { fresh: isPageFresh(filePath, apiUpdatedAt), hasDetail: pageHasDetail(filePath), exists: existsSync(filePath) };const slug = relative(deps.cfg.dir, filePath).replace(/\\/g, '/').replace(/\.md$/, '');+ if (!deps.managed && !await isWriteThroughDisabled(deps.engine) && !isSourceDbOnlySlug(deps.cfg.dir, slugifyPath(slug), 'refuse')) {+ return { fresh: isPageFresh(filePath, apiUpdatedAt), hasDetail: pageHasDetail(filePath), exists: existsSync(filePath) };+ }const page = deps.managed ? await deps.managed.page(slug) : await deps.engine.getPage(slugifyPath(slug), { sourceId: deps.sourceId });return { exists: !!page, fresh: typeof page?.frontmatter.updated_at === 'string' && page.frontmatter.updated_at >= apiUpdatedAt,hasDetail: !!page && page.frontmatter.detail_fetched !== false };diff --git a/src/core/google/sweep-shared.ts b/src/core/google/sweep-shared.tsindex 13025e4a67..12281cbd77 100644--- a/src/core/google/sweep-shared.ts+++ b/src/core/google/sweep-shared.ts@@ -18,6 +18,7 @@ import { assertInlineBody } from '../page-body/page-shape.ts';import { OperationError } from '../ops/contract.ts';import { slugifyPath } from '../sync.ts';import { isWriteThroughDisabled } from '../write-through.ts';+import { isSourceDbOnlySlug } from '../persistence/source-storage.ts';import type { GoogleSourceConfig, GoogleSourceState } from './types.ts';import type { LoopsExclusionPolicy } from './loops-exclusion.ts';@@ -143,7 +144,7 @@ export async function importRendered(const slug = slugifyPath(relPath);const existing = await deps.engine.getPage(slug, { sourceId: deps.sourceId });if (existing) assertInlineBody(existing, 'Google connector materialization');- const databaseOnly = await isWriteThroughDisabled(deps.engine);+ const databaseOnly = await isWriteThroughDisabled(deps.engine) || isSourceDbOnlySlug(deps.cfg.dir, slug, 'refuse');const guard = databaseOnly ? null : await replaceableFile(deps.engine, deps.sourceId, slug, filePath);const drift = () => new OperationError('file_database_drift',`${slug}: the checkout file has an edit not retained in the database, or changed during import. The file was not replaced. If the file is newer, run gbrain sync --source ${deps.sourceId}; if the database is newer, re-save its page with write-through on; if both changed, ask the user which version to keep before retrying.`,diff --git a/test/pathological/d16-google-file-replacement.test.ts b/test/pathological/d16-google-file-replacement.test.tsindex 96fc47cab3..9ec573dd4f 100644--- a/test/pathological/d16-google-file-replacement.test.ts+++ b/test/pathological/d16-google-file-replacement.test.ts@@ -3,9 +3,10 @@* Protects: unmanaged Google materialization preserves checkout-only* edits, including an edit after the replacement comparison, while healthy* contacts still import. A stale file held in page_versions is replaceable;- * write-through off imports only to the database, and segmented pages are held.+ * write-through off or a declared db_only prefix imports only to the database,+ * and segmented pages are held.* Fails when: unconditional temp-import-rename destroys an unimported file edit- * and ignores sync.write_through. Existing materialization tests cover upstream+ * and ignores sync.write_through or storage.db_only. Existing materialization tests cover upstream* changes and import failures, not divergent copies or a late editor write.* Seams: no production seam; real importer and engines, fake Google HTTP, an engine* proxy edits the file when the import transaction starts after temp creation.@@ -177,6 +178,27 @@ for (const { backend, databaseUrl } of pathologicalArms()) {});}, 180_000);+ for (const divergent of [false, true]) {+ test(`declared db_only prefix: ${divergent ? 'divergent' : 'agreeing'} file stays exact and absent sibling stays absent`, async () => {+ await withSource(databaseUrl, async b => {+ writeFileSync(join(b.root, 'gbrain.yml'), 'storage:\n db_only:\n - people/\n');+ const file = b.file() + (divergent ? EDIT : '');+ writeFileSync(b.path, file);+ const old = await b.body();+ const sibling = await b.body(GOOD);+ const goodPath = join(b.root, `${GOOD}.md`);+ rmSync(goodPath);+ const result = await expectUnitNotAborted(() => b.sync());+ expect({ file: b.file(), siblingFile: existsSync(goodPath), body: await b.body(), sibling: await b.body(GOOD) })+ .toEqual({ file, siblingFile: false, body: old.replace('Upstream 0', 'Upstream 1'), sibling: sibling.replace('Upstream 0', 'Upstream 1') });+ expect(result.failedFiles ?? 0).toBe(0);+ expect(await b.versions(old)).toBeGreaterThan(0);+ expect(existsSync(`${b.path}.tmp`)).toBe(false);+ expect(existsSync(`${goodPath}.tmp`)).toBe(false);+ });+ }, 180_000);+ }+test('segmented pages hold without changing either copy; agreeing inline controls import', async () => {await withSource(databaseUrl, async b => {const original = await b.body();diff --git a/test/pathological/d17-github-file-replacement.test.ts b/test/pathological/d17-github-file-replacement.test.tsindex 720a0873f2..4aa7aebe7a 100644--- a/test/pathological/d17-github-file-replacement.test.ts+++ b/test/pathological/d17-github-file-replacement.test.ts@@ -3,9 +3,10 @@* Protects: unmanaged GitHub materialization preserves checkout-only* edits, including an edit after the replacement comparison, while healthy* items still import. A stale file held in page_versions is replaceable;- * write-through off imports only to the database, and segmented pages are held.+ * write-through off or a declared db_only prefix imports only to the database,+ * and segmented pages are held.* Fails when: unconditional temp-import-rename destroys an unimported file edit- * and ignores sync.write_through. Existing materialization tests cover upstream+ * and ignores sync.write_through or storage.db_only. Existing materialization tests cover upstream* changes and import failures, not divergent copies or a late editor write.* Seams: no production seam; real importer and engines, fake GitHub HTTP, an engine* proxy edits the file when the import transaction starts after temp creation.@@ -181,6 +182,27 @@ for (const { backend, databaseUrl } of pathologicalArms()) {});}, 180_000);+ for (const divergent of [false, true]) {+ test(`declared db_only prefix: ${divergent ? 'divergent future-dated' : 'agreeing'} file stays exact and absent sibling stays absent`, async () => {+ await withSource(databaseUrl, async b => {+ writeFileSync(join(b.root, 'gbrain.yml'), 'storage:\n db_only:\n - gh/\n');+ const file = divergent ? b.file().replace(/updated_at: "[^"]+"/, 'updated_at: "2099-01-01T00:00:00Z"') + EDIT : b.file();+ writeFileSync(b.path, file);+ const old = await b.body();+ const sibling = await b.body(GOOD);+ const goodPath = join(b.root, `${GOOD}.md`);+ rmSync(goodPath);+ const result = await expectUnitNotAborted(() => b.sync());+ expect({ file: b.file(), siblingFile: existsSync(goodPath), body: await b.body(), sibling: await b.body(GOOD) })+ .toEqual({ file, siblingFile: false, body: old.replace('Upstream 0', 'Upstream 1'), sibling: sibling.replace('Upstream 0', 'Upstream 1') });+ expect(result.failedFiles ?? 0).toBe(0);+ expect(await b.versions(old)).toBeGreaterThan(0);+ expect(existsSync(`${b.path}.tmp`)).toBe(false);+ expect(existsSync(`${goodPath}.tmp`)).toBe(false);+ });+ }, 180_000);+ }+test('segmented pages hold without changing either copy; agreeing inline controls import', async () => {await withSource(databaseUrl, async b => {const original = await b.body();