Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Add guest sources to the database: pages there stay external, only listed writers write them (GBRA-504)
garrytanb8cfd5632826
diff --git a/scripts/e2e-backend-matrix.txt b/scripts/e2e-backend-matrix.txtindex a87908a16e..373f7a132c 100644--- a/scripts/e2e-backend-matrix.txt+++ b/scripts/e2e-backend-matrix.txt@@ -58,6 +58,7 @@ test/e2e/persistence-publish-lock-order-postgres.test.tstest/e2e/p8-memory-writes-postgres.test.tstest/e2e/delta-cursor-integrity-postgres.test.tstest/e2e/trust-tier-postgres.test.ts+test/e2e/guest-notes-postgres.test.tstest/e2e/trust-generation-postgres.test.tstest/e2e/fence-chunk-overlay-postgres.test.tstest/e2e/fence-chunk-trust-read-postgres.test.tsdiff --git a/src/core/deletion-inventory.ts b/src/core/deletion-inventory.tsindex aeb1ac2573..04c91ee3c9 100644--- a/src/core/deletion-inventory.ts+++ b/src/core/deletion-inventory.ts@@ -96,6 +96,9 @@ const ROWS: readonly Row[] = [['facts', 'swept', 'fact', 'source_id entity_slug fact kind visibility notability context source source_session embedding source_markdown_slug claim_metric claim_unit claim_period event_type dimension value value_hash dim_status embedding_model embedded_text_hash write_principal_kind write_principal_id last_write_principal_kind last_write_principal_id attributed_to trust_tier write_origin source_window'],['files', 'swept', 'page_files', 'source_id page_slug filename storage_path mime_type content_hash metadata'],['gbrain_cycle_locks', 'out_of_scope', 'no_memory_text', 'id holder_host'],+ ['guest_marks', 'out_of_scope', 'no_memory_text', 'source_id slug_at_write audience_member group_slug sender_label writer_kind writer_id request_id'],+ ['guest_promotions', 'out_of_scope', 'no_memory_text', 'target_source_id target_slug promoted_by_kind promoted_by_id request_id'],+ ['guest_sources', 'out_of_scope', 'no_memory_text', 'source_id writers trust_ceiling'],['ingest_applied_captures', 'out_of_scope', 'no_memory_text', 'idempotency_key source_id slug result'],['ingest_log', 'out_of_scope', 'probed_reported', 'source_id source_type source_ref pages_updated summary writer_version', 'summary pages_updated'],['link_edge_proposals', 'out_of_scope', 'probed_reported', 'source_id link_type evidence_hash status model generated_line detail', 'generated_line detail'],diff --git a/src/core/function-search-path.ts b/src/core/function-search-path.tsindex fecd32a47a..217ff57efc 100644--- a/src/core/function-search-path.ts+++ b/src/core/function-search-path.ts@@ -40,7 +40,7 @@ export const PINNED_FUNCTION_NAMES = ['gbrain_access_state_unreadable','gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation','gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals',- 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_inserted_facts',+ 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_guest_records', 'gbrain_guard_inserted_facts','gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication','gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal','gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page',diff --git a/src/core/guests/schema.ts b/src/core/guests/schema.tsnew file mode 100644index 0000000000..45b1c73225--- /dev/null+++ b/src/core/guests/schema.ts@@ -0,0 +1,82 @@+/**+ * Guest notes (GBRA-504): the database records behind a guest source. Applied by+ * migration v312 only (like the trust DDL it is not in the schema blob; a fresh+ * install replays every migration).+ *+ * - guest_sources: which sources are guest sources, who may write them+ * (principal strings `<kind>:<id>`, the persistence attribution principal,+ * e.g. `oauth_client:<client id>`) and the tier ceiling their pages keep. The+ * trust trigger (trust/schema.ts GUEST_AWARE_STAMP_TIER_FUNCTION) reads it.+ * - guest_marks: who a guest page was saved for, from which group, when and by+ * which writer. Immutable (UPDATE refused); a row leaves only with its page.+ * - guest_promotions: an owner kept a guest page as an owner page.+ *+ * A guest source is database-only: gbrain_guard_guest_records refuses a+ * local_path on it, and refuses listing a source that has one.+ */+import { TRUST_TIERS } from '../trust/tier.ts';++export const GUEST_RECORD_TABLES = ['guest_sources', 'guest_marks', 'guest_promotions'] as const;++const GUARD_FUNCTION = `CREATE OR REPLACE FUNCTION gbrain_guard_guest_records() RETURNS trigger LANGUAGE plpgsql SET search_path = pg_catalog, public, pg_temp AS $fn$+BEGIN+ IF TG_TABLE_NAME = 'guest_marks' THEN+ RAISE EXCEPTION USING ERRCODE='P0001', MESSAGE='guest_mark_immutable: a guest mark is never changed; it leaves only with its page',+ TABLE=TG_TABLE_NAME, SCHEMA=TG_TABLE_SCHEMA, CONSTRAINT='guest_source_guard';+ ELSIF TG_TABLE_NAME = 'sources' THEN+ IF NEW.local_path IS NOT NULL AND EXISTS (SELECT 1 FROM guest_sources g WHERE g.source_id = NEW.id) THEN+ RAISE EXCEPTION USING ERRCODE='P0001', MESSAGE='guest_source_database_only: a guest source is database-only and takes no local path or repository',+ TABLE=TG_TABLE_NAME, SCHEMA=TG_TABLE_SCHEMA, CONSTRAINT='guest_source_guard', DETAIL=jsonb_build_object('source',NEW.id)::text;+ END IF;+ ELSIF EXISTS (SELECT 1 FROM sources s WHERE s.id = NEW.source_id AND s.local_path IS NOT NULL) THEN+ RAISE EXCEPTION USING ERRCODE='P0001', MESSAGE='guest_source_database_only: a source with a local path or repository cannot become a guest source',+ TABLE=TG_TABLE_NAME, SCHEMA=TG_TABLE_SCHEMA, CONSTRAINT='guest_source_guard', DETAIL=jsonb_build_object('source',NEW.source_id)::text;+ END IF;+ RETURN NEW;+END $fn$`;++export const GUEST_NOTES_SCHEMA_SQL = `+CREATE TABLE IF NOT EXISTS guest_sources (+ source_id TEXT PRIMARY KEY REFERENCES sources(id) ON DELETE CASCADE,+ writers TEXT[] NOT NULL DEFAULT '{}',+ trust_ceiling TEXT NOT NULL DEFAULT 'external_untrusted' CHECK (trust_ceiling IN (${TRUST_TIERS.map(tier => `'${tier}'`).join(', ')})),+ created_at TIMESTAMPTZ NOT NULL DEFAULT now()+);+CREATE TABLE IF NOT EXISTS guest_marks (+ page_id INTEGER PRIMARY KEY REFERENCES pages(id) ON DELETE CASCADE,+ source_id TEXT NOT NULL,+ slug_at_write TEXT NOT NULL,+ audience_member TEXT NOT NULL,+ group_slug TEXT NOT NULL,+ sender_label TEXT NOT NULL,+ saved_at TIMESTAMPTZ NOT NULL,+ writer_kind TEXT NOT NULL,+ writer_id TEXT NOT NULL,+ request_id TEXT,+ created_at TIMESTAMPTZ NOT NULL DEFAULT now()+);+CREATE INDEX IF NOT EXISTS guest_marks_audience_saved_idx ON guest_marks (audience_member, saved_at);+CREATE TABLE IF NOT EXISTS guest_promotions (+ id BIGSERIAL PRIMARY KEY,+ guest_page_id INTEGER NOT NULL REFERENCES pages(id) ON DELETE CASCADE,+ target_source_id TEXT NOT NULL,+ target_slug TEXT NOT NULL,+ promoted_by_kind TEXT NOT NULL,+ promoted_by_id TEXT NOT NULL,+ promoted_at TIMESTAMPTZ NOT NULL DEFAULT now(),+ request_id TEXT+);+CREATE INDEX IF NOT EXISTS guest_promotions_guest_page_idx ON guest_promotions (guest_page_id);+${GUARD_FUNCTION};+DROP TRIGGER IF EXISTS guest_marks_immutable ON guest_marks;+CREATE TRIGGER guest_marks_immutable BEFORE UPDATE ON guest_marks FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records();+DROP TRIGGER IF EXISTS guest_source_database_only ON sources;+CREATE TRIGGER guest_source_database_only BEFORE UPDATE OF local_path ON sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records();+DROP TRIGGER IF EXISTS guest_source_database_only ON guest_sources;+CREATE TRIGGER guest_source_database_only BEFORE INSERT OR UPDATE OF source_id ON guest_sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records();+DO $rls$ BEGIN+ IF EXISTS (SELECT 1 FROM pg_roles pr WHERE pg_has_role(current_user, pr.oid, 'USAGE') AND (pr.rolbypassrls OR pr.rolsuper)) THEN+ ${GUEST_RECORD_TABLES.map(table => `ALTER TABLE ${table} ENABLE ROW LEVEL SECURITY;`).join('\n ')}+ END IF;+END $rls$;+`;diff --git a/src/core/persistence/graduation-inventory.ts b/src/core/persistence/graduation-inventory.tsindex 65f64e75c3..a45ebcd6fd 100644--- a/src/core/persistence/graduation-inventory.ts+++ b/src/core/persistence/graduation-inventory.ts@@ -90,6 +90,9 @@ export const GRADUATION_INVENTORY: Inventory = {carry('facts', 'user_data', 'Facts with attribution columns and the superseded_by self-FK.'),carry('files', 'user_data', 'File metadata; object bytes stay in the storage backend.'),carry('git_canonical_brain', 'operational', 'Git-canonical fence counter (GBRA-95 G7a): sources whose config sets canonical = git, kept by triggers on sources that the copy bypasses; the target would otherwise read zero and its writer guard would refuse nothing.'),+ carry('guest_marks', 'security', 'Who each guest note was saved for, from which group and by which writer (GBRA-504); the outside-guest warning is built from it, never from page text.'),+ carry('guest_promotions', 'user_data', 'Guest notes the owner kept as owner pages, and where.'),+ carry('guest_sources', 'security', 'Which sources hold outside-guest notes, their writer list and tier ceiling; dropping it would let any writer add owner-tier pages there.'),carry('ingest_applied_captures', 'operational', 'Applied /ingest captures by job idempotency key, so a re-run or a replay of a capture after graduation still writes nothing.'),carry('ingest_log', 'operational', 'Ingestion log.'),carry('links', 'user_data', 'Page graph links.'),diff --git a/src/core/pglite-schema.generated.ts b/src/core/pglite-schema.generated.tsindex 35dff78e71..739e8258a7 100644--- a/src/core/pglite-schema.generated.ts+++ b/src/core/pglite-schema.generated.ts@@ -2962,7 +2962,7 @@ BEGINFOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS pathFROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace CROSS JOIN LATERAL unnest(p.proconfig) AS c(setting)WHERE n.nspname = 'public' AND p.prokind = 'f' AND c.setting IN ('search_path=pg_catalog, public', 'search_path=pg_catalog')- AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')+ AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_guest_records', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')AND pg_has_role(current_user, p.proowner, 'USAGE')ORDER BY 1LOOPdiff --git a/src/core/schema-embedded.generated.ts b/src/core/schema-embedded.generated.tsindex 01680acd36..f6bf074ace 100644--- a/src/core/schema-embedded.generated.ts+++ b/src/core/schema-embedded.generated.ts@@ -3748,7 +3748,7 @@ BEGINFOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS pathFROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace CROSS JOIN LATERAL unnest(p.proconfig) AS c(setting)WHERE n.nspname = 'public' AND p.prokind = 'f' AND c.setting IN ('search_path=pg_catalog, public', 'search_path=pg_catalog')- AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')+ AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_guest_records', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')AND pg_has_role(current_user, p.proowner, 'USAGE')ORDER BY 1LOOPdiff --git a/src/core/schema-migrations/latest.generated.ts b/src/core/schema-migrations/latest.generated.tsindex 08a24ddaca..cb04ac84a9 100644--- a/src/core/schema-migrations/latest.generated.ts+++ b/src/core/schema-migrations/latest.generated.ts@@ -4,4 +4,4 @@// The highest schema migration version (migrate.ts LATEST_VERSION), importable without// loading the migrations themselves.-export const LATEST_SCHEMA_VERSION = 310;+export const LATEST_SCHEMA_VERSION = 312;diff --git a/src/core/schema-migrations/registry.generated.ts b/src/core/schema-migrations/registry.generated.tsindex 53e16c2c76..9f19da31ee 100644--- a/src/core/schema-migrations/registry.generated.ts+++ b/src/core/schema-migrations/registry.generated.ts@@ -311,6 +311,7 @@ import { v307 } from './v307-page-label-guards.ts';import { v308 } from './v308-access-labelled-only.ts';import { v309 } from './v309-requester-scope.ts';import { v310 } from './v310-mcp-request-log-rollup.ts';+import { v312 } from './v312-guest-notes.ts';// Array order is historical (see HISTORICAL_ARRAY_ORDER in the generator); the// runner sorts by version before applying.@@ -620,4 +621,5 @@ export const MIGRATIONS: Migration[] = [v308,v309,v310,+ v312,];diff --git a/src/core/schema-migrations/v312-guest-notes.ts b/src/core/schema-migrations/v312-guest-notes.tsnew file mode 100644index 0000000000..8bf9a3f0be--- /dev/null+++ b/src/core/schema-migrations/v312-guest-notes.ts@@ -0,0 +1,26 @@+import type { Migration } from './types.ts';+import { GUEST_NOTES_SCHEMA_SQL } from '../guests/schema.ts';+import { GUEST_AWARE_STAMP_TIER_FUNCTION } from '../trust/schema.ts';++// Applied by src/core/migrate.ts on the next initSchema(); see docs/ENGINES.md+// ("Canonical schema sources") for when schema.sql or a TS fragment also changes.+//+// GBRA-504 (guest notes, slice 1): guest_sources (which sources are guest+// sources, their writer list and tier ceiling), guest_marks (who a guest page+// was saved for, immutable, leaves with its page) and guest_promotions, with+// RLS on (v275's list is frozen); the guard that keeps a guest source+// database-only; and the trust trigger function re-created with the guest rules+// (trust/schema.ts): a guest page never rises above its source's ceiling, only a+// listed writer creates or rewrites one, and facts, takes and timeline rows are+// refused there. Function replacement only on the trust tables, so no trigger is+// re-created on them. Additive: no row is read, copied or rewritten, and with no+// guest source every new branch is a no-op, so a repo-less brain gets it+// unchanged. No schema.sql mirror: like v282-v310, it exists only through+// migrations. Provisional number: renumbered at the merge slot.+export const v312: Migration = {+ version: 312,+ name: 'guest_notes',+ idempotent: true,+ sql: `${GUEST_NOTES_SCHEMA_SQL}${GUEST_AWARE_STAMP_TIER_FUNCTION};+`,+};diff --git a/src/core/trust/schema.ts b/src/core/trust/schema.tsindex 4ded1ffe0d..29d114acfa 100644--- a/src/core/trust/schema.ts+++ b/src/core/trust/schema.ts@@ -32,6 +32,11 @@* user_confirmed. Inside a writer scope it is otherwise clamped back; with* no writer scope it raises `trust_raise_refused`. Lowering is always allowed.* - A writer tier above operator_curated needs a covering promotion ceiling.+ * - Guest sources (GBRA-504, v312): a pages row in a source listed in+ * guest_sources never ends above that source's trust_ceiling, on every exit;+ * creating it or changing its content needs the principal of+ * gbrain.write_principal_kind/_id on the source's writer list; facts, takes+ * and timeline rows there are refused. GUEST_AWARE_STAMP_TIER_FUNCTION.** `gbrain.write_trust_promotion` protects against bugs, not against a process* holding a raw database connection, which can set any setting.@@ -85,13 +90,14 @@ export const TRUST_TIER_TRIGGER_PREDECESSORS: Readonly<Record<TrustTable, readonconst tierList = TRUST_TIERS.map(tier => `'${tier}'`).join(',');const rank = trustRankSql;const lowerOf = (a: string, b: string) => `(CASE WHEN ${rank(a)} <= ${rank(b)} THEN ${a} ELSE ${b} END)`;-const contentExpr = (row: 'NEW' | 'OLD', table: TrustTable) => TRUST_CONTENT_COLUMNS[table]+const contentExpr = (row: 'NEW' | 'OLD', table: TrustTable, columns: readonly string[]) => columns.map(column => table === 'pages' && column === 'frontmatter'// A non-object frontmatter (legacy or raw-SQL rows) has no keys to drop; jsonb `-` would raise on it.? `(CASE WHEN jsonb_typeof(${row}.frontmatter) = 'object' THEN ${row}.frontmatter - ARRAY[${TRUST_EPHEMERAL_FRONTMATTER_KEYS.map(key => `'${key}'`).join(',')}]::text[] ELSE ${row}.frontmatter END)`: `${row}.${column}`).join(', ');-const contentChanged = (table: TrustTable) => `(${contentExpr('NEW', table)}) IS DISTINCT FROM (${contentExpr('OLD', table)})`;+const contentChanged = (table: TrustTable, columns: readonly string[] = TRUST_CONTENT_COLUMNS[table]) =>+ `(${contentExpr('NEW', table, columns)}) IS DISTINCT FROM (${contentExpr('OLD', table, columns)})`;const refuse = (message: string, detail: string) => `RAISE EXCEPTION USING ERRCODE='P0001', MESSAGE='trust_raise_refused: ${message}',TABLE=TG_TABLE_NAME, SCHEMA=TG_TABLE_SCHEMA, CONSTRAINT='trust_tier_guard', DETAIL=${detail}`;const SETTINGS = `@@ -104,9 +110,68 @@ const SETTINGS = `RAISE EXCEPTION USING ERRCODE='22023', MESSAGE='gbrain trust setting names no tier', CONSTRAINT='trust_tier_guard';END IF;`;-const STAMP_TIER_FUNCTION = `CREATE OR REPLACE FUNCTION gbrain_stamp_trust_tier() RETURNS trigger LANGUAGE plpgsql SET search_path = pg_catalog, public, pg_temp AS $fn$-DECLARE writer text; origin_text text; promo text; backfill boolean; keep boolean; changed boolean; effective text;-BEGIN${SETTINGS}+/** A guest page's content for the writer backstop: every content column but deleted_at, so soft delete and restore pass. */+const GUEST_PAGE_CONTENT_COLUMNS = TRUST_CONTENT_COLUMNS.pages.filter(column => column !== 'deleted_at');+const guestRefuse = (code: string, message: string) => `RAISE EXCEPTION USING ERRCODE='P0001', MESSAGE='${code}: ${message}',+ TABLE=TG_TABLE_NAME, SCHEMA=TG_TABLE_SCHEMA, CONSTRAINT='guest_source_guard', DETAIL=jsonb_build_object('op',TG_OP)::text`;+const CHANGED_CHAIN = `${TRUST_TABLES.map((table, index) => `${index === 0 ? 'IF' : 'ELSIF'} TG_TABLE_NAME = '${table}' THEN+ changed := ${contentChanged(table)};`).join('\n ')}+ ELSE+ RAISE EXCEPTION 'gbrain_stamp_trust_tier is not classified for table %', TG_TABLE_NAME;+ END IF;`;+/**+ * GBRA-504: the guest-source rules, run before anything else. A page in a guest+ * source (guest_sources, one primary-key probe) may be inserted, or have a+ * content column other than deleted_at changed (moves in or out included), only+ * by a principal on the source's writer list, read from the attribution+ * settings. A fact, take or timeline row in a guest source is refused on INSERT+ * and on a content change; lifecycle updates and deletes pass. Other tables skip+ * the probe while guest_sources is empty.+ */+const GUEST_GUARD = `+ IF TG_OP = 'UPDATE' THEN+ ${CHANGED_CHAIN.replace(/\n/g, '\n ')}+ END IF;+ IF TG_TABLE_NAME = 'pages' THEN+ SELECT g.trust_ceiling, g.writers INTO guest_ceiling, guest_writers FROM guest_sources g WHERE g.source_id = NEW.source_id;+ guest := FOUND;+ IF NOT guest AND TG_OP = 'UPDATE' AND OLD.source_id IS DISTINCT FROM NEW.source_id THEN+ SELECT g.writers INTO guest_writers FROM guest_sources g WHERE g.source_id = OLD.source_id;+ guest := FOUND;+ END IF;+ IF guest AND NOT COALESCE(NULLIF(current_setting('gbrain.write_principal_kind', true), '') || ':'+ || NULLIF(current_setting('gbrain.write_principal_id', true), '') = ANY(guest_writers), false) THEN+ IF TG_OP = 'INSERT' THEN+ ${guestRefuse('source_writer_restricted', 'only the listed writers of a guest source may create its pages')};+ ELSIF ${contentChanged('pages', GUEST_PAGE_CONTENT_COLUMNS)} THEN+ ${guestRefuse('source_writer_restricted', 'only the listed writers of a guest source may change its pages')};+ END IF;+ END IF;+ ELSIF (TG_OP = 'INSERT' OR changed) AND EXISTS (SELECT 1 FROM guest_sources) THEN+ IF TG_TABLE_NAME = 'facts' THEN+ guest := EXISTS (SELECT 1 FROM guest_sources g WHERE g.source_id = NEW.source_id);+ ELSE+ guest := EXISTS (SELECT 1 FROM pages p JOIN guest_sources g ON g.source_id = p.source_id WHERE p.id = NEW.page_id);+ END IF;+ IF guest THEN+ ${guestRefuse('guest_page_immutable', 'a guest source holds no facts, takes or timeline entries')};+ END IF;+ END IF;`;+/** Every exit of the guest-aware function caps a guest page at its source ceiling. */+const GUEST_CEILING_RETURN = `IF guest_ceiling IS NOT NULL AND ${rank('NEW.trust_tier')} > ${rank('guest_ceiling')} THEN NEW.trust_tier := guest_ceiling; END IF; RETURN NEW;`;++/**+ * The tier trigger function. `guestSources: false` is the v226 body, kept+ * byte-identical (the migration golden pins it, and migrations between v226 and+ * v312 run before guest_sources exists). `true` adds the guest-source rules+ * (GUEST_GUARD) and the per-source ceiling on every RETURN NEW; v312 installs+ * it, and any later migration that re-creates this function uses it.+ */+const stampTierFunction = (guestSources: boolean) => {+ const ret = guestSources ? GUEST_CEILING_RETURN : 'RETURN NEW;';+ return `CREATE OR REPLACE FUNCTION gbrain_stamp_trust_tier() RETURNS trigger LANGUAGE plpgsql SET search_path = pg_catalog, public, pg_temp AS $fn$+DECLARE writer text; origin_text text; promo text; backfill boolean; keep boolean; changed boolean; effective text;${guestSources ? ' guest boolean := false; guest_ceiling text; guest_writers text[];' : ''}+BEGIN${SETTINGS}${guestSources ? GUEST_GUARD : ''}IF ${rank('writer')} > ${rank(`'${OWNER_TIER_FLOOR}'`)} AND (promo IS NULL OR ${rank('writer')} > ${rank('promo')}) THEN${refuse('a write declared a tier above operator_curated without owner confirmation', `jsonb_build_object('op',TG_OP,'writer',writer)::text`)};END IF;@@ -115,27 +180,23 @@ BEGIN${SETTINGS}IF ${rank('NEW.trust_tier')} > ${rank(`'${OWNER_TIER_FLOOR}'`)} AND (promo IS NULL OR ${rank('NEW.trust_tier')} > ${rank('promo')}) THEN${refuse('a copied row named a tier above operator_curated without owner confirmation', `jsonb_build_object('op',TG_OP,'to',NEW.trust_tier)::text`)};END IF;- RETURN NEW;+ ${ret}END IF;NEW.trust_tier := COALESCE(writer, 'unknown');NEW.write_origin := origin_text::jsonb;- RETURN NEW;+ ${ret}END IF;IF ${rank('NEW.trust_tier')} > ${rank('OLD.trust_tier')} THENIF promo IS NOT NULL AND ${rank('NEW.trust_tier')} <= ${rank('promo')} THEN- RETURN NEW;+ ${ret}ELSIF backfill AND OLD.trust_tier = 'unknown' AND NEW.trust_tier <> 'user_confirmed' THEN- RETURN NEW;+ ${ret}ELSIF writer IS NULL THEN${refuse('raising a tier needs owner confirmation', `jsonb_build_object('op',TG_OP,'from',OLD.trust_tier,'to',NEW.trust_tier,'backfill',backfill)::text`)};END IF;NEW.trust_tier := OLD.trust_tier;- END IF;- ${TRUST_TABLES.map((table, index) => `${index === 0 ? 'IF' : 'ELSIF'} TG_TABLE_NAME = '${table}' THEN- changed := ${contentChanged(table)};`).join('\n ')}- ELSE- RAISE EXCEPTION 'gbrain_stamp_trust_tier is not classified for table %', TG_TABLE_NAME;- END IF;+ END IF;${guestSources ? '' : `+ ${CHANGED_CHAIN}`}IF changed AND NOT keep THENeffective := COALESCE(writer, 'unknown');IF ${rank('effective')} < ${rank(`'${OWNER_TIER_FLOOR}'`)} THEN effective := ${lowerOf('OLD.trust_tier', 'effective')}; END IF;@@ -143,8 +204,12 @@ BEGIN${SETTINGS}NEW.trust_tier := effective;IF NEW.write_origin IS NOT DISTINCT FROM OLD.write_origin THEN NEW.write_origin := origin_text::jsonb; END IF;END IF;- RETURN NEW;+ ${ret}END $fn$`;+};+const STAMP_TIER_FUNCTION = stampTierFunction(false);+/** The current tier trigger function, guest-source rules included (v312). */+export const GUEST_AWARE_STAMP_TIER_FUNCTION = stampTierFunction(true);/*** A version row snapshots the page before the archiving write changes it, indiff --git a/src/schema.sql b/src/schema.sqlindex 92eb133d93..394f634c72 100644--- a/src/schema.sql+++ b/src/schema.sql@@ -3744,7 +3744,7 @@ BEGINFOR f IN SELECT p.oid::regprocedure AS sig, substr(c.setting, 13) AS pathFROM pg_proc p JOIN pg_namespace n ON n.oid = p.pronamespace CROSS JOIN LATERAL unnest(p.proconfig) AS c(setting)WHERE n.nspname = 'public' AND p.prokind = 'f' AND c.setting IN ('search_path=pg_catalog, public', 'search_path=pg_catalog')- AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')+ AND p.proname IN ('auto_enable_rls', 'bump_page_generation_clock_fn', 'bump_page_generation_fn', 'enforce_minion_queue_protocol', 'gbrain_access_derive_page_readers', 'gbrain_access_folder_rules', 'gbrain_access_lineage_rules', 'gbrain_access_mark_restricted', 'gbrain_access_norm_readers', 'gbrain_access_origin_closed_for', 'gbrain_access_origin_hidden_for', 'gbrain_access_origin_labelled_for', 'gbrain_access_origin_restricted', 'gbrain_access_pending_covers', 'gbrain_access_readers', 'gbrain_access_refresh_serves', 'gbrain_access_refresh_serves_trigger', 'gbrain_access_stamp_folder_rules', 'gbrain_access_state_unreadable', 'gbrain_advance_page_revision', 'gbrain_advance_tag_revision', 'gbrain_bump_trust_generation', 'gbrain_clear_atom_page_state', 'gbrain_count_git_canonical_sources', 'gbrain_count_modifications', 'gbrain_forget_page_retrievals', 'gbrain_fts_input', 'gbrain_graduation_fence', 'gbrain_guard_deferred_request', 'gbrain_guard_effect_protocol', 'gbrain_guard_guest_records', 'gbrain_guard_inserted_facts', 'gbrain_guard_protocol_activation', 'gbrain_guard_request_protocol', 'gbrain_guard_skill_publication', 'gbrain_lease_shared_skill_delivery', 'gbrain_mark_derivation_scope_entry', 'gbrain_preserve_fact_withdrawal', 'gbrain_queue_page_projection', 'gbrain_refuse_purged_fact', 'gbrain_refuse_purged_page', 'gbrain_refuse_purged_take', 'gbrain_refuse_purging_derivation', 'gbrain_release_refresh_barrier', 'gbrain_require_managed_writer', 'gbrain_require_persistence_protocol', 'gbrain_snapshot_version_trust', 'gbrain_stamp_revision_attribution', 'gbrain_stamp_trust_tier', 'gbrain_stamp_version_attribution', 'gbrain_stamp_write_attribution', 'gbrain_try_jsonb', 'notify_minion_job_change', 'update_chunk_search_vector', 'update_page_search_vector')AND pg_has_role(current_user, p.proowner, 'USAGE')ORDER BY 1LOOPdiff --git a/test/e2e/guest-notes-postgres.test.ts b/test/e2e/guest-notes-postgres.test.tsnew file mode 100644index 0000000000..45741f3ac0--- /dev/null+++ b/test/e2e/guest-notes-postgres.test.ts@@ -0,0 +1,6 @@+import { registerPostgresTests } from '../helpers/test-backends.ts';++// Guest notes, slice 1 (GBRA-504) on Postgres: the guest record tables, the+// trust trigger's guest ceiling and writer backstop, direct and through+// transaction-mode PgBouncer (scripts/e2e-backend-matrix.txt).+await registerPostgresTests(() => import('../guest-notes-schema.test.ts'));diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-default.json b/test/fixtures/goldens/catalog/pglite-engine-init-default.jsonindex d048ee8fdd..42a9ba7379 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-default.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-default.json@@ -164,6 +164,13 @@"git_canonical_brain.git_canonical_brain_pkey": "p PRIMARY KEY (singleton)","git_canonical_brain.git_canonical_brain_singleton_check": "c CHECK ((singleton = 1))","git_canonical_brain.git_canonical_brain_strict_sources_check": "c CHECK ((strict_sources >= 0))",+ "guest_marks.guest_marks_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_marks.guest_marks_pkey": "p PRIMARY KEY (page_id)",+ "guest_promotions.guest_promotions_guest_page_id_fkey": "f FOREIGN KEY (guest_page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_promotions.guest_promotions_pkey": "p PRIMARY KEY (id)",+ "guest_sources.guest_sources_pkey": "p PRIMARY KEY (source_id)",+ "guest_sources.guest_sources_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "guest_sources.guest_sources_trust_ceiling_check": "c CHECK ((trust_ceiling = ANY (ARRAY['user_confirmed'::text, 'operator_curated'::text, 'tool_observed'::text, 'agent_written'::text, 'unknown'::text, 'external_untrusted'::text])))","ingest_applied_captures.ingest_applied_captures_pkey": "p PRIMARY KEY (idempotency_key)","ingest_log.ingest_log_pkey": "p PRIMARY KEY (id)","link_edge_proposals.link_edge_proposals_a_to_page_id_fkey": "f FOREIGN KEY (a_to_page_id) REFERENCES pages(id) ON DELETE CASCADE",@@ -629,6 +636,7 @@"gbrain_graduation_fence()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=cd4642fe8deee2a3c14ef41f53862f0a449b2d8a10e47177bd4f5d2e05ce8803","gbrain_guard_deferred_request()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=edf066d51ee76d4037663393271883a12d7fdf4f0f01b7d1faa9e979d552c6c6","gbrain_guard_effect_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=aa01528006dd7029eac6808e0233991524c9de9dc14aaf41f44160d67a747042",+ "gbrain_guard_guest_records()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0618c22ca97887e3333e0543478e7e97ecba3ba3c678f6d803a1e6df0900b163","gbrain_guard_inserted_facts()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=78fe53917ec54c7627df4961a7669e0d65f8adfa7e249da1beeb58dc37978a66","gbrain_guard_protocol_activation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=bb477ec66ecac06e6edba773a94a2834ef4286a0b9e5cfa8b9b8646e003b0b9e","gbrain_guard_request_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2709686143e064b577e2b3c8e3e2b1009d52a836a2bc709f5f003a251eb004d2",@@ -646,7 +654,7 @@"gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0aa697992ad1777eaba4a1f4d2325dc4f2a98f3ebf9e81325d1b068406ce1cb","gbrain_stamp_revision_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d446ed1145d8bb9c93cb0ca4aa076a5dc7a5fe07b3e79518adaf1b17b0a51216",- "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4610c2e064a0d34dbb66981dd49f15fb6b0b85407327983cde76b905cd626598",+ "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=8dd3e1a4575fe8d2844a4430d0e66ceb122265ef161f9cecefa3a3edf06a6e5b","gbrain_stamp_version_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=1f8fcf3492a9276c52541f6d353d6c709a123b6db4c84bb9a60d77a82fa1672f","gbrain_stamp_write_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e2dbafe65571fedcadc0441415f58fb5b5209b4c9cefa50e4855f58f0452327c","gbrain_try_jsonb(input text)": "RETURNS jsonb kind=f lang=plpgsql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=11b96a0400158fcb3dbd84255985cd11e473688c53fff64ebf92602fceccbedf",@@ -843,6 +851,15 @@"git_canonical_brain": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "guest_marks": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_promotions": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_sources": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"ingest_applied_captures": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1329,6 +1346,11 @@"files_storage_path_key": "CREATE UNIQUE INDEX files_storage_path_key ON public.files USING btree (storage_path)","gbrain_cycle_locks_pkey": "CREATE UNIQUE INDEX gbrain_cycle_locks_pkey ON public.gbrain_cycle_locks USING btree (id)","git_canonical_brain_pkey": "CREATE UNIQUE INDEX git_canonical_brain_pkey ON public.git_canonical_brain USING btree (singleton)",+ "guest_marks_audience_saved_idx": "CREATE INDEX guest_marks_audience_saved_idx ON public.guest_marks USING btree (audience_member, saved_at)",+ "guest_marks_pkey": "CREATE UNIQUE INDEX guest_marks_pkey ON public.guest_marks USING btree (page_id)",+ "guest_promotions_guest_page_idx": "CREATE INDEX guest_promotions_guest_page_idx ON public.guest_promotions USING btree (guest_page_id)",+ "guest_promotions_pkey": "CREATE UNIQUE INDEX guest_promotions_pkey ON public.guest_promotions USING btree (id)",+ "guest_sources_pkey": "CREATE UNIQUE INDEX guest_sources_pkey ON public.guest_sources USING btree (source_id)","idx_access_tokens_hash": "CREATE INDEX idx_access_tokens_hash ON public.access_tokens USING btree (token_hash) WHERE (revoked_at IS NULL)","idx_budget_reservations_expires": "CREATE INDEX idx_budget_reservations_expires ON public.budget_reservations USING btree (expires_at) WHERE (status = 'held'::text)","idx_chat_usage_log_created": "CREATE INDEX idx_chat_usage_log_created ON public.chat_usage_log USING btree (created_at)",@@ -1744,6 +1766,7 @@"facts_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=facts.id","files_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=files.id","graph_generation_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-",+ "guest_promotions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=guest_promotions.id","ingest_log_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=ingest_log.id","link_edge_proposals_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_edge_proposals.id","link_transitions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_transitions.id",@@ -2788,6 +2811,44 @@],"flags": "relkind=r rls=true force_rls=false"},+ "guest_marks": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 slug_at_write text/text NOT NULL",+ "4 audience_member text/text NOT NULL",+ "5 group_slug text/text NOT NULL",+ "6 sender_label text/text NOT NULL",+ "7 saved_at timestamp with time zone/timestamptz NOT NULL",+ "8 writer_kind text/text NOT NULL",+ "9 writer_id text/text NOT NULL",+ "10 request_id text/text NULL",+ "11 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_promotions": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('guest_promotions_id_seq'::regclass)",+ "2 guest_page_id integer/int4 NOT NULL",+ "3 target_source_id text/text NOT NULL",+ "4 target_slug text/text NOT NULL",+ "5 promoted_by_kind text/text NOT NULL",+ "6 promoted_by_id text/text NOT NULL",+ "7 promoted_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",+ "8 request_id text/text NULL"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_sources": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 writers ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "3 trust_ceiling text/text NOT NULL DEFAULT 'external_untrusted'::text",+ "4 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"ingest_applied_captures": {"columns": ["1 idempotency_key text/text NOT NULL",@@ -4729,6 +4790,8 @@"facts.planner_stats_upd": "CREATE TRIGGER planner_stats_upd AFTER UPDATE ON public.facts REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","facts.trust_generation_update": "CREATE CONSTRAINT TRIGGER trust_generation_update AFTER UPDATE ON public.facts DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((old.trust_tier IS DISTINCT FROM new.trust_tier)) EXECUTE FUNCTION gbrain_bump_trust_generation()","facts.trust_tier_stamp": "CREATE TRIGGER trust_tier_stamp BEFORE INSERT OR UPDATE ON public.facts FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_trust_tier()",+ "guest_marks.guest_marks_immutable": "CREATE TRIGGER guest_marks_immutable BEFORE UPDATE ON public.guest_marks FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()",+ "guest_sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE INSERT OR UPDATE OF source_id ON public.guest_sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","links.planner_stats_del": "CREATE TRIGGER planner_stats_del AFTER DELETE ON public.links REFERENCING OLD TABLE AS old_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","links.planner_stats_ins": "CREATE TRIGGER planner_stats_ins AFTER INSERT ON public.links REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","links.planner_stats_upd": "CREATE TRIGGER planner_stats_upd AFTER UPDATE ON public.links REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()",@@ -4778,6 +4841,7 @@"sources.git_canonical_sources_count_delete": "CREATE TRIGGER git_canonical_sources_count_delete AFTER DELETE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_insert": "CREATE TRIGGER git_canonical_sources_count_insert AFTER INSERT ON public.sources FOR EACH ROW WHEN (((new.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_update": "CREATE TRIGGER git_canonical_sources_count_update AFTER UPDATE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) IS DISTINCT FROM (new.config ->> 'canonical'::text))) EXECUTE FUNCTION gbrain_count_git_canonical_sources()",+ "sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE UPDATE OF local_path ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","sources.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.tags_knowledge_revision": "CREATE TRIGGER tags_knowledge_revision AFTER INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_advance_tag_revision()",diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.jsonindex 5fcffd4cce..7eef60a71a 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json@@ -164,6 +164,13 @@"git_canonical_brain.git_canonical_brain_pkey": "p PRIMARY KEY (singleton)","git_canonical_brain.git_canonical_brain_singleton_check": "c CHECK ((singleton = 1))","git_canonical_brain.git_canonical_brain_strict_sources_check": "c CHECK ((strict_sources >= 0))",+ "guest_marks.guest_marks_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_marks.guest_marks_pkey": "p PRIMARY KEY (page_id)",+ "guest_promotions.guest_promotions_guest_page_id_fkey": "f FOREIGN KEY (guest_page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_promotions.guest_promotions_pkey": "p PRIMARY KEY (id)",+ "guest_sources.guest_sources_pkey": "p PRIMARY KEY (source_id)",+ "guest_sources.guest_sources_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "guest_sources.guest_sources_trust_ceiling_check": "c CHECK ((trust_ceiling = ANY (ARRAY['user_confirmed'::text, 'operator_curated'::text, 'tool_observed'::text, 'agent_written'::text, 'unknown'::text, 'external_untrusted'::text])))","ingest_applied_captures.ingest_applied_captures_pkey": "p PRIMARY KEY (idempotency_key)","ingest_log.ingest_log_pkey": "p PRIMARY KEY (id)","link_edge_proposals.link_edge_proposals_a_to_page_id_fkey": "f FOREIGN KEY (a_to_page_id) REFERENCES pages(id) ON DELETE CASCADE",@@ -629,6 +636,7 @@"gbrain_graduation_fence()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=cd4642fe8deee2a3c14ef41f53862f0a449b2d8a10e47177bd4f5d2e05ce8803","gbrain_guard_deferred_request()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=edf066d51ee76d4037663393271883a12d7fdf4f0f01b7d1faa9e979d552c6c6","gbrain_guard_effect_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=aa01528006dd7029eac6808e0233991524c9de9dc14aaf41f44160d67a747042",+ "gbrain_guard_guest_records()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0618c22ca97887e3333e0543478e7e97ecba3ba3c678f6d803a1e6df0900b163","gbrain_guard_inserted_facts()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=78fe53917ec54c7627df4961a7669e0d65f8adfa7e249da1beeb58dc37978a66","gbrain_guard_protocol_activation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=bb477ec66ecac06e6edba773a94a2834ef4286a0b9e5cfa8b9b8646e003b0b9e","gbrain_guard_request_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2709686143e064b577e2b3c8e3e2b1009d52a836a2bc709f5f003a251eb004d2",@@ -646,7 +654,7 @@"gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0aa697992ad1777eaba4a1f4d2325dc4f2a98f3ebf9e81325d1b068406ce1cb","gbrain_stamp_revision_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d446ed1145d8bb9c93cb0ca4aa076a5dc7a5fe07b3e79518adaf1b17b0a51216",- "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4610c2e064a0d34dbb66981dd49f15fb6b0b85407327983cde76b905cd626598",+ "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=8dd3e1a4575fe8d2844a4430d0e66ceb122265ef161f9cecefa3a3edf06a6e5b","gbrain_stamp_version_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=1f8fcf3492a9276c52541f6d353d6c709a123b6db4c84bb9a60d77a82fa1672f","gbrain_stamp_write_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e2dbafe65571fedcadc0441415f58fb5b5209b4c9cefa50e4855f58f0452327c","gbrain_try_jsonb(input text)": "RETURNS jsonb kind=f lang=plpgsql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=11b96a0400158fcb3dbd84255985cd11e473688c53fff64ebf92602fceccbedf",@@ -843,6 +851,15 @@"git_canonical_brain": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "guest_marks": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_promotions": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_sources": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"ingest_applied_captures": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1329,6 +1346,11 @@"files_storage_path_key": "CREATE UNIQUE INDEX files_storage_path_key ON public.files USING btree (storage_path)","gbrain_cycle_locks_pkey": "CREATE UNIQUE INDEX gbrain_cycle_locks_pkey ON public.gbrain_cycle_locks USING btree (id)","git_canonical_brain_pkey": "CREATE UNIQUE INDEX git_canonical_brain_pkey ON public.git_canonical_brain USING btree (singleton)",+ "guest_marks_audience_saved_idx": "CREATE INDEX guest_marks_audience_saved_idx ON public.guest_marks USING btree (audience_member, saved_at)",+ "guest_marks_pkey": "CREATE UNIQUE INDEX guest_marks_pkey ON public.guest_marks USING btree (page_id)",+ "guest_promotions_guest_page_idx": "CREATE INDEX guest_promotions_guest_page_idx ON public.guest_promotions USING btree (guest_page_id)",+ "guest_promotions_pkey": "CREATE UNIQUE INDEX guest_promotions_pkey ON public.guest_promotions USING btree (id)",+ "guest_sources_pkey": "CREATE UNIQUE INDEX guest_sources_pkey ON public.guest_sources USING btree (source_id)","idx_access_tokens_hash": "CREATE INDEX idx_access_tokens_hash ON public.access_tokens USING btree (token_hash) WHERE (revoked_at IS NULL)","idx_budget_reservations_expires": "CREATE INDEX idx_budget_reservations_expires ON public.budget_reservations USING btree (expires_at) WHERE (status = 'held'::text)","idx_chat_usage_log_created": "CREATE INDEX idx_chat_usage_log_created ON public.chat_usage_log USING btree (created_at)",@@ -1744,6 +1766,7 @@"facts_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=facts.id","files_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=files.id","graph_generation_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-",+ "guest_promotions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=guest_promotions.id","ingest_log_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=ingest_log.id","link_edge_proposals_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_edge_proposals.id","link_transitions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_transitions.id",@@ -2788,6 +2811,44 @@],"flags": "relkind=r rls=true force_rls=false"},+ "guest_marks": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 slug_at_write text/text NOT NULL",+ "4 audience_member text/text NOT NULL",+ "5 group_slug text/text NOT NULL",+ "6 sender_label text/text NOT NULL",+ "7 saved_at timestamp with time zone/timestamptz NOT NULL",+ "8 writer_kind text/text NOT NULL",+ "9 writer_id text/text NOT NULL",+ "10 request_id text/text NULL",+ "11 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_promotions": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('guest_promotions_id_seq'::regclass)",+ "2 guest_page_id integer/int4 NOT NULL",+ "3 target_source_id text/text NOT NULL",+ "4 target_slug text/text NOT NULL",+ "5 promoted_by_kind text/text NOT NULL",+ "6 promoted_by_id text/text NOT NULL",+ "7 promoted_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",+ "8 request_id text/text NULL"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_sources": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 writers ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "3 trust_ceiling text/text NOT NULL DEFAULT 'external_untrusted'::text",+ "4 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"ingest_applied_captures": {"columns": ["1 idempotency_key text/text NOT NULL",@@ -4729,6 +4790,8 @@"facts.planner_stats_upd": "CREATE TRIGGER planner_stats_upd AFTER UPDATE ON public.facts REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","facts.trust_generation_update": "CREATE CONSTRAINT TRIGGER trust_generation_update AFTER UPDATE ON public.facts DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((old.trust_tier IS DISTINCT FROM new.trust_tier)) EXECUTE FUNCTION gbrain_bump_trust_generation()","facts.trust_tier_stamp": "CREATE TRIGGER trust_tier_stamp BEFORE INSERT OR UPDATE ON public.facts FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_trust_tier()",+ "guest_marks.guest_marks_immutable": "CREATE TRIGGER guest_marks_immutable BEFORE UPDATE ON public.guest_marks FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()",+ "guest_sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE INSERT OR UPDATE OF source_id ON public.guest_sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","links.planner_stats_del": "CREATE TRIGGER planner_stats_del AFTER DELETE ON public.links REFERENCING OLD TABLE AS old_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","links.planner_stats_ins": "CREATE TRIGGER planner_stats_ins AFTER INSERT ON public.links REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","links.planner_stats_upd": "CREATE TRIGGER planner_stats_upd AFTER UPDATE ON public.links REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()",@@ -4778,6 +4841,7 @@"sources.git_canonical_sources_count_delete": "CREATE TRIGGER git_canonical_sources_count_delete AFTER DELETE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_insert": "CREATE TRIGGER git_canonical_sources_count_insert AFTER INSERT ON public.sources FOR EACH ROW WHEN (((new.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_update": "CREATE TRIGGER git_canonical_sources_count_update AFTER UPDATE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) IS DISTINCT FROM (new.config ->> 'canonical'::text))) EXECUTE FUNCTION gbrain_count_git_canonical_sources()",+ "sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE UPDATE OF local_path ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","sources.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.tags_knowledge_revision": "CREATE TRIGGER tags_knowledge_revision AFTER INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_advance_tag_revision()",diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.jsonindex 3fcec7f36b..80fff642b3 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json@@ -164,6 +164,13 @@"git_canonical_brain.git_canonical_brain_pkey": "p PRIMARY KEY (singleton)","git_canonical_brain.git_canonical_brain_singleton_check": "c CHECK ((singleton = 1))","git_canonical_brain.git_canonical_brain_strict_sources_check": "c CHECK ((strict_sources >= 0))",+ "guest_marks.guest_marks_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_marks.guest_marks_pkey": "p PRIMARY KEY (page_id)",+ "guest_promotions.guest_promotions_guest_page_id_fkey": "f FOREIGN KEY (guest_page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_promotions.guest_promotions_pkey": "p PRIMARY KEY (id)",+ "guest_sources.guest_sources_pkey": "p PRIMARY KEY (source_id)",+ "guest_sources.guest_sources_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "guest_sources.guest_sources_trust_ceiling_check": "c CHECK ((trust_ceiling = ANY (ARRAY['user_confirmed'::text, 'operator_curated'::text, 'tool_observed'::text, 'agent_written'::text, 'unknown'::text, 'external_untrusted'::text])))","ingest_applied_captures.ingest_applied_captures_pkey": "p PRIMARY KEY (idempotency_key)","ingest_log.ingest_log_pkey": "p PRIMARY KEY (id)","link_edge_proposals.link_edge_proposals_a_to_page_id_fkey": "f FOREIGN KEY (a_to_page_id) REFERENCES pages(id) ON DELETE CASCADE",@@ -629,6 +636,7 @@"gbrain_graduation_fence()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=cd4642fe8deee2a3c14ef41f53862f0a449b2d8a10e47177bd4f5d2e05ce8803","gbrain_guard_deferred_request()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=edf066d51ee76d4037663393271883a12d7fdf4f0f01b7d1faa9e979d552c6c6","gbrain_guard_effect_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=aa01528006dd7029eac6808e0233991524c9de9dc14aaf41f44160d67a747042",+ "gbrain_guard_guest_records()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0618c22ca97887e3333e0543478e7e97ecba3ba3c678f6d803a1e6df0900b163","gbrain_guard_inserted_facts()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=78fe53917ec54c7627df4961a7669e0d65f8adfa7e249da1beeb58dc37978a66","gbrain_guard_protocol_activation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=bb477ec66ecac06e6edba773a94a2834ef4286a0b9e5cfa8b9b8646e003b0b9e","gbrain_guard_request_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2709686143e064b577e2b3c8e3e2b1009d52a836a2bc709f5f003a251eb004d2",@@ -646,7 +654,7 @@"gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0aa697992ad1777eaba4a1f4d2325dc4f2a98f3ebf9e81325d1b068406ce1cb","gbrain_stamp_revision_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d446ed1145d8bb9c93cb0ca4aa076a5dc7a5fe07b3e79518adaf1b17b0a51216",- "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4610c2e064a0d34dbb66981dd49f15fb6b0b85407327983cde76b905cd626598",+ "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=8dd3e1a4575fe8d2844a4430d0e66ceb122265ef161f9cecefa3a3edf06a6e5b","gbrain_stamp_version_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=1f8fcf3492a9276c52541f6d353d6c709a123b6db4c84bb9a60d77a82fa1672f","gbrain_stamp_write_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e2dbafe65571fedcadc0441415f58fb5b5209b4c9cefa50e4855f58f0452327c","gbrain_try_jsonb(input text)": "RETURNS jsonb kind=f lang=plpgsql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=11b96a0400158fcb3dbd84255985cd11e473688c53fff64ebf92602fceccbedf",@@ -843,6 +851,15 @@"git_canonical_brain": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "guest_marks": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_promotions": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_sources": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"ingest_applied_captures": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1329,6 +1346,11 @@"files_storage_path_key": "CREATE UNIQUE INDEX files_storage_path_key ON public.files USING btree (storage_path)","gbrain_cycle_locks_pkey": "CREATE UNIQUE INDEX gbrain_cycle_locks_pkey ON public.gbrain_cycle_locks USING btree (id)","git_canonical_brain_pkey": "CREATE UNIQUE INDEX git_canonical_brain_pkey ON public.git_canonical_brain USING btree (singleton)",+ "guest_marks_audience_saved_idx": "CREATE INDEX guest_marks_audience_saved_idx ON public.guest_marks USING btree (audience_member, saved_at)",+ "guest_marks_pkey": "CREATE UNIQUE INDEX guest_marks_pkey ON public.guest_marks USING btree (page_id)",+ "guest_promotions_guest_page_idx": "CREATE INDEX guest_promotions_guest_page_idx ON public.guest_promotions USING btree (guest_page_id)",+ "guest_promotions_pkey": "CREATE UNIQUE INDEX guest_promotions_pkey ON public.guest_promotions USING btree (id)",+ "guest_sources_pkey": "CREATE UNIQUE INDEX guest_sources_pkey ON public.guest_sources USING btree (source_id)","idx_access_tokens_hash": "CREATE INDEX idx_access_tokens_hash ON public.access_tokens USING btree (token_hash) WHERE (revoked_at IS NULL)","idx_budget_reservations_expires": "CREATE INDEX idx_budget_reservations_expires ON public.budget_reservations USING btree (expires_at) WHERE (status = 'held'::text)","idx_chat_usage_log_created": "CREATE INDEX idx_chat_usage_log_created ON public.chat_usage_log USING btree (created_at)",@@ -1740,6 +1762,7 @@"facts_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=facts.id","files_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=files.id","graph_generation_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-",+ "guest_promotions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=guest_promotions.id","ingest_log_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=ingest_log.id","link_edge_proposals_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_edge_proposals.id","link_transitions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_transitions.id",@@ -2784,6 +2807,44 @@],"flags": "relkind=r rls=true force_rls=false"},+ "guest_marks": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 slug_at_write text/text NOT NULL",+ "4 audience_member text/text NOT NULL",+ "5 group_slug text/text NOT NULL",+ "6 sender_label text/text NOT NULL",+ "7 saved_at timestamp with time zone/timestamptz NOT NULL",+ "8 writer_kind text/text NOT NULL",+ "9 writer_id text/text NOT NULL",+ "10 request_id text/text NULL",+ "11 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_promotions": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('guest_promotions_id_seq'::regclass)",+ "2 guest_page_id integer/int4 NOT NULL",+ "3 target_source_id text/text NOT NULL",+ "4 target_slug text/text NOT NULL",+ "5 promoted_by_kind text/text NOT NULL",+ "6 promoted_by_id text/text NOT NULL",+ "7 promoted_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",+ "8 request_id text/text NULL"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_sources": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 writers ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "3 trust_ceiling text/text NOT NULL DEFAULT 'external_untrusted'::text",+ "4 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"ingest_applied_captures": {"columns": ["1 idempotency_key text/text NOT NULL",@@ -4725,6 +4786,8 @@"facts.planner_stats_upd": "CREATE TRIGGER planner_stats_upd AFTER UPDATE ON public.facts REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","facts.trust_generation_update": "CREATE CONSTRAINT TRIGGER trust_generation_update AFTER UPDATE ON public.facts DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((old.trust_tier IS DISTINCT FROM new.trust_tier)) EXECUTE FUNCTION gbrain_bump_trust_generation()","facts.trust_tier_stamp": "CREATE TRIGGER trust_tier_stamp BEFORE INSERT OR UPDATE ON public.facts FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_trust_tier()",+ "guest_marks.guest_marks_immutable": "CREATE TRIGGER guest_marks_immutable BEFORE UPDATE ON public.guest_marks FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()",+ "guest_sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE INSERT OR UPDATE OF source_id ON public.guest_sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","links.planner_stats_del": "CREATE TRIGGER planner_stats_del AFTER DELETE ON public.links REFERENCING OLD TABLE AS old_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","links.planner_stats_ins": "CREATE TRIGGER planner_stats_ins AFTER INSERT ON public.links REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","links.planner_stats_upd": "CREATE TRIGGER planner_stats_upd AFTER UPDATE ON public.links REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()",@@ -4774,6 +4837,7 @@"sources.git_canonical_sources_count_delete": "CREATE TRIGGER git_canonical_sources_count_delete AFTER DELETE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_insert": "CREATE TRIGGER git_canonical_sources_count_insert AFTER INSERT ON public.sources FOR EACH ROW WHEN (((new.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_update": "CREATE TRIGGER git_canonical_sources_count_update AFTER UPDATE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) IS DISTINCT FROM (new.config ->> 'canonical'::text))) EXECUTE FUNCTION gbrain_count_git_canonical_sources()",+ "sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE UPDATE OF local_path ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","sources.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.tags_knowledge_revision": "CREATE TRIGGER tags_knowledge_revision AFTER INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_advance_tag_revision()",diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-default.json b/test/fixtures/goldens/catalog/postgres-engine-init-default.jsonindex bd2659b722..c2a1414154 100644--- a/test/fixtures/goldens/catalog/postgres-engine-init-default.json+++ b/test/fixtures/goldens/catalog/postgres-engine-init-default.json@@ -167,6 +167,13 @@"git_canonical_brain.git_canonical_brain_pkey": "p PRIMARY KEY (singleton)","git_canonical_brain.git_canonical_brain_singleton_check": "c CHECK ((singleton = 1))","git_canonical_brain.git_canonical_brain_strict_sources_check": "c CHECK ((strict_sources >= 0))",+ "guest_marks.guest_marks_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_marks.guest_marks_pkey": "p PRIMARY KEY (page_id)",+ "guest_promotions.guest_promotions_guest_page_id_fkey": "f FOREIGN KEY (guest_page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_promotions.guest_promotions_pkey": "p PRIMARY KEY (id)",+ "guest_sources.guest_sources_pkey": "p PRIMARY KEY (source_id)",+ "guest_sources.guest_sources_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "guest_sources.guest_sources_trust_ceiling_check": "c CHECK ((trust_ceiling = ANY (ARRAY['user_confirmed'::text, 'operator_curated'::text, 'tool_observed'::text, 'agent_written'::text, 'unknown'::text, 'external_untrusted'::text])))","ingest_applied_captures.ingest_applied_captures_pkey": "p PRIMARY KEY (idempotency_key)","ingest_log.ingest_log_pkey": "p PRIMARY KEY (id)","link_edge_proposals.link_edge_proposals_a_to_page_id_fkey": "f FOREIGN KEY (a_to_page_id) REFERENCES pages(id) ON DELETE CASCADE",@@ -632,6 +639,7 @@"gbrain_graduation_fence()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=cd4642fe8deee2a3c14ef41f53862f0a449b2d8a10e47177bd4f5d2e05ce8803","gbrain_guard_deferred_request()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=edf066d51ee76d4037663393271883a12d7fdf4f0f01b7d1faa9e979d552c6c6","gbrain_guard_effect_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=aa01528006dd7029eac6808e0233991524c9de9dc14aaf41f44160d67a747042",+ "gbrain_guard_guest_records()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0618c22ca97887e3333e0543478e7e97ecba3ba3c678f6d803a1e6df0900b163","gbrain_guard_inserted_facts()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=78fe53917ec54c7627df4961a7669e0d65f8adfa7e249da1beeb58dc37978a66","gbrain_guard_protocol_activation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=bb477ec66ecac06e6edba773a94a2834ef4286a0b9e5cfa8b9b8646e003b0b9e","gbrain_guard_request_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2709686143e064b577e2b3c8e3e2b1009d52a836a2bc709f5f003a251eb004d2",@@ -649,7 +657,7 @@"gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0aa697992ad1777eaba4a1f4d2325dc4f2a98f3ebf9e81325d1b068406ce1cb","gbrain_stamp_revision_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d446ed1145d8bb9c93cb0ca4aa076a5dc7a5fe07b3e79518adaf1b17b0a51216",- "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4610c2e064a0d34dbb66981dd49f15fb6b0b85407327983cde76b905cd626598",+ "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=8dd3e1a4575fe8d2844a4430d0e66ceb122265ef161f9cecefa3a3edf06a6e5b","gbrain_stamp_version_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=1f8fcf3492a9276c52541f6d353d6c709a123b6db4c84bb9a60d77a82fa1672f","gbrain_stamp_write_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e2dbafe65571fedcadc0441415f58fb5b5209b4c9cefa50e4855f58f0452327c","gbrain_try_jsonb(input text)": "RETURNS jsonb kind=f lang=plpgsql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=11b96a0400158fcb3dbd84255985cd11e473688c53fff64ebf92602fceccbedf",@@ -850,6 +858,15 @@"git_canonical_brain": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "guest_marks": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_promotions": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_sources": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"ingest_applied_captures": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1331,6 +1348,11 @@"files_storage_path_key": "CREATE UNIQUE INDEX files_storage_path_key ON public.files USING btree (storage_path)","gbrain_cycle_locks_pkey": "CREATE UNIQUE INDEX gbrain_cycle_locks_pkey ON public.gbrain_cycle_locks USING btree (id)","git_canonical_brain_pkey": "CREATE UNIQUE INDEX git_canonical_brain_pkey ON public.git_canonical_brain USING btree (singleton)",+ "guest_marks_audience_saved_idx": "CREATE INDEX guest_marks_audience_saved_idx ON public.guest_marks USING btree (audience_member, saved_at)",+ "guest_marks_pkey": "CREATE UNIQUE INDEX guest_marks_pkey ON public.guest_marks USING btree (page_id)",+ "guest_promotions_guest_page_idx": "CREATE INDEX guest_promotions_guest_page_idx ON public.guest_promotions USING btree (guest_page_id)",+ "guest_promotions_pkey": "CREATE UNIQUE INDEX guest_promotions_pkey ON public.guest_promotions USING btree (id)",+ "guest_sources_pkey": "CREATE UNIQUE INDEX guest_sources_pkey ON public.guest_sources USING btree (source_id)","idx_access_tokens_hash": "CREATE INDEX idx_access_tokens_hash ON public.access_tokens USING btree (token_hash) WHERE (revoked_at IS NULL)","idx_budget_reservations_expires": "CREATE INDEX idx_budget_reservations_expires ON public.budget_reservations USING btree (expires_at) WHERE (status = 'held'::text)","idx_chat_usage_log_created": "CREATE INDEX idx_chat_usage_log_created ON public.chat_usage_log USING btree (created_at)",@@ -1746,6 +1768,7 @@"facts_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=facts.id","files_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=files.id","graph_generation_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-",+ "guest_promotions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=guest_promotions.id","ingest_log_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=ingest_log.id","link_edge_proposals_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_edge_proposals.id","link_transitions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_transitions.id",@@ -2800,6 +2823,44 @@],"flags": "relkind=r rls=true force_rls=false"},+ "guest_marks": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 slug_at_write text/text NOT NULL",+ "4 audience_member text/text NOT NULL",+ "5 group_slug text/text NOT NULL",+ "6 sender_label text/text NOT NULL",+ "7 saved_at timestamp with time zone/timestamptz NOT NULL",+ "8 writer_kind text/text NOT NULL",+ "9 writer_id text/text NOT NULL",+ "10 request_id text/text NULL",+ "11 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_promotions": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('guest_promotions_id_seq'::regclass)",+ "2 guest_page_id integer/int4 NOT NULL",+ "3 target_source_id text/text NOT NULL",+ "4 target_slug text/text NOT NULL",+ "5 promoted_by_kind text/text NOT NULL",+ "6 promoted_by_id text/text NOT NULL",+ "7 promoted_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",+ "8 request_id text/text NULL"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_sources": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 writers ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "3 trust_ceiling text/text NOT NULL DEFAULT 'external_untrusted'::text",+ "4 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"ingest_applied_captures": {"columns": ["1 idempotency_key text/text NOT NULL",@@ -4718,6 +4779,8 @@"facts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.facts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","facts.trust_generation_update": "CREATE CONSTRAINT TRIGGER trust_generation_update AFTER UPDATE ON public.facts DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((old.trust_tier IS DISTINCT FROM new.trust_tier)) EXECUTE FUNCTION gbrain_bump_trust_generation()","facts.trust_tier_stamp": "CREATE TRIGGER trust_tier_stamp BEFORE INSERT OR UPDATE ON public.facts FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_trust_tier()",+ "guest_marks.guest_marks_immutable": "CREATE TRIGGER guest_marks_immutable BEFORE UPDATE ON public.guest_marks FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()",+ "guest_sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE INSERT OR UPDATE OF source_id ON public.guest_sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","minion_jobs.minion_job_notify": "CREATE TRIGGER minion_job_notify AFTER INSERT OR UPDATE OF status ON public.minion_jobs FOR EACH ROW EXECUTE FUNCTION notify_minion_job_change()","minion_jobs.minion_queue_protocol": "CREATE TRIGGER minion_queue_protocol BEFORE INSERT OR UPDATE ON public.minion_jobs FOR EACH ROW EXECUTE FUNCTION enforce_minion_queue_protocol()","needs_rederive.trust_generation_insert": "CREATE CONSTRAINT TRIGGER trust_generation_insert AFTER INSERT ON public.needs_rederive DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (true) EXECUTE FUNCTION gbrain_bump_trust_generation()",@@ -4762,6 +4825,7 @@"sources.git_canonical_sources_count_delete": "CREATE TRIGGER git_canonical_sources_count_delete AFTER DELETE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_insert": "CREATE TRIGGER git_canonical_sources_count_insert AFTER INSERT ON public.sources FOR EACH ROW WHEN (((new.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_update": "CREATE TRIGGER git_canonical_sources_count_update AFTER UPDATE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) IS DISTINCT FROM (new.config ->> 'canonical'::text))) EXECUTE FUNCTION gbrain_count_git_canonical_sources()",+ "sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE UPDATE OF local_path ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","sources.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.tags_knowledge_revision": "CREATE TRIGGER tags_knowledge_revision AFTER INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_advance_tag_revision()",diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.jsonindex 6766aa60da..04ac228b32 100644--- a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json+++ b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json@@ -167,6 +167,13 @@"git_canonical_brain.git_canonical_brain_pkey": "p PRIMARY KEY (singleton)","git_canonical_brain.git_canonical_brain_singleton_check": "c CHECK ((singleton = 1))","git_canonical_brain.git_canonical_brain_strict_sources_check": "c CHECK ((strict_sources >= 0))",+ "guest_marks.guest_marks_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_marks.guest_marks_pkey": "p PRIMARY KEY (page_id)",+ "guest_promotions.guest_promotions_guest_page_id_fkey": "f FOREIGN KEY (guest_page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_promotions.guest_promotions_pkey": "p PRIMARY KEY (id)",+ "guest_sources.guest_sources_pkey": "p PRIMARY KEY (source_id)",+ "guest_sources.guest_sources_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "guest_sources.guest_sources_trust_ceiling_check": "c CHECK ((trust_ceiling = ANY (ARRAY['user_confirmed'::text, 'operator_curated'::text, 'tool_observed'::text, 'agent_written'::text, 'unknown'::text, 'external_untrusted'::text])))","ingest_applied_captures.ingest_applied_captures_pkey": "p PRIMARY KEY (idempotency_key)","ingest_log.ingest_log_pkey": "p PRIMARY KEY (id)","link_edge_proposals.link_edge_proposals_a_to_page_id_fkey": "f FOREIGN KEY (a_to_page_id) REFERENCES pages(id) ON DELETE CASCADE",@@ -632,6 +639,7 @@"gbrain_graduation_fence()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=cd4642fe8deee2a3c14ef41f53862f0a449b2d8a10e47177bd4f5d2e05ce8803","gbrain_guard_deferred_request()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=edf066d51ee76d4037663393271883a12d7fdf4f0f01b7d1faa9e979d552c6c6","gbrain_guard_effect_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=aa01528006dd7029eac6808e0233991524c9de9dc14aaf41f44160d67a747042",+ "gbrain_guard_guest_records()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0618c22ca97887e3333e0543478e7e97ecba3ba3c678f6d803a1e6df0900b163","gbrain_guard_inserted_facts()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=78fe53917ec54c7627df4961a7669e0d65f8adfa7e249da1beeb58dc37978a66","gbrain_guard_protocol_activation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=bb477ec66ecac06e6edba773a94a2834ef4286a0b9e5cfa8b9b8646e003b0b9e","gbrain_guard_request_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2709686143e064b577e2b3c8e3e2b1009d52a836a2bc709f5f003a251eb004d2",@@ -649,7 +657,7 @@"gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0aa697992ad1777eaba4a1f4d2325dc4f2a98f3ebf9e81325d1b068406ce1cb","gbrain_stamp_revision_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d446ed1145d8bb9c93cb0ca4aa076a5dc7a5fe07b3e79518adaf1b17b0a51216",- "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4610c2e064a0d34dbb66981dd49f15fb6b0b85407327983cde76b905cd626598",+ "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=8dd3e1a4575fe8d2844a4430d0e66ceb122265ef161f9cecefa3a3edf06a6e5b","gbrain_stamp_version_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=1f8fcf3492a9276c52541f6d353d6c709a123b6db4c84bb9a60d77a82fa1672f","gbrain_stamp_write_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e2dbafe65571fedcadc0441415f58fb5b5209b4c9cefa50e4855f58f0452327c","gbrain_try_jsonb(input text)": "RETURNS jsonb kind=f lang=plpgsql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=11b96a0400158fcb3dbd84255985cd11e473688c53fff64ebf92602fceccbedf",@@ -850,6 +858,15 @@"git_canonical_brain": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "guest_marks": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_promotions": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_sources": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"ingest_applied_captures": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1331,6 +1348,11 @@"files_storage_path_key": "CREATE UNIQUE INDEX files_storage_path_key ON public.files USING btree (storage_path)","gbrain_cycle_locks_pkey": "CREATE UNIQUE INDEX gbrain_cycle_locks_pkey ON public.gbrain_cycle_locks USING btree (id)","git_canonical_brain_pkey": "CREATE UNIQUE INDEX git_canonical_brain_pkey ON public.git_canonical_brain USING btree (singleton)",+ "guest_marks_audience_saved_idx": "CREATE INDEX guest_marks_audience_saved_idx ON public.guest_marks USING btree (audience_member, saved_at)",+ "guest_marks_pkey": "CREATE UNIQUE INDEX guest_marks_pkey ON public.guest_marks USING btree (page_id)",+ "guest_promotions_guest_page_idx": "CREATE INDEX guest_promotions_guest_page_idx ON public.guest_promotions USING btree (guest_page_id)",+ "guest_promotions_pkey": "CREATE UNIQUE INDEX guest_promotions_pkey ON public.guest_promotions USING btree (id)",+ "guest_sources_pkey": "CREATE UNIQUE INDEX guest_sources_pkey ON public.guest_sources USING btree (source_id)","idx_access_tokens_hash": "CREATE INDEX idx_access_tokens_hash ON public.access_tokens USING btree (token_hash) WHERE (revoked_at IS NULL)","idx_budget_reservations_expires": "CREATE INDEX idx_budget_reservations_expires ON public.budget_reservations USING btree (expires_at) WHERE (status = 'held'::text)","idx_chat_usage_log_created": "CREATE INDEX idx_chat_usage_log_created ON public.chat_usage_log USING btree (created_at)",@@ -1746,6 +1768,7 @@"facts_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=facts.id","files_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=files.id","graph_generation_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-",+ "guest_promotions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=guest_promotions.id","ingest_log_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=ingest_log.id","link_edge_proposals_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_edge_proposals.id","link_transitions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_transitions.id",@@ -2800,6 +2823,44 @@],"flags": "relkind=r rls=true force_rls=false"},+ "guest_marks": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 slug_at_write text/text NOT NULL",+ "4 audience_member text/text NOT NULL",+ "5 group_slug text/text NOT NULL",+ "6 sender_label text/text NOT NULL",+ "7 saved_at timestamp with time zone/timestamptz NOT NULL",+ "8 writer_kind text/text NOT NULL",+ "9 writer_id text/text NOT NULL",+ "10 request_id text/text NULL",+ "11 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_promotions": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('guest_promotions_id_seq'::regclass)",+ "2 guest_page_id integer/int4 NOT NULL",+ "3 target_source_id text/text NOT NULL",+ "4 target_slug text/text NOT NULL",+ "5 promoted_by_kind text/text NOT NULL",+ "6 promoted_by_id text/text NOT NULL",+ "7 promoted_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",+ "8 request_id text/text NULL"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_sources": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 writers ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "3 trust_ceiling text/text NOT NULL DEFAULT 'external_untrusted'::text",+ "4 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"ingest_applied_captures": {"columns": ["1 idempotency_key text/text NOT NULL",@@ -4718,6 +4779,8 @@"facts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.facts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","facts.trust_generation_update": "CREATE CONSTRAINT TRIGGER trust_generation_update AFTER UPDATE ON public.facts DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((old.trust_tier IS DISTINCT FROM new.trust_tier)) EXECUTE FUNCTION gbrain_bump_trust_generation()","facts.trust_tier_stamp": "CREATE TRIGGER trust_tier_stamp BEFORE INSERT OR UPDATE ON public.facts FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_trust_tier()",+ "guest_marks.guest_marks_immutable": "CREATE TRIGGER guest_marks_immutable BEFORE UPDATE ON public.guest_marks FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()",+ "guest_sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE INSERT OR UPDATE OF source_id ON public.guest_sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","minion_jobs.minion_job_notify": "CREATE TRIGGER minion_job_notify AFTER INSERT OR UPDATE OF status ON public.minion_jobs FOR EACH ROW EXECUTE FUNCTION notify_minion_job_change()","minion_jobs.minion_queue_protocol": "CREATE TRIGGER minion_queue_protocol BEFORE INSERT OR UPDATE ON public.minion_jobs FOR EACH ROW EXECUTE FUNCTION enforce_minion_queue_protocol()","needs_rederive.trust_generation_insert": "CREATE CONSTRAINT TRIGGER trust_generation_insert AFTER INSERT ON public.needs_rederive DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (true) EXECUTE FUNCTION gbrain_bump_trust_generation()",@@ -4762,6 +4825,7 @@"sources.git_canonical_sources_count_delete": "CREATE TRIGGER git_canonical_sources_count_delete AFTER DELETE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_insert": "CREATE TRIGGER git_canonical_sources_count_insert AFTER INSERT ON public.sources FOR EACH ROW WHEN (((new.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_update": "CREATE TRIGGER git_canonical_sources_count_update AFTER UPDATE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) IS DISTINCT FROM (new.config ->> 'canonical'::text))) EXECUTE FUNCTION gbrain_count_git_canonical_sources()",+ "sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE UPDATE OF local_path ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","sources.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.tags_knowledge_revision": "CREATE TRIGGER tags_knowledge_revision AFTER INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_advance_tag_revision()",diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.jsonindex 9c63a6ad9a..d403c2fae3 100644--- a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json+++ b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json@@ -167,6 +167,13 @@"git_canonical_brain.git_canonical_brain_pkey": "p PRIMARY KEY (singleton)","git_canonical_brain.git_canonical_brain_singleton_check": "c CHECK ((singleton = 1))","git_canonical_brain.git_canonical_brain_strict_sources_check": "c CHECK ((strict_sources >= 0))",+ "guest_marks.guest_marks_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_marks.guest_marks_pkey": "p PRIMARY KEY (page_id)",+ "guest_promotions.guest_promotions_guest_page_id_fkey": "f FOREIGN KEY (guest_page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_promotions.guest_promotions_pkey": "p PRIMARY KEY (id)",+ "guest_sources.guest_sources_pkey": "p PRIMARY KEY (source_id)",+ "guest_sources.guest_sources_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "guest_sources.guest_sources_trust_ceiling_check": "c CHECK ((trust_ceiling = ANY (ARRAY['user_confirmed'::text, 'operator_curated'::text, 'tool_observed'::text, 'agent_written'::text, 'unknown'::text, 'external_untrusted'::text])))","ingest_applied_captures.ingest_applied_captures_pkey": "p PRIMARY KEY (idempotency_key)","ingest_log.ingest_log_pkey": "p PRIMARY KEY (id)","link_edge_proposals.link_edge_proposals_a_to_page_id_fkey": "f FOREIGN KEY (a_to_page_id) REFERENCES pages(id) ON DELETE CASCADE",@@ -632,6 +639,7 @@"gbrain_graduation_fence()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=cd4642fe8deee2a3c14ef41f53862f0a449b2d8a10e47177bd4f5d2e05ce8803","gbrain_guard_deferred_request()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=edf066d51ee76d4037663393271883a12d7fdf4f0f01b7d1faa9e979d552c6c6","gbrain_guard_effect_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=aa01528006dd7029eac6808e0233991524c9de9dc14aaf41f44160d67a747042",+ "gbrain_guard_guest_records()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0618c22ca97887e3333e0543478e7e97ecba3ba3c678f6d803a1e6df0900b163","gbrain_guard_inserted_facts()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=78fe53917ec54c7627df4961a7669e0d65f8adfa7e249da1beeb58dc37978a66","gbrain_guard_protocol_activation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=bb477ec66ecac06e6edba773a94a2834ef4286a0b9e5cfa8b9b8646e003b0b9e","gbrain_guard_request_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2709686143e064b577e2b3c8e3e2b1009d52a836a2bc709f5f003a251eb004d2",@@ -649,7 +657,7 @@"gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0aa697992ad1777eaba4a1f4d2325dc4f2a98f3ebf9e81325d1b068406ce1cb","gbrain_stamp_revision_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d446ed1145d8bb9c93cb0ca4aa076a5dc7a5fe07b3e79518adaf1b17b0a51216",- "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4610c2e064a0d34dbb66981dd49f15fb6b0b85407327983cde76b905cd626598",+ "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=8dd3e1a4575fe8d2844a4430d0e66ceb122265ef161f9cecefa3a3edf06a6e5b","gbrain_stamp_version_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=1f8fcf3492a9276c52541f6d353d6c709a123b6db4c84bb9a60d77a82fa1672f","gbrain_stamp_write_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e2dbafe65571fedcadc0441415f58fb5b5209b4c9cefa50e4855f58f0452327c","gbrain_try_jsonb(input text)": "RETURNS jsonb kind=f lang=plpgsql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=11b96a0400158fcb3dbd84255985cd11e473688c53fff64ebf92602fceccbedf",@@ -850,6 +858,15 @@"git_canonical_brain": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "guest_marks": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_promotions": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_sources": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"ingest_applied_captures": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1331,6 +1348,11 @@"files_storage_path_key": "CREATE UNIQUE INDEX files_storage_path_key ON public.files USING btree (storage_path)","gbrain_cycle_locks_pkey": "CREATE UNIQUE INDEX gbrain_cycle_locks_pkey ON public.gbrain_cycle_locks USING btree (id)","git_canonical_brain_pkey": "CREATE UNIQUE INDEX git_canonical_brain_pkey ON public.git_canonical_brain USING btree (singleton)",+ "guest_marks_audience_saved_idx": "CREATE INDEX guest_marks_audience_saved_idx ON public.guest_marks USING btree (audience_member, saved_at)",+ "guest_marks_pkey": "CREATE UNIQUE INDEX guest_marks_pkey ON public.guest_marks USING btree (page_id)",+ "guest_promotions_guest_page_idx": "CREATE INDEX guest_promotions_guest_page_idx ON public.guest_promotions USING btree (guest_page_id)",+ "guest_promotions_pkey": "CREATE UNIQUE INDEX guest_promotions_pkey ON public.guest_promotions USING btree (id)",+ "guest_sources_pkey": "CREATE UNIQUE INDEX guest_sources_pkey ON public.guest_sources USING btree (source_id)","idx_access_tokens_hash": "CREATE INDEX idx_access_tokens_hash ON public.access_tokens USING btree (token_hash) WHERE (revoked_at IS NULL)","idx_budget_reservations_expires": "CREATE INDEX idx_budget_reservations_expires ON public.budget_reservations USING btree (expires_at) WHERE (status = 'held'::text)","idx_chat_usage_log_created": "CREATE INDEX idx_chat_usage_log_created ON public.chat_usage_log USING btree (created_at)",@@ -1742,6 +1764,7 @@"facts_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=facts.id","files_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=files.id","graph_generation_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-",+ "guest_promotions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=guest_promotions.id","ingest_log_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=ingest_log.id","link_edge_proposals_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_edge_proposals.id","link_transitions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_transitions.id",@@ -2796,6 +2819,44 @@],"flags": "relkind=r rls=true force_rls=false"},+ "guest_marks": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 slug_at_write text/text NOT NULL",+ "4 audience_member text/text NOT NULL",+ "5 group_slug text/text NOT NULL",+ "6 sender_label text/text NOT NULL",+ "7 saved_at timestamp with time zone/timestamptz NOT NULL",+ "8 writer_kind text/text NOT NULL",+ "9 writer_id text/text NOT NULL",+ "10 request_id text/text NULL",+ "11 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_promotions": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('guest_promotions_id_seq'::regclass)",+ "2 guest_page_id integer/int4 NOT NULL",+ "3 target_source_id text/text NOT NULL",+ "4 target_slug text/text NOT NULL",+ "5 promoted_by_kind text/text NOT NULL",+ "6 promoted_by_id text/text NOT NULL",+ "7 promoted_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",+ "8 request_id text/text NULL"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_sources": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 writers ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "3 trust_ceiling text/text NOT NULL DEFAULT 'external_untrusted'::text",+ "4 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"ingest_applied_captures": {"columns": ["1 idempotency_key text/text NOT NULL",@@ -4714,6 +4775,8 @@"facts.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.facts FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","facts.trust_generation_update": "CREATE CONSTRAINT TRIGGER trust_generation_update AFTER UPDATE ON public.facts DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((old.trust_tier IS DISTINCT FROM new.trust_tier)) EXECUTE FUNCTION gbrain_bump_trust_generation()","facts.trust_tier_stamp": "CREATE TRIGGER trust_tier_stamp BEFORE INSERT OR UPDATE ON public.facts FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_trust_tier()",+ "guest_marks.guest_marks_immutable": "CREATE TRIGGER guest_marks_immutable BEFORE UPDATE ON public.guest_marks FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()",+ "guest_sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE INSERT OR UPDATE OF source_id ON public.guest_sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","minion_jobs.minion_job_notify": "CREATE TRIGGER minion_job_notify AFTER INSERT OR UPDATE OF status ON public.minion_jobs FOR EACH ROW EXECUTE FUNCTION notify_minion_job_change()","minion_jobs.minion_queue_protocol": "CREATE TRIGGER minion_queue_protocol BEFORE INSERT OR UPDATE ON public.minion_jobs FOR EACH ROW EXECUTE FUNCTION enforce_minion_queue_protocol()","needs_rederive.trust_generation_insert": "CREATE CONSTRAINT TRIGGER trust_generation_insert AFTER INSERT ON public.needs_rederive DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN (true) EXECUTE FUNCTION gbrain_bump_trust_generation()",@@ -4758,6 +4821,7 @@"sources.git_canonical_sources_count_delete": "CREATE TRIGGER git_canonical_sources_count_delete AFTER DELETE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_insert": "CREATE TRIGGER git_canonical_sources_count_insert AFTER INSERT ON public.sources FOR EACH ROW WHEN (((new.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_update": "CREATE TRIGGER git_canonical_sources_count_update AFTER UPDATE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) IS DISTINCT FROM (new.config ->> 'canonical'::text))) EXECUTE FUNCTION gbrain_count_git_canonical_sources()",+ "sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE UPDATE OF local_path ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","sources.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.tags_knowledge_revision": "CREATE TRIGGER tags_knowledge_revision AFTER INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_advance_tag_revision()",diff --git a/test/fixtures/goldens/doctor/json-pglite-degraded.json b/test/fixtures/goldens/doctor/json-pglite-degraded.jsonindex 534415ee7a..5ac896df53 100644--- a/test/fixtures/goldens/doctor/json-pglite-degraded.json+++ b/test/fixtures/goldens/doctor/json-pglite-degraded.json@@ -1116,7 +1116,7 @@{"category": "meta","elapsed_ms": "<volatile>",- "message": "All 179 table(s) the applied migrations create exist.",+ "message": "All 182 table(s) the applied migrations create exist.","name": "schema_missing_tables","status": "ok"},diff --git a/test/fixtures/goldens/doctor/json-pglite-fresh.json b/test/fixtures/goldens/doctor/json-pglite-fresh.jsonindex a41c98640d..2d5a3203dd 100644--- a/test/fixtures/goldens/doctor/json-pglite-fresh.json+++ b/test/fixtures/goldens/doctor/json-pglite-fresh.json@@ -1163,7 +1163,7 @@{"category": "meta","elapsed_ms": "<volatile>",- "message": "All 179 table(s) the applied migrations create exist.",+ "message": "All 182 table(s) the applied migrations create exist.","name": "schema_missing_tables","status": "ok"},diff --git a/test/fixtures/goldens/doctor/json-postgres-fresh.json b/test/fixtures/goldens/doctor/json-postgres-fresh.jsonindex 0967acc272..fadedf9ad3 100644--- a/test/fixtures/goldens/doctor/json-postgres-fresh.json+++ b/test/fixtures/goldens/doctor/json-postgres-fresh.json@@ -1124,7 +1124,7 @@{"category": "ops","elapsed_ms": "<volatile>",- "message": "RLS enabled on 178/178 public tables",+ "message": "RLS enabled on 181/181 public tables","name": "rls","status": "ok"},@@ -1166,7 +1166,7 @@{"category": "meta","elapsed_ms": "<volatile>",- "message": "All 178 table(s) the applied migrations create exist.",+ "message": "All 181 table(s) the applied migrations create exist.","name": "schema_missing_tables","status": "ok"},diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.jsonindex 2399550e15..f09c2a154d 100644--- a/test/fixtures/goldens/migrations/records.json+++ b/test/fixtures/goldens/migrations/records.json@@ -1,11 +1,12 @@{"golden": {- "count": 305,+ "count": 306,"gaps": [17,18,19,- 100+ 100,+ 311],"helpers": {"ALIAS_TABLES": "cddd37c636af42d862c08ca7754a57dfe9d12576b769fa8f74a5f02c803f67a0",@@ -100,7 +101,7 @@"widenIdentityIndex": "86a6176bd7637d964dbc1d3cd3b1bdfa3ca0161e1ee248c37d7380a1471282e6","withSchemaLockTimeout": "95605bd3004955e11e936c7a4aa6889319b401098abf9db18ef3e48da2c3fc59"},- "latest": 310,+ "latest": 312,"records": [{"handler": {@@ -5031,6 +5032,19 @@"transaction": "absent","verify": "absent","version": 310+ },+ {+ "handler": "absent",+ "idempotent": true,+ "name": "guest_notes",+ "sql": {+ "length": 17488,+ "sha256": "14c2cc406663fe8ba02179dc31b47c43ea9dbfb9788d4a94ac3c0c7cff4f20e6"+ },+ "sqlFor": "absent",+ "transaction": "absent",+ "verify": "absent",+ "version": 312}],"versions": [@@ -5338,7 +5352,8 @@307,308,309,- 310+ 310,+ 312]},"normalizer": "migrations-record-v1"diff --git a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.jsonindex 88dfd2a9a0..5bf7e8a5d2 100644--- a/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json+++ b/test/fixtures/goldens/pglite-upgrade-replay/catalog-after-boot.json@@ -164,6 +164,13 @@"git_canonical_brain.git_canonical_brain_pkey": "p PRIMARY KEY (singleton)","git_canonical_brain.git_canonical_brain_singleton_check": "c CHECK ((singleton = 1))","git_canonical_brain.git_canonical_brain_strict_sources_check": "c CHECK ((strict_sources >= 0))",+ "guest_marks.guest_marks_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_marks.guest_marks_pkey": "p PRIMARY KEY (page_id)",+ "guest_promotions.guest_promotions_guest_page_id_fkey": "f FOREIGN KEY (guest_page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "guest_promotions.guest_promotions_pkey": "p PRIMARY KEY (id)",+ "guest_sources.guest_sources_pkey": "p PRIMARY KEY (source_id)",+ "guest_sources.guest_sources_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "guest_sources.guest_sources_trust_ceiling_check": "c CHECK ((trust_ceiling = ANY (ARRAY['user_confirmed'::text, 'operator_curated'::text, 'tool_observed'::text, 'agent_written'::text, 'unknown'::text, 'external_untrusted'::text])))","ingest_applied_captures.ingest_applied_captures_pkey": "p PRIMARY KEY (idempotency_key)","ingest_log.ingest_log_pkey": "p PRIMARY KEY (id)","link_edge_proposals.link_edge_proposals_a_to_page_id_fkey": "f FOREIGN KEY (a_to_page_id) REFERENCES pages(id) ON DELETE CASCADE",@@ -629,6 +636,7 @@"gbrain_graduation_fence()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=cd4642fe8deee2a3c14ef41f53862f0a449b2d8a10e47177bd4f5d2e05ce8803","gbrain_guard_deferred_request()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=edf066d51ee76d4037663393271883a12d7fdf4f0f01b7d1faa9e979d552c6c6","gbrain_guard_effect_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=aa01528006dd7029eac6808e0233991524c9de9dc14aaf41f44160d67a747042",+ "gbrain_guard_guest_records()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=0618c22ca97887e3333e0543478e7e97ecba3ba3c678f6d803a1e6df0900b163","gbrain_guard_inserted_facts()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=78fe53917ec54c7627df4961a7669e0d65f8adfa7e249da1beeb58dc37978a66","gbrain_guard_protocol_activation()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=bb477ec66ecac06e6edba773a94a2834ef4286a0b9e5cfa8b9b8646e003b0b9e","gbrain_guard_request_protocol()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=2709686143e064b577e2b3c8e3e2b1009d52a836a2bc709f5f003a251eb004d2",@@ -646,7 +654,7 @@"gbrain_require_persistence_protocol(required integer)": "RETURNS void kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=af07b7fac60dec0a4fe568217931ac449d32f73b3a53a047b3b02a5f59cb5058","gbrain_snapshot_version_trust()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=a0aa697992ad1777eaba4a1f4d2325dc4f2a98f3ebf9e81325d1b068406ce1cb","gbrain_stamp_revision_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=d446ed1145d8bb9c93cb0ca4aa076a5dc7a5fe07b3e79518adaf1b17b0a51216",- "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=4610c2e064a0d34dbb66981dd49f15fb6b0b85407327983cde76b905cd626598",+ "gbrain_stamp_trust_tier()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=8dd3e1a4575fe8d2844a4430d0e66ceb122265ef161f9cecefa3a3edf06a6e5b","gbrain_stamp_version_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=1f8fcf3492a9276c52541f6d353d6c709a123b6db4c84bb9a60d77a82fa1672f","gbrain_stamp_write_attribution()": "RETURNS trigger kind=f lang=plpgsql volatility=v secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=e2dbafe65571fedcadc0441415f58fb5b5209b4c9cefa50e4855f58f0452327c","gbrain_try_jsonb(input text)": "RETURNS jsonb kind=f lang=plpgsql volatility=i secdef=false config=[search_path=pg_catalog, public, pg_temp] body_sha256=11b96a0400158fcb3dbd84255985cd11e473688c53fff64ebf92602fceccbedf",@@ -843,6 +851,15 @@"git_canonical_brain": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "guest_marks": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_promotions": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "guest_sources": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"ingest_applied_captures": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1329,6 +1346,11 @@"files_storage_path_key": "CREATE UNIQUE INDEX files_storage_path_key ON public.files USING btree (storage_path)","gbrain_cycle_locks_pkey": "CREATE UNIQUE INDEX gbrain_cycle_locks_pkey ON public.gbrain_cycle_locks USING btree (id)","git_canonical_brain_pkey": "CREATE UNIQUE INDEX git_canonical_brain_pkey ON public.git_canonical_brain USING btree (singleton)",+ "guest_marks_audience_saved_idx": "CREATE INDEX guest_marks_audience_saved_idx ON public.guest_marks USING btree (audience_member, saved_at)",+ "guest_marks_pkey": "CREATE UNIQUE INDEX guest_marks_pkey ON public.guest_marks USING btree (page_id)",+ "guest_promotions_guest_page_idx": "CREATE INDEX guest_promotions_guest_page_idx ON public.guest_promotions USING btree (guest_page_id)",+ "guest_promotions_pkey": "CREATE UNIQUE INDEX guest_promotions_pkey ON public.guest_promotions USING btree (id)",+ "guest_sources_pkey": "CREATE UNIQUE INDEX guest_sources_pkey ON public.guest_sources USING btree (source_id)","idx_access_tokens_hash": "CREATE INDEX idx_access_tokens_hash ON public.access_tokens USING btree (token_hash) WHERE (revoked_at IS NULL)","idx_budget_reservations_expires": "CREATE INDEX idx_budget_reservations_expires ON public.budget_reservations USING btree (expires_at) WHERE (status = 'held'::text)","idx_chat_usage_log_created": "CREATE INDEX idx_chat_usage_log_created ON public.chat_usage_log USING btree (created_at)",@@ -1744,6 +1766,7 @@"facts_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=facts.id","files_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=files.id","graph_generation_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-",+ "guest_promotions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=guest_promotions.id","ingest_log_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=ingest_log.id","link_edge_proposals_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_edge_proposals.id","link_transitions_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=link_transitions.id",@@ -2788,6 +2811,44 @@],"flags": "relkind=r rls=true force_rls=false"},+ "guest_marks": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 slug_at_write text/text NOT NULL",+ "4 audience_member text/text NOT NULL",+ "5 group_slug text/text NOT NULL",+ "6 sender_label text/text NOT NULL",+ "7 saved_at timestamp with time zone/timestamptz NOT NULL",+ "8 writer_kind text/text NOT NULL",+ "9 writer_id text/text NOT NULL",+ "10 request_id text/text NULL",+ "11 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_promotions": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('guest_promotions_id_seq'::regclass)",+ "2 guest_page_id integer/int4 NOT NULL",+ "3 target_source_id text/text NOT NULL",+ "4 target_slug text/text NOT NULL",+ "5 promoted_by_kind text/text NOT NULL",+ "6 promoted_by_id text/text NOT NULL",+ "7 promoted_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()",+ "8 request_id text/text NULL"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "guest_sources": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 writers ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "3 trust_ceiling text/text NOT NULL DEFAULT 'external_untrusted'::text",+ "4 created_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"ingest_applied_captures": {"columns": ["1 idempotency_key text/text NOT NULL",@@ -4729,6 +4790,8 @@"facts.planner_stats_upd": "CREATE TRIGGER planner_stats_upd AFTER UPDATE ON public.facts REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","facts.trust_generation_update": "CREATE CONSTRAINT TRIGGER trust_generation_update AFTER UPDATE ON public.facts DEFERRABLE INITIALLY DEFERRED FOR EACH ROW WHEN ((old.trust_tier IS DISTINCT FROM new.trust_tier)) EXECUTE FUNCTION gbrain_bump_trust_generation()","facts.trust_tier_stamp": "CREATE TRIGGER trust_tier_stamp BEFORE INSERT OR UPDATE ON public.facts FOR EACH ROW EXECUTE FUNCTION gbrain_stamp_trust_tier()",+ "guest_marks.guest_marks_immutable": "CREATE TRIGGER guest_marks_immutable BEFORE UPDATE ON public.guest_marks FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()",+ "guest_sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE INSERT OR UPDATE OF source_id ON public.guest_sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","links.planner_stats_del": "CREATE TRIGGER planner_stats_del AFTER DELETE ON public.links REFERENCING OLD TABLE AS old_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","links.planner_stats_ins": "CREATE TRIGGER planner_stats_ins AFTER INSERT ON public.links REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()","links.planner_stats_upd": "CREATE TRIGGER planner_stats_upd AFTER UPDATE ON public.links REFERENCING NEW TABLE AS new_rows FOR EACH STATEMENT EXECUTE FUNCTION gbrain_count_modifications()",@@ -4778,6 +4841,7 @@"sources.git_canonical_sources_count_delete": "CREATE TRIGGER git_canonical_sources_count_delete AFTER DELETE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_insert": "CREATE TRIGGER git_canonical_sources_count_insert AFTER INSERT ON public.sources FOR EACH ROW WHEN (((new.config ->> 'canonical'::text) = 'git'::text)) EXECUTE FUNCTION gbrain_count_git_canonical_sources()","sources.git_canonical_sources_count_update": "CREATE TRIGGER git_canonical_sources_count_update AFTER UPDATE ON public.sources FOR EACH ROW WHEN (((old.config ->> 'canonical'::text) IS DISTINCT FROM (new.config ->> 'canonical'::text))) EXECUTE FUNCTION gbrain_count_git_canonical_sources()",+ "sources.guest_source_database_only": "CREATE TRIGGER guest_source_database_only BEFORE UPDATE OF local_path ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_guard_guest_records()","sources.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.sources FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.managed_writer_guard": "CREATE TRIGGER managed_writer_guard BEFORE INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_require_managed_writer()","tags.tags_knowledge_revision": "CREATE TRIGGER tags_knowledge_revision AFTER INSERT OR DELETE OR UPDATE ON public.tags FOR EACH ROW EXECUTE FUNCTION gbrain_advance_tag_revision()",diff --git a/test/graduation-inventory.test.ts b/test/graduation-inventory.test.tsindex 6c6987ef83..13cbb44003 100644--- a/test/graduation-inventory.test.ts+++ b/test/graduation-inventory.test.ts@@ -60,7 +60,7 @@ describe('graduation inventory', () => {expect(new Set(names).size).toBe(names.length);const counts: Record<string, number> = {};for (const e of GRADUATION_INVENTORY.entries) counts[e.class] = (counts[e.class] ?? 0) + 1;- expect(counts).toEqual({ carry: 163, rebind: 2, rebuild: 3, discard: 9, schema_owned: 4 });+ expect(counts).toEqual({ carry: 166, rebind: 2, rebuild: 3, discard: 9, schema_owned: 4 });for (const e of GRADUATION_INVENTORY.entries) {expect({ relation: e.relation, reason: e.reason.length > 5, present: e.engines.pglite || e.engines.postgres }).toEqual({ relation: e.relation, reason: true, present: true });@@ -69,7 +69,7 @@ describe('graduation inventory', () => {expect(expectedRelations('postgres').filter(r => !expectedRelations('pglite').includes(r))).toEqual(['file_migration_ledger']);expect(GRADUATION_INVENTORY.entries.filter(e => e.lossKind === 'security').map(e => e.relation).sort()).toEqual(['access_group_members', 'access_groups', 'access_member_links', 'access_member_sources', 'access_members', 'access_pending_coverage', 'access_policy_revisions',- 'access_policy_state', 'access_rules', 'access_tokens', 'oauth_clients', 'oauth_codes', 'oauth_grant_audit', 'oauth_tokens',+ 'access_policy_state', 'access_rules', 'access_tokens', 'guest_marks', 'guest_sources', 'oauth_clients', 'oauth_codes', 'oauth_grant_audit', 'oauth_tokens','page_label_guards', 'persistence_local_writers', 'shared_skill_state', 'slug_rename_history']);});diff --git a/test/guest-notes-schema.test.ts b/test/guest-notes-schema.test.tsnew file mode 100644index 0000000000..8bc1525183--- /dev/null+++ b/test/guest-notes-schema.test.ts@@ -0,0 +1,191 @@+/**+ * Guest notes, slice 1 (GBRA-504): the database records and source rules.+ *+ * Protects: migration v312's guest_sources, guest_marks and guest_promotions+ * tables (RLS on); guest_marks rows refuse UPDATE and leave with their page;+ * the trust trigger's per-source ceiling on pages (INSERT, owner-tier content+ * rewrite, the backfill INSERT and the promotion UPDATE branches); facts,+ * takes and timeline rows refused in a guest source; the writer backstop (a+ * page INSERT or content UPDATE in a guest source needs a principal on the+ * source's writer list, while soft delete, restore, purge and non-content+ * updates pass); a guest source refusing a local_path; and pages outside a+ * guest source keeping their behavior. Runs on PGLite, and on Postgres (direct+ * and transaction-mode PgBouncer) through test/e2e/guest-notes-postgres.test.ts.+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { randomUUID } from 'node:crypto';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import type { BrainEngine } from '../src/core/engine.ts';+import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';+import { testBackends } from './helpers/test-backends.ts';+import { withTrustBackfill, withTrustPromotion, withWriteAttribution } from '../src/core/persistence/context.ts';+import type { WriteAttribution } from '../src/core/persistence/attribution.ts';+import type { Principal } from '../src/core/persistence/model.ts';+import type { TrustTier } from '../src/core/trust/tier.ts';++interface Backend { name: string; engine: BrainEngine; close: () => Promise<void> }+const backends: Backend[] = [];+beforeAll(async () => {+ for (const name of testBackends()) {+ if (name === 'pglite') {+ const engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema();+ backends.push({ name, engine, close: () => engine.disconnect() });+ } else {+ const pg = await isolatedPersistencePostgres(process.env.DATABASE_URL!);+ backends.push({ name, engine: pg.engine, close: pg.close });+ }+ }+}, 180_000);+afterAll(async () => { for (const b of backends) await b.close(); });++const BROKER: Principal = { kind: 'oauth_client', id: 'client-a' };+const OTHER: Principal = { kind: 'oauth_client', id: 'client-b' };+const OWNER_CLI: Principal = { kind: 'local_cli', id: 'cli-a' };+const as = (principal: Principal, tier?: TrustTier): WriteAttribution =>+ ({ requestId: null, principal, ...(tier ? { trust: { tier, origin: { channel: 'test' } } } : {}) });+const writeAs = <T>(engine: BrainEngine, principal: Principal, tier: TrustTier | undefined, fn: (tx: BrainEngine) => Promise<T>) =>+ engine.transaction(tx => withWriteAttribution(tx, as(principal, tier), () => fn(tx)));++async function guestSource(engine: BrainEngine, writers: Principal[] = [BROKER]): Promise<string> {+ const id = `guests-${randomUUID().slice(0, 8)}`;+ await engine.executeRaw(`INSERT INTO sources(id,name,config) VALUES($1,$1,'{"federated":true,"guest":true}'::jsonb)`, [id]);+ await engine.executeRaw(`INSERT INTO guest_sources(source_id,writers) VALUES($1,$2::text[])`, [id, writers.map(p => `${p.kind}:${p.id}`)]);+ return id;+}+const insertPage = (db: BrainEngine, sourceId: string, slug = `guests/${randomUUID().slice(0, 8)}`, suppliedTier = '') =>+ db.executeRaw<{ id: number; slug: string; trust_tier: string }>(+ `INSERT INTO pages(slug,type,title,compiled_truth,source_id${suppliedTier ? ',trust_tier' : ''}) VALUES($1,'note','T','guest words',$2${suppliedTier ? `,'${suppliedTier}'` : ''}) RETURNING id, slug, trust_tier`,+ [slug, sourceId]).then(rows => rows[0]!);+const tierOf = async (engine: BrainEngine, id: number) =>+ (await engine.executeRaw<{ t: string }>('SELECT trust_tier AS t FROM pages WHERE id=$1', [id]))[0]!.t;+const failure = (promise: Promise<unknown>) => promise.then(() => null, (e: unknown) => String((e as Error)?.message ?? e));++for (const backendName of testBackends()) {+ const engineOf = () => backends.find(b => b.name === backendName)!.engine;++ describe(`guest notes schema (${backendName})`, () => {+ test('v312 creates the three tables with row-level security on', async () => {+ const rows = await engineOf().executeRaw<{ relname: string; relrowsecurity: boolean }>(+ `SELECT relname, relrowsecurity FROM pg_class WHERE relname = ANY($1::text[]) AND relkind = 'r' ORDER BY relname`,+ [['guest_marks', 'guest_promotions', 'guest_sources']]);+ expect(rows.map(r => r.relname)).toEqual(['guest_marks', 'guest_promotions', 'guest_sources']);+ const [role] = await engineOf().executeRaw<{ bypass: boolean }>(+ `SELECT EXISTS (SELECT 1 FROM pg_roles pr WHERE pg_has_role(current_user, pr.oid, 'USAGE') AND (pr.rolbypassrls OR pr.rolsuper)) AS bypass`);+ if (role!.bypass) expect(rows.every(r => r.relrowsecurity)).toBe(true);+ const [index] = await engineOf().executeRaw<{ def: string }>(+ `SELECT indexdef AS def FROM pg_indexes WHERE tablename = 'guest_marks' AND indexdef LIKE '%audience_member%'`);+ expect(index?.def).toContain('(audience_member, saved_at)');+ });++ test('a guest mark refuses UPDATE, survives soft delete and restore, and leaves with its page', async () => {+ const engine = engineOf();+ const source = await guestSource(engine);+ const page = await writeAs(engine, BROKER, 'agent_written', tx => insertPage(tx, source));+ await engine.executeRaw(`INSERT INTO guest_marks(page_id,source_id,slug_at_write,audience_member,group_slug,sender_label,saved_at,writer_kind,writer_id,request_id)+ VALUES($1,$2,$3,'bob-example','team-a','bob-example',now(),'oauth_client','client-a',NULL)`, [page.id, source, page.slug]);+ expect(await failure(engine.executeRaw(`UPDATE guest_marks SET sender_label='alice-example' WHERE page_id=$1`, [page.id]))).toMatch(/guest_mark_immutable/);+ expect(await engine.softDeletePage(page.slug, { sourceId: source })).toEqual({ slug: page.slug });+ expect(await engine.restorePage(page.slug, { sourceId: source })).toBe(true);+ const [mark] = await engine.executeRaw<{ sender_label: string }>('SELECT sender_label FROM guest_marks WHERE page_id=$1', [page.id]);+ expect(mark?.sender_label).toBe('bob-example');+ await engine.executeRaw('DELETE FROM pages WHERE id=$1', [page.id]);+ expect(await engine.executeRaw('SELECT 1 FROM guest_marks WHERE page_id=$1', [page.id])).toEqual([]);+ });++ test('a guest promotion row leaves with its guest page', async () => {+ const engine = engineOf();+ const source = await guestSource(engine);+ const page = await writeAs(engine, BROKER, 'agent_written', tx => insertPage(tx, source));+ await engine.executeRaw(`INSERT INTO guest_promotions(guest_page_id,target_source_id,target_slug,promoted_by_kind,promoted_by_id) VALUES($1,'default','notes/kept','local_cli','cli-a')`, [page.id]);+ await engine.executeRaw('DELETE FROM pages WHERE id=$1', [page.id]);+ expect(await engine.executeRaw('SELECT 1 FROM guest_promotions WHERE guest_page_id=$1', [page.id])).toEqual([]);+ });++ test('the ceiling caps a page INSERT and an owner-tier content rewrite', async () => {+ const engine = engineOf();+ const source = await guestSource(engine);+ const page = await writeAs(engine, BROKER, 'agent_written', tx => insertPage(tx, source));+ expect(page.trust_tier).toBe('external_untrusted');+ await writeAs(engine, BROKER, 'operator_curated', tx => tx.executeRaw(`UPDATE pages SET compiled_truth='rewritten' WHERE id=$1`, [page.id]));+ expect(await tierOf(engine, page.id)).toBe('external_untrusted');+ });++ test('the ceiling holds on the backfill INSERT and promotion UPDATE branches', async () => {+ const engine = engineOf();+ const source = await guestSource(engine);+ const copied = await engine.transaction(tx => withWriteAttribution(tx, as(BROKER), () =>+ withTrustBackfill(tx, () => insertPage(tx, source, undefined, 'operator_curated'))));+ expect(copied.trust_tier).toBe('external_untrusted');+ await engine.transaction(tx => withTrustPromotion(tx, 'operator_curated', () =>+ tx.executeRaw(`UPDATE pages SET trust_tier='operator_curated' WHERE id=$1`, [copied.id])));+ expect(await tierOf(engine, copied.id)).toBe('external_untrusted');+ });++ test('facts, takes and timeline rows are refused in a guest source; lifecycle updates of older rows pass', async () => {+ const engine = engineOf();+ const source = await guestSource(engine);+ const page = await writeAs(engine, BROKER, 'agent_written', tx => insertPage(tx, source));+ expect(await failure(writeAs(engine, BROKER, 'agent_written', tx => tx.executeRaw(+ `INSERT INTO facts(source_id,entity_slug,fact,kind,source) VALUES($1,'e','claim','fact','test')`, [source])))).toMatch(/guest_page_immutable/);+ expect(await failure(writeAs(engine, BROKER, 'agent_written', tx => tx.executeRaw(+ `INSERT INTO takes(page_id,row_num,claim,kind,holder,weight) VALUES($1,1,'c','take','world',0.5)`, [page.id])))).toMatch(/guest_page_immutable/);+ expect(await failure(writeAs(engine, BROKER, 'agent_written', tx => tx.executeRaw(+ `INSERT INTO timeline_entries(page_id,date,summary,detail,source) VALUES($1,'2026-01-01','s','d','x')`, [page.id])))).toMatch(/guest_page_immutable/);++ const later = `guests-${randomUUID().slice(0, 8)}`;+ await engine.executeRaw(`INSERT INTO sources(id,name) VALUES($1,$1)`, [later]);+ const [fact] = await engine.executeRaw<{ id: number }>(`INSERT INTO facts(source_id,entity_slug,fact,kind,source) VALUES($1,'e','older claim','fact','test') RETURNING id`, [later]);+ await engine.executeRaw(`INSERT INTO guest_sources(source_id) VALUES($1)`, [later]);+ await engine.executeRaw(`UPDATE facts SET expired_at=now() WHERE id=$1`, [fact!.id]);+ expect(await failure(engine.executeRaw(`UPDATE facts SET fact='changed' WHERE id=$1`, [fact!.id]))).toMatch(/guest_page_immutable/);+ });++ test('only a listed writer creates or rewrites a guest page', async () => {+ const engine = engineOf();+ const source = await guestSource(engine);+ expect(await failure(insertPage(engine, source))).toMatch(/source_writer_restricted/);+ expect(await failure(writeAs(engine, OTHER, 'agent_written', tx => insertPage(tx, source)))).toMatch(/source_writer_restricted/);+ expect(await failure(writeAs(engine, OWNER_CLI, 'operator_curated', tx => insertPage(tx, source)))).toMatch(/source_writer_restricted/);+ const page = await writeAs(engine, BROKER, 'agent_written', tx => insertPage(tx, source));+ expect(await failure(writeAs(engine, OWNER_CLI, 'operator_curated', tx =>+ tx.executeRaw(`UPDATE pages SET compiled_truth='owner rewrite' WHERE id=$1`, [page.id])))).toMatch(/source_writer_restricted/);+ expect(await failure(engine.executeRaw(`UPDATE pages SET frontmatter='{"trust_tier":"user_confirmed"}'::jsonb WHERE id=$1`, [page.id]))).toMatch(/source_writer_restricted/);+ expect(await failure(engine.executeRaw(`UPDATE pages SET source_id='default' WHERE id=$1`, [page.id]))).toMatch(/source_writer_restricted/);+ const outside = await insertPage(engine, 'default', `notes/${randomUUID().slice(0, 8)}`);+ expect(await failure(engine.executeRaw(`UPDATE pages SET source_id=$2 WHERE id=$1`, [outside.id, source]))).toMatch(/source_writer_restricted/);+ });++ test('soft delete, restore, purge and non-content updates of a guest page need no listed writer', async () => {+ const engine = engineOf();+ const source = await guestSource(engine);+ const page = await writeAs(engine, BROKER, 'agent_written', tx => insertPage(tx, source));+ expect(await engine.softDeletePage(page.slug, { sourceId: source })).toEqual({ slug: page.slug });+ expect(await engine.restorePage(page.slug, { sourceId: source })).toBe(true);+ await engine.executeRaw(`UPDATE pages SET updated_at=now(), frontmatter=frontmatter || '{"captured_at":"2026-02-02"}'::jsonb WHERE id=$1`, [page.id]);+ expect(await tierOf(engine, page.id)).toBe('external_untrusted');+ await engine.executeRaw('DELETE FROM pages WHERE id=$1', [page.id]);+ expect(await engine.executeRaw('SELECT 1 FROM pages WHERE id=$1', [page.id])).toEqual([]);+ });++ test('a guest source refuses a local_path', async () => {+ const engine = engineOf();+ const source = await guestSource(engine);+ expect(await failure(engine.executeRaw(`UPDATE sources SET local_path='/tmp/guests-a' WHERE id=$1`, [source]))).toMatch(/guest_source_database_only/);+ const pathed = `source-a-${randomUUID().slice(0, 8)}`;+ await engine.executeRaw(`INSERT INTO sources(id,name,local_path) VALUES($1,$1,'/tmp/source-a')`, [pathed]);+ expect(await failure(engine.executeRaw(`INSERT INTO guest_sources(source_id) VALUES($1)`, [pathed]))).toMatch(/guest_source_database_only/);+ });++ test('pages outside a guest source behave as before', async () => {+ const engine = engineOf();+ await guestSource(engine);+ const plain = await insertPage(engine, 'default', `notes/${randomUUID().slice(0, 8)}`);+ expect(plain.trust_tier).toBe('unknown');+ await writeAs(engine, OWNER_CLI, 'operator_curated', tx => tx.executeRaw(`UPDATE pages SET compiled_truth='owner edit' WHERE id=$1`, [plain.id]));+ expect(await tierOf(engine, plain.id)).toBe('operator_curated');+ const [fact] = await engine.executeRaw<{ id: number }>(`INSERT INTO facts(source_id,entity_slug,fact,kind,source) VALUES('default','e','claim','fact','test') RETURNING id`);+ expect(fact!.id).toBeGreaterThan(0);+ await engine.executeRaw(`INSERT INTO timeline_entries(page_id,date,summary,detail,source) VALUES($1,'2026-01-01','s','d','x')`, [plain.id]);+ });+ });+}