Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(storage): scope status pages to repo source (#4763) (#4802)
Javier Aldape8c70f6255047
diff --git a/src/commands/storage.ts b/src/commands/storage.tsindex ba3494e905..162c16da82 100644--- a/src/commands/storage.ts+++ b/src/commands/storage.ts@@ -3,7 +3,7 @@ import type { BrainEngine } from '../core/engine.ts';import { loadStorageConfig, validateStorageConfig, getStorageTier } from '../core/storage-config.ts';import type { StorageConfig, StorageTier } from '../core/storage-config.ts';import { walkBrainRepo, type DiskFileEntry } from '../core/disk-walk.ts';-import { getDefaultSourcePath } from '../core/source-resolver.ts';+import { getDefaultSourcePath, resolveSourceForRepoPath } from '../core/source-resolver.ts';/*** Distinct nominal types for the two tier-keyed numeric maps. Both shapes@@ -146,7 +146,11 @@ export async function getStorageStatus(// per directory + one stat per .md file, plus O(1) lookups below.const fileMap: Map<string, DiskFileEntry> = repoPath ? walkBrainRepo(repoPath) : new Map();- const pages = await engine.listPages({ limit: 1_000_000 });+ const source = repoPath ? await resolveSourceForRepoPath(engine, repoPath) : null;+ const pages = await engine.listPages({+ limit: 1_000_000,+ ...(source ? { sourceId: source.source_id } : {}),+ });for (const page of pages) {const tier = config ? getStorageTier(page.slug, config) : 'unspecified';diff --git a/test/storage-pglite.test.ts b/test/storage-pglite.test.tsindex 46656f0b49..8df01e5dcf 100644--- a/test/storage-pglite.test.ts+++ b/test/storage-pglite.test.ts@@ -10,7 +10,7 @@*/import { describe, test, expect, beforeAll, afterAll, beforeEach } from 'bun:test';-import { mkdtempSync, rmSync, writeFileSync, readFileSync, existsSync } from 'fs';+import { mkdtempSync, rmSync, writeFileSync, readFileSync, existsSync, mkdirSync } from 'fs';import { join } from 'path';import { tmpdir } from 'os';import { PGLiteEngine } from '../src/core/pglite-engine.ts';@@ -103,6 +103,44 @@ describe('Storage tiering on PGLite — full lifecycle (D8 + D4)', () => {}});+ test('getStorageStatus scopes page checks to the source that owns the repo path (#4763)', async () => {+ try {+ writeGbrainYml();+ mkdirSync(join(tmp, 'media', 'x'), { recursive: true });+ writeFileSync(join(tmp, 'media', 'x', 'default-db-only.md'), 'file-backed default page');++ const otherRepo = join(tmp, 'other-repo');+ mkdirSync(otherRepo, { recursive: true });+ await engine.executeRaw(`UPDATE sources SET local_path = $1 WHERE id = 'default'`, [tmp]);+ await engine.executeRaw(+ `INSERT INTO sources (id, name, local_path, config)+ VALUES ('media-corpus', 'media-corpus', $1, '{}'::jsonb)+ ON CONFLICT (id) DO UPDATE SET local_path = EXCLUDED.local_path`,+ [otherRepo],+ );++ await engine.putPage('media/x/default-db-only', {+ type: 'concept',+ title: 'Default source page',+ compiled_truth: '',+ timeline: '',+ }, { sourceId: 'default' });+ await engine.putPage('media/x/foreign-db-only', {+ type: 'concept',+ title: 'Foreign source page',+ compiled_truth: '',+ timeline: '',+ }, { sourceId: 'media-corpus' });++ const result = await getStorageStatus(engine, tmp);+ expect(result.totalPages).toBe(1);+ expect(result.pagesByTier.db_only).toBe(1);+ expect(result.missingFiles).toEqual([]);+ } finally {+ cleanup();+ }+ });+test('manageGitignore on PGLite emits the D4 soft-warn (once per process)', () => {try {writeGbrainYml();