Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(access): privacyClass judges Git placement by privacy alone (GBRA-218)

garrytan5a6a4c8c87f9
diff --git a/src/core/persistence/git-declared.ts b/src/core/persistence/git-declared.ts
index d7daad9d60..04a57cd481 100644
--- a/src/core/persistence/git-declared.ts
+++ b/src/core/persistence/git-declared.ts
@@ -29,7 +29,7 @@ import { gitChildEnv } from '../git-env.ts';
import type { Action } from '../agent-output.ts';
import { opError, type OperationError } from '../ops/contract.ts';
import { execFile } from '../spawn.ts';
-import { isDerivationPrivate, isPrivatePage, privatePagesFilterFragment, readHonorAliases } from '../search/private-visibility.ts';
+import { isDerivationPrivate, isPrivatePage, privacyPartSql, readHonorAliases } from '../search/private-visibility.ts';
import { DERIVE_PHASE_DB_ONLY_DEFAULTS } from '../storage-config.ts';
import type { PageSnapshot } from '../page-state/types.ts';
import type { PageMutationFile } from './coordinator.ts';
@@ -74,8 +74,9 @@ export function declaredPathClass(root: string, slug: string, page: { source_pat
/**
* Why a page is private, or null: its own fields (`visibility`, a pinned question, the derived-type default), a privacy
- * alias (with `visibility.honor_aliases` read first), or its declared lineage and derived origin, read with the same SQL
- * remote reads use (`privatePagesFilterFragment`) over the page's own values, so an unwritten page is judged too.
+ * alias (with `visibility.honor_aliases` read first), or its declared lineage and derived origin, read with the privacy
+ * part of the SQL remote reads use (`privacyPartSql`) over the page's own values, so an unwritten page is judged too.
+ * Member and folder access do not decide where a page lives, so they are not read here.
*/
export async function privacyClass(engine: BrainEngine, sourceId: string, page: { id?: number | null; slug: string; type?: string | null; frontmatter?: unknown }): Promise<PrivacyClass | null> {
await readHonorAliases(engine);
@@ -83,7 +84,7 @@ export async function privacyClass(engine: BrainEngine, sourceId: string, page:
if (isDerivationPrivate(page)) return 'alias_private';
const frontmatter = typeof page.frontmatter === 'object' && page.frontmatter !== null ? page.frontmatter as Record<string, unknown> : {};
if (frontmatter.derived_from == null && !['atom', 'concept', 'event'].includes(page.type ?? '')) return null;
- const [row] = await engine.executeRaw<{ lineage: boolean }>(`SELECT NOT ${privatePagesFilterFragment('p')} AS lineage
+ const [row] = await engine.executeRaw<{ lineage: boolean }>(`SELECT NOT ${privacyPartSql('p')} AS lineage
FROM (SELECT $1::text AS source_id, $2::text AS slug, $3::text AS type, $4::text::jsonb AS frontmatter, $5::bigint AS id) p`,
[sourceId, page.slug, page.type ?? null, JSON.stringify(frontmatter), page.id ?? null]);
return row?.lineage === true ? 'lineage_private' : null;
diff --git a/src/core/persistence/git-gap.ts b/src/core/persistence/git-gap.ts
index 3dce854b58..cf853d447f 100644
--- a/src/core/persistence/git-gap.ts
+++ b/src/core/persistence/git-gap.ts
@@ -38,7 +38,7 @@ export interface GitHomePolicy { mirror: boolean; databaseOnlySource?: boolean;
* private and alias-private pages never reach a remote; a page the database keeps on purpose (`database_only_reason`) or
* under a `storage.db_only` prefix stays there; a derive-phase page that never recorded a file (page-prepare.ts
* `isNeverFiledDerivedPage`, DERIVE_PHASE_DB_ONLY_DEFAULTS) publishes database-only; a path the checkout's Git ignores
- * can never be committed. `lineage_private` is what privatePagesFilterFragment adds over the row's own fields; the caller
+ * can never be committed. `lineage_private` is what privacyPartSql adds over the row's own fields; the caller
* computes it in SQL. Callers load `visibility.honor_aliases` (readHonorAliases) first.
*/
export function declaredDatabaseOnly(page: { slug: string; type?: string | null; frontmatter?: unknown; database_only_reason?: string | null;
diff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.ts
index fd5083ae84..bf4020acfe 100644
--- a/src/core/search/private-visibility.ts
+++ b/src/core/search/private-visibility.ts
@@ -51,7 +51,7 @@ export function privatePagesFilterFragment(pageAlias: string): string {
}
/** The privacy rules alone (visibility, aliases, pinned questions, lineage): what the escape hatches and granted_sources may relax. */
-function privacyPartSql(pageAlias: string): string {
+export function privacyPartSql(pageAlias: string): string {
return `(${privateSnapshotFilterFragment(pageAlias)}
AND NOT ${derivedOriginPrivateSql(pageAlias)}
AND NOT ${declaredLineagePrivateSql(pageAlias)})`;
diff --git a/test/access-git-declared-class.test.ts b/test/access-git-declared-class.test.ts
new file mode 100644
index 0000000000..9d5bf8a458
--- /dev/null
+++ b/test/access-git-declared-class.test.ts
@@ -0,0 +1,32 @@
+/**
+ * GBRA-218: member access never decides whether a page lives in Git.
+ * privacyClass judges an unwritten page with the privacy part of the remote
+ * read filter over a synthetic row, which has no access columns; the full
+ * filter (readers and lineage) made it throw for every derived page.
+ * Repo-less PGLite.
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { importFromContent } from '../src/core/import-file.ts';
+import { privacyClass } from '../src/core/persistence/git-declared.ts';
+
+const SRC = 'git-class';
+let engine: PGLiteEngine;
+
+describe('privacyClass ignores member access (pglite, repo-less)', () => {
+ beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({ engine: 'pglite' } as never);
+ await engine.initSchema();
+ await engine.executeRaw('INSERT INTO sources (id, name) VALUES ($1, $1)', [SRC]);
+ await importFromContent(engine, 'notes/secret-origin', '---\ntype: note\ntitle: Origin\nvisibility: private\n---\nPrivate origin.', { sourceId: SRC, noEmbed: true });
+ await importFromContent(engine, 'notes/readers-origin', '---\ntype: note\ntitle: Readers\nreadable_by: [alice-example]\n---\nRestricted origin.', { sourceId: SRC, noEmbed: true });
+ }, 120_000);
+ afterAll(async () => { await engine.disconnect(); });
+
+ test('a derived page is judged without throwing, by privacy alone', async () => {
+ expect(await privacyClass(engine, SRC, { slug: 'concepts/roadmap', type: 'concept', frontmatter: {} })).toBeNull();
+ expect(await privacyClass(engine, SRC, { slug: 'notes/summary', type: 'note', frontmatter: { derived_from: ['notes/secret-origin'] } })).toBe('lineage_private');
+ expect(await privacyClass(engine, SRC, { slug: 'notes/summary-2', type: 'note', frontmatter: { derived_from: ['notes/readers-origin'] } })).toBeNull();
+ }, 60_000);
+});