Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Owner opt-in: member-page lineage follows that page rules; versions keep the member-page exception; --as lineage on reads only

garrytan8aaa65b0e318
diff --git a/src/cli/as-preview.ts b/src/cli/as-preview.ts
index 775f2c1275..f5eeac1ab1 100644
--- a/src/cli/as-preview.ts
+++ b/src/cli/as-preview.ts
@@ -31,7 +31,7 @@ export interface AsPreview {
const PASSTHROUGH: AsPreview = { run: fn => fn(), context: ctx => ctx };
-export async function openAsPreview(engine: BrainEngine, member: string | undefined, command: string): Promise<AsPreview> {
+export async function openAsPreview(engine: BrainEngine, member: string | undefined, command: string, readOnly = false): Promise<AsPreview> {
if (member === undefined) return PASSTHROUGH;
let identity: string[];
let owner: boolean;
@@ -48,7 +48,7 @@ export async function openAsPreview(engine: BrainEngine, member: string | undefi
}
const { withCallerAccess } = await import('../core/search/private-visibility.ts');
const folder = await (await import('../core/access/caller.ts')).folderAccessFor(engine, identity);
- const access = { identity, ...folder, applyRemoteReadPolicy: true, hidePrivate: !owner, owner, ownerLineage: owner, ownerReadsRestricted, privateReadableSources: [] };
+ const access = { identity, ...folder, applyRemoteReadPolicy: true, hidePrivate: !owner, owner, ownerLineage: owner && readOnly, ownerReadsRestricted: ownerReadsRestricted && readOnly, privateReadableSources: [] };
return {
run: fn => withCallerAccess(access, fn),
context: ctx => ({ ...ctx, accessIdentity: identity, applyRemoteReadPolicy: true }),
diff --git a/src/cli/main.ts b/src/cli/main.ts
index fb62cdde70..6da0d430df 100755
--- a/src/cli/main.ts
+++ b/src/cli/main.ts
@@ -667,7 +667,7 @@ async function runSharedOperation(command: string, subArgs: string[], cliOpts: C
// because the import.meta.main seam exits explicitly on every one-shot path.
const READ_OP_TIMEOUT_MS = 180_000;
const configSnapshot = op.scope === 'read' ? takeStartupConfigSnapshot(engine) ?? openRequestConfigSnapshot(engine) : null;
- const asPreview = await (await import('./as-preview.ts')).openAsPreview(engine, cliOpts.as, command); // GBRA-218 local --as <member>
+ const asPreview = await (await import('./as-preview.ts')).openAsPreview(engine, cliOpts.as, command, op.mutating === false); // GBRA-218 local --as <member>; GST-2490: owner lineage on reads only
try {
const { withTimeout, OperationTimeoutError } = await import('../core/timeout.ts');
diff --git a/src/core/schema-migrations/v304-access-owner-origin.ts b/src/core/schema-migrations/v304-access-owner-origin.ts
index 38d83df046..4205eea8ba 100644
--- a/src/core/schema-migrations/v304-access-owner-origin.ts
+++ b/src/core/schema-migrations/v304-access-owner-origin.ts
@@ -10,8 +10,8 @@ import type { Migration } from './types.ts';
// gbrain_access_origin_hidden_for has the same arms but asks, per origin, whether a caller with p_identity (and the
// folder rules it satisfies, p_satisfied) reads that origin (gbrain_access_origin_closed_for): an owner read passes a
// derivative when it reads every origin. p_open is the owner opt-in (config access.owner_reads_restricted): every
-// origin passes except another member's own member page (memory/members/<id>, p_own_page excluded) and pending
-// coverage. Only owner reads call these; gbrain_access_origin_restricted is untouched, so every other caller reads
+// origin passes except pending coverage and another member's own member page (memory/members/<id>, p_own_page
+// excluded) whose readers and rules the caller does not meet, exactly as that page itself reads. Only owner reads call these; gbrain_access_origin_restricted is untouched, so every other caller reads
// exactly as before, and letting listed members read derivatives later is a call-site change. Nothing is rewritten.
// No schema.sql mirror: like v282, v283 and v285, these exist only through migrations. Provisional number: renumbered
// at the merge slot.
@@ -24,9 +24,9 @@ CREATE OR REPLACE FUNCTION gbrain_access_origin_closed_for(o_source TEXT, o_slug
p_identity TEXT[], p_satisfied TEXT[], p_open BOOLEAN, p_own_page TEXT) RETURNS boolean
LANGUAGE sql STABLE PARALLEL SAFE SET search_path = pg_catalog, public, pg_temp AS $fn$
SELECT gbrain_access_pending_covers(o_source, o_slug)
- OR (starts_with(o_slug, 'memory/members/') AND o_slug IS DISTINCT FROM p_own_page AND NOT COALESCE(o_readers && p_identity, false))
- OR (NOT p_open AND NOT (((o_readers IS NULL AND NOT (o_frontmatter ? 'readable_by')) OR COALESCE(o_readers && p_identity, false))
- AND (o_rules IS NULL OR o_rules <@ p_satisfied)))
+ OR ((NOT p_open OR (starts_with(o_slug, 'memory/members/') AND o_slug IS DISTINCT FROM p_own_page))
+ AND NOT (((o_readers IS NULL AND NOT (o_frontmatter ? 'readable_by')) OR COALESCE(o_readers && p_identity, false))
+ AND (o_rules IS NULL OR o_rules <@ p_satisfied)))
$fn$;
CREATE OR REPLACE FUNCTION gbrain_access_origin_hidden_for(p_id INTEGER, p_source_id TEXT, p_type TEXT, fm JSONB,
p_identity TEXT[], p_satisfied TEXT[], p_open BOOLEAN, p_own_page TEXT) RETURNS boolean
diff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.ts
index a61c2a2390..5e24c21b39 100644
--- a/src/core/search/private-visibility.ts
+++ b/src/core/search/private-visibility.ts
@@ -409,7 +409,10 @@ export function callerReadersAllow(frontmatter: unknown, slug?: string): boolean
/** GBRA-231: readersAllowedSql for the current caller, one conjunct per audience entry. */
export function callerReadersAllowedSql(alias: string, row: 'page' | 'snapshot' = 'page'): string {
const ownPage = ownerOptInPage(currentCallerAccess());
- if (ownPage) return row === 'snapshot' ? 'TRUE' : `(${readersAllowedSql(alias, currentCallerAccess().identity)} OR ${notOtherMemberPageSql(alias, ownPage)})`;
+ if (ownPage) {
+ const notOther = row === 'snapshot' ? `EXISTS (SELECT 1 FROM pages sp WHERE sp.id = ${alias}.page_id AND ${notOtherMemberPageSql('sp', ownPage)})` : notOtherMemberPageSql(alias, ownPage);
+ return `(${readersAllowedSql(alias, currentCallerAccess().identity, row)} OR ${notOther})`;
+ }
return callerIdentities().map(identity => readersAllowedSql(alias, identity, row)).join(' AND ');
}
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-default.json b/test/fixtures/goldens/catalog/pglite-engine-init-default.json
index 2810c9a1dd..365b1cc774 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-default.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-default.json
@@ -597,7 +597,7 @@
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ce49b0fd15875d5f8f9c073eb0df8703f3a90fd6c59bffc239c3011eaf7cef35",
+ "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
"gbrain_access_origin_hidden_for(p_id integer, p_source_id text, p_type text, fm jsonb, p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
"gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
index a43bcd7045..f5f37f52ab 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json
@@ -597,7 +597,7 @@
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ce49b0fd15875d5f8f9c073eb0df8703f3a90fd6c59bffc239c3011eaf7cef35",
+ "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
"gbrain_access_origin_hidden_for(p_id integer, p_source_id text, p_type text, fm jsonb, p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
"gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
index a53c0a7c55..717dd57ead 100644
--- a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
+++ b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json
@@ -597,7 +597,7 @@
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ce49b0fd15875d5f8f9c073eb0df8703f3a90fd6c59bffc239c3011eaf7cef35",
+ "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
"gbrain_access_origin_hidden_for(p_id integer, p_source_id text, p_type text, fm jsonb, p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
"gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-default.json b/test/fixtures/goldens/catalog/postgres-engine-init-default.json
index 41fcab67d5..15cdeb704a 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-default.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-default.json
@@ -601,7 +601,7 @@
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ce49b0fd15875d5f8f9c073eb0df8703f3a90fd6c59bffc239c3011eaf7cef35",
+ "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
"gbrain_access_origin_hidden_for(p_id integer, p_source_id text, p_type text, fm jsonb, p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
"gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
index 8d6bbadae0..9a39a88413 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json
@@ -601,7 +601,7 @@
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ce49b0fd15875d5f8f9c073eb0df8703f3a90fd6c59bffc239c3011eaf7cef35",
+ "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
"gbrain_access_origin_hidden_for(p_id integer, p_source_id text, p_type text, fm jsonb, p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
"gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
index 323f0dea0e..2eff9fb9a0 100644
--- a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
+++ b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json
@@ -601,7 +601,7 @@
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ce49b0fd15875d5f8f9c073eb0df8703f3a90fd6c59bffc239c3011eaf7cef35",
+ "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
"gbrain_access_origin_hidden_for(p_id integer, p_source_id text, p_type text, fm jsonb, p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
"gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.json
index ad1ccba521..22feb54248 100644
--- a/test/fixtures/goldens/migrations/records.json
+++ b/test/fixtures/goldens/migrations/records.json
@@ -4956,8 +4956,8 @@
"idempotent": true,
"name": "access_owner_origin",
"sql": {
- "length": 4231,
- "sha256": "1d1a59070c8965dda0f27a26a927a196f9ab2d5f5a6a93def64a039918fddc19"
+ "length": 4188,
+ "sha256": "6f153b23e8d7bde011ed8dd88649e3a1343c741349ef36b27ec7a60ae17712f6"
},
"sqlFor": "absent",
"transaction": "absent",
diff --git a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
index 6a09a0ffd2..0b2ada8737 100644
--- a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
+++ b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json
@@ -597,7 +597,7 @@
"gbrain_access_folder_rules(p_source text, p_slug text)": "RETURNS text[] kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a476d94909ef46bf697ec14b0e5034eaf504004553264298107d3962fa3059cd",
"gbrain_access_mark_restricted()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e45dc26421664fa3d409fba6c612af88905d2df35923f9592bcb759fc1ea618f",
"gbrain_access_norm_readers(vals text[])": "RETURNS text[] kind=f lang=sql volatility=i secdef=false config=[search_path=pg_catalog, pg_temp] body_sha256=b536c2604461abac62c90c090d127b71bdda8ed23d43ae25790606a8ee64f769",
- "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ce49b0fd15875d5f8f9c073eb0df8703f3a90fd6c59bffc239c3011eaf7cef35",
+ "gbrain_access_origin_closed_for(o_source text, o_slug text, o_frontmatter jsonb, o_readers text[], o_rules text[], p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=67c5094be3455630ad49372cb6385911718bc183acba4546194978dd6e307444",
"gbrain_access_origin_hidden_for(p_id integer, p_source_id text, p_type text, fm jsonb, p_identity text[], p_satisfied text[], p_open boolean, p_own_page text)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=ea3c9cddcba7f9c01b136778aa4490f63fc204f900a280c37e7fb31d6fd3e38d",
"gbrain_access_origin_restricted(p_id integer, p_source_id text, p_type text, fm jsonb)": "RETURNS boolean kind=f lang=plpgsql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d33ef57dcf408ee17d85ce50e05d881c1cd2f4df2ae1424612ad38092d154948",
"gbrain_access_pending_covers(p_source text, p_slug text)": "RETURNS boolean kind=f lang=sql volatility=s secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=57448e941169ad1e65fbdab4bbe4572cc7b6f164ef19fd61a3666640e85f253c",
diff --git a/test/owner-reads-restricted.test.ts b/test/owner-reads-restricted.test.ts
index d9d80eb317..9efa1b4019 100644
--- a/test/owner-reads-restricted.test.ts
+++ b/test/owner-reads-restricted.test.ts
@@ -116,7 +116,7 @@ for (const kind of testBackends()) {
async function call(who: string, op: string, params: Record<string, unknown>): Promise<string> {
if (who === 'as-owner') {
- const preview = await openAsPreview(engine, OWNER, op);
+ const preview = await openAsPreview(engine, OWNER, op, true);
const out = await preview.run(() => dispatchToolCall(engine, op, { ...params }, preview.context({ remote: false, sourceId: SRC }) as never));
return out.content.map(c => c.text).join('\n');
}
@@ -294,3 +294,69 @@ for (const kind of testBackends()) {
});
}
}
+
+for (const kind of testBackends()) {
+ describe(`owner opt-in and other members' member pages (${kind}, repo-less)`, () => {
+ let engine: BrainEngine;
+ let close: () => Promise<void>;
+ const tokens: Record<string, string> = {};
+ const MSRC = 'optin-members';
+ const provider = () => new GBrainOAuthProvider({ sql: sqlQueryForEngine(engine), transaction: fn => engine.transaction(tx => fn(sqlQueryForEngine(tx))) });
+ async function read(who: string, op: string, params: Record<string, unknown>): Promise<string> {
+ __resetPrivateVisibilityCacheForTests();
+ const auth = await provider().verifyAccessToken(tokens[who]!) as unknown as AuthInfo;
+ const out = await dispatchToolCall(engine, op, { ...params }, { remote: true, transport: 'http', auth, sourceId: auth.sourceId ?? 'default', takesHoldersAllowList: ['world'] });
+ return out.content.map(c => c.text).join('\n');
+ }
+ const note = (title: string, canary: string, fm: string[], type = 'note') => ['---', `type: ${type}`, `title: ${title}`, ...fm, '---', `# ${title}`, '', `Harbor notes ${canary} here.`].join('\n');
+ const optIn = async <T>(on: boolean, fn: () => Promise<T>): Promise<T> => {
+ await setOwnerReadsRestricted(engine, on, { remote: false });
+ __resetPrivateVisibilityCacheForTests();
+ try { return await fn(); } finally { await setOwnerReadsRestricted(engine, false, { remote: false }); __resetPrivateVisibilityCacheForTests(); }
+ };
+
+ beforeAll(async () => {
+ if (kind === 'postgres') ({ engine, close } = await isolatedPersistencePostgres(process.env.DATABASE_URL!));
+ else { engine = new PGLiteEngine(); await engine.connect({ engine: 'pglite' } as never); await engine.initSchema(); close = () => engine.disconnect(); }
+ for (const id of [OWNER, 'alice-example', 'bob-example', 'dan-example']) await engine.executeRaw('INSERT INTO access_members (id) VALUES ($1)', [id]);
+ await engine.executeRaw('INSERT INTO sources (id, name) VALUES ($1, $1) ON CONFLICT (id) DO NOTHING', [MSRC]);
+ await proposeRevision(engine, MSRC, [{ id: 'bob-page', prefix: 'memory/members/bob-example', readable_by: ['member:bob-example'] }] as never, { origin: 'cli', store: 'database' });
+ await importFromContent(engine, 'memory/members/alice-example', note('alice memory', 'canarympalicevone', ['readable_by: [alice-example]']), { sourceId: MSRC });
+ await importFromContent(engine, 'memory/members/alice-example', note('alice memory', 'canarympalicevtwo', [`readable_by: [alice-example, ${OWNER}]`]), { sourceId: MSRC });
+ await importFromContent(engine, 'memory/members/bob-example', note('bob memory', 'canarympbobpage', [`readable_by: [bob-example, ${OWNER}]`]), { sourceId: MSRC });
+ await importFromContent(engine, 'atoms/bob-atom', note('bob atom', 'canarympbobatom', ['source_slug: memory/members/bob-example'], 'atom'), { sourceId: MSRC });
+ await importFromContent(engine, 'notes/bob-derived', note('bob derived', 'canarympbobderived', ['derived_from: [memory/members/bob-example]']), { sourceId: MSRC });
+ await importFromContent(engine, 'memory/members/dan-example', note('dan memory', 'canarympdanpage', []), { sourceId: MSRC });
+ await importFromContent(engine, 'atoms/dan-atom', note('dan atom', 'canarympdanatom', ['visibility: world', 'source_slug: memory/members/dan-example'], 'atom'), { sourceId: MSRC });
+ for (const [name, member] of [['owner', OWNER], ['unbound', null]] as const) {
+ const minted = await mintLegacyToken(engine, { name, scopes: ['read'], takesHolders: ['world'], sourceGrant: [MSRC] });
+ tokens[name] = minted.token;
+ if (member) await bindCredential(engine, { kind: 'token', id: minted.id }, { member });
+ }
+ await setOwner(engine, OWNER);
+ }, 300_000);
+ afterAll(async () => { await close?.(); }, 60_000);
+
+ for (const on of [false, true]) {
+ test(`opt-in ${on ? 'on' : 'off'}: an older version of another member's member page kept from the owner stays hidden`, async () => {
+ await optIn(on, async () => {
+ const versions = await read('owner', 'get_versions', { slug: 'memory/members/alice-example', include_body: true, limit: 10 });
+ expect({ on, v1: versions.includes('canarympalicevone') }).toEqual({ on, v1: false });
+ expect(await read('owner', 'get_page', { slug: 'memory/members/alice-example' })).toContain('canarympalicevtwo');
+ });
+ }, 120_000);
+
+ test(`opt-in ${on ? 'on' : 'off'}: derived pages of another member's member page follow that page's rules for the owner`, async () => {
+ await optIn(on, async () => {
+ const seen: string[] = [];
+ for (const [slug, canary] of [['memory/members/bob-example', 'canarympbobpage'], ['atoms/bob-atom', 'canarympbobatom'], ['notes/bob-derived', 'canarympbobderived'],
+ ['memory/members/dan-example', 'canarympdanpage'], ['atoms/dan-atom', 'canarympdanatom']] as const) {
+ if ((await read('owner', 'get_page', { slug })).includes(canary)) seen.push(slug);
+ }
+ expect({ on, seen }).toEqual({ on, seen: ['memory/members/dan-example', 'atoms/dan-atom'] });
+ expect((await read('unbound', 'get_page', { slug: 'atoms/dan-atom' })).includes('canarympdanatom')).toBe(true);
+ });
+ }, 120_000);
+ }
+ });
+}