Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
F5 owner phrases: DB tests on both engines, ranking-invariance test, goldens, contract and key-files docs
garrytan7ed788571e59
diff --git a/docs/architecture/key-files/entity-recall.md b/docs/architecture/key-files/entity-recall.mdindex 6689a132d3..22d6aa489a 100644--- a/docs/architecture/key-files/entity-recall.md+++ b/docs/architecture/key-files/entity-recall.md@@ -11,6 +11,7 @@ card and `get_backlinks`. Guide: [entity recall](../../guides/entity-recall.md).- `src/core/mentions/aliases.ts` — derived names of an entity page, implementing `docs/designs/ALIAS_CONVENTIONS.md`. Stored aliases and card identity lines read declarations with `anchored: true` (a cue must attach to the page itself; search's per-result `aliasDeclarations` scan reads them all). `titleSubject` (text after the last `: `), `declarationsIn` (each declaration with its line: prose cues, label and value lines and table rows whose label names an alias field (also a label opening a later sentence of a line, alias noun within its first two words, at most 7 words), the quoted-only "calls it" cue, a quoted defined term right after the page's own name; a capture is a quoted name or a run of up to 4 capitalized or code tokens ending at punctuation, a lowercase word or the line end, rejected on a possessive, a run of only common words or a cue after a relational noun; linear in the line length), `declaredNames` (its post-filtered names, shared with search's `aliasDeclarations`), `deriveEntityAliases(page, {multiword, deny})` (subject `origin='subject'`, declarations `origin='declared'` with their lines, read from `publicBody`: private takes and facts fences stripped; a single-token declaration is `case_sensitive`; `mentions.alias_deny` and frontmatter `alias_deny` reject as `denied`). `aliasRejection`: under 4 characters (unless a short code the page declares for itself: a declaration marked `selfCode`), a generic word, or the first word of the page's own multi-word name. Rejections are returned with their line for explain. Tests: `test/mentions-policy-aliases.test.ts`.- `src/core/mentions/short-codes.ts` — `isShortCode` (2-3 letters or digits with a capital, not in `SHORT_CODE_STOPLIST` of common capitals and business acronyms, compared upper-cased). `declarationsIn` marks a short code `selfCode` when an alias label or an `also called` / `a.k.a.` / `known as` / `short for` cue declares it in a sentence naming nothing before the cue but the page (empty, a pronoun or an own name); `aliasRejection` lets it through and `by-mention.ts` keeps a `declared`, `case_sensitive` short code in the gazetteer, matched only as written. Leaf module (aliases.ts imports by-mention.ts). Tests: `test/mentions-policy-aliases.test.ts`, `test/mentions-pass.test.ts`.- `src/core/mentions/pass.ts` — `runMentionPass(engine, {sourceId?, deadline?, signal?, beforePublish?})`, run by `extractStaleFromDB` (unmanaged) and `extractManagedStaleLinks` (managed, unless `mentions: false`). Per source: policy off → `disableSource` deletes plain mention links (`link_kind` null or `plain`; `typed_ner` stays), derived alias rows, saved entries and page state once and records `disabled`; a changed policy fingerprint (types, cross-source flag, ignore list, `mentions.alias_deny`, `mentions.multiword_aliases`, `mentions.sibling_merge`) marks every page due and recounts `pending`; the status row's `policy_fingerprint` carries the extractor versions its count reflects after the hash (`<hash>;v<mention>.<alias>`, `INDEX_VERSION_STAMP`), and a stamp that differs from the binary's recounts `pending` once (version-behind pages are already due, so nothing is invalidated); `refreshAliases` rewrites derived rows of entity pages whose `page_mention_state.alias_revision`/`alias_version` differ (revision-checked, coordinated write when managed) and removes them from pages that stopped being entities; `buildGazetteer({strict: true})` failing writes nothing and records `failed`; `saveEntries` diffs `mention_gazetteer_entries` under `pg_advisory_xact_lock`, bumps the source generation and marks due only pages linking to a removed target plus pages a mini-gazetteer of added names matches (ASCII names prefiltered with `LIKE` on lower-cased text, others scanned in JS; a first save marks the source due); `reconcileSource` scans due pages (no state row, or `mention_revision`/`mention_version` differ) in batches of 200 and publishes only when the source generations (`FOR SHARE`) and each page's `knowledge_revision` (`FOR SHARE`) are unchanged, writing link diffs (`addLinksBatch`, audit site `extract.mentions`) and page state in one transaction; then the status row gets state, `pending` (`countIndexDuePages`: mention-due pages plus linkable entity pages whose derived aliases are behind their content or `ALIAS_DERIVATION_VERSION`, counted when the source finishes or the deadline stops it) and `last_pass_at`. `writeDerivedAliases` / `writePageAliases` are import's and `reindex --aliases`' alias projection. `MENTION_EXTRACTOR_VERSION` and `ALIAS_DERIVATION_VERSION` are independent of `LINK_EXTRACTOR_VERSION_TS`. The scanned text is title, compiled truth and timeline; frontmatter `mention_ignore` names are skipped per page. Tests: `test/mentions-pass.test.ts`, `test/mentions-coverage-version.test.ts`, `test/mentions-managed.test.ts`, `test/e2e/mentions-parity.test.ts`.+- `src/core/mentions/owner-phrase/` — owner-phrase resolution with validity windows behind `mentions.owner_phrases` (default off; contract: [owner phrases](../../guides/owner-phrases.md)). `scan.ts` stores per page (`owner_phrase_page_state`, keyed by `knowledge_revision` and `OWNER_PHRASE_SCAN_VERSION`) the cue lines, owner phrases, declared descriptors, the non-fallback page date and the belated-note readings; `dates.ts` parses written dates; `statements.ts` turns cue lines into dated takeover/join/ongoing/end/stint/correction statements (agent-written pages set none); `windows.ts` applies corrections, assembles per-identity-group windows with inclusive bounds and resolves a phrase (temporal candidates first, then ambiguity refusal, readings must agree). `pass.ts` `runOwnerPhrasePass`, called per source from `runMentionPass` after the plain reconcile, rebuilds windows into `owner_phrase_windows` (generation bumps only when the window hash changes; a window whose evidence includes a private page records `private_page_id`) and diffs `link_source='mentions'`, `link_kind='owner_phrase'` links under `pg_advisory_xact_lock`, storing a private evidence page as `origin_page_id`; a page pair another link covers gets none, and a plain mention displaces the row (`mentions/pass.ts`). Key off removes rows, windows, scans and status once. `known-as.ts` is the card's bounded `known_as` read (10 rows plus total, private windows hidden from untrusted readers); `ranking.ts` `rankingLinkSql` keeps owner-phrase links out of the readers that count every link (adjacency boosts, entity anchoring, generated-page demotion). Tests: `test/owner-phrase-rules.test.ts`, `test/owner-phrase-pass.test.ts`, `test/e2e/owner-phrase-parity.test.ts`.- `src/core/mentions/stale.ts` — the pass as a sweep phase: `previewMentionPass` (index-due pages per source, as `countIndexDuePages` counts them, and newest `last_pass_at`, for `--dry-run`, doctor `links_extraction_lag` and post-upgrade), `linkPhaseDeadline` (a budgeted sweep gives link work half its budget while mention-due pages exist), `formatMentionSummary`, `mentionJsonFields`.- `src/core/mentions/coverage.ts` — `readMentionCoverage(engine, sourceIds)`: `{state, pending_pages, last_pass_at, degraded?}` from `mention_index_status` plus due pages written at or after the row's `counted_at` (states `complete`, `pending`, `disabled`, `failed`; the card adds `type_not_linkable`). A row whose version stamp differs from the binary's (counted by another release) is recounted once with `countIndexDuePages` and the count and stamp saved on the row (compare-and-set on the stored fingerprint; a failed write still returns the count), so after a version bump every page behind `MENTION_EXTRACTOR_VERSION` or `ALIAS_DERIVATION_VERSION` reads as pending whatever its `updated_at`, and later reads stay one status read plus the recent-pages query. Policy settings changes are detected by the pass, not here. `mentionCoverageNotice` builds the `mention_index` notice (kind `degraded`, a per-call code): the free catch-up sweep for pending/failed, the user's setting for disabled/type-not-linkable, each with a read-only verify.- `src/core/mentions/referrers.ts` — the shared referrer query behind `referenced_by` and `get_backlinks {group:"page"}`: one row per referring page (every link source), semi-join over links to the target (plus identity co-members under `entity_identity.union`), canonical type via bound alias arrays, date `COALESCE(effective_date, updated_at)` with `date_source`, previews (160 characters after an optional `# ` heading, fences stripped, `redactFindings`). `readReferrerGroups`: per-type totals and a bounded top-10 per type, water-filled to 50 rows per card. `readReferrerPage`: keyset paging on `(date DESC, source_id, slug)` with an opaque cursor (microsecond UTC text). Untrusted scopes apply `privatePagesFilterFragment` to referrer and target and `privateLinkOriginFilterFragment` to the link, in rows and counts. #5575: quarantined referrers are left out (rows and counts) unless `includeQuarantined`, the scope's `eligibility` (`pageEligibleSql`) applies before LIMIT, and each row carries `trust_tier`, `origin` and `unconfirmed` from `trustFields`. Tests: `test/mentions-card-backlinks.test.ts`, `test/context-pack-newer-mentions.test.ts`, `test/entity-card-perf.slow.test.ts` (10,000-link hub gate).diff --git a/docs/guides/owner-phrases.md b/docs/guides/owner-phrases.mdindex 7f3f3069be..1e51c7d5a3 100644--- a/docs/guides/owner-phrases.md+++ b/docs/guides/owner-phrases.md@@ -28,8 +28,13 @@ owner-phrase link, window and page state on the next pass.A link is stored as an ordinary mention: `link_source='mentions'`,`link_kind='owner_phrase'`, `link_type='mentions'`, with the phrase as written-in `context`. Ranking readers ignore mention links, so owner-phrase links never-change search scores. Graph traversal, `get_backlinks` and the entity card's+in `context`. Owner-phrase links never change search scores. Most ranking+readers already skip mention links (backlink counts, relational chain hops and+typed degree, salience inbound counts). The three that count every link+(adjacency boosts, entity anchoring and generated-page demotion) skip+`link_kind='owner_phrase'` through `rankingLinkSql`+(`src/core/mentions/owner-phrase/ranking.ts`), so a brain's final scores are+the same with the key on or off. Graph traversal, `get_backlinks` and the entity card's`referenced_by` see them the same way they see plain mentions. A page pair thatanother link already connects gets no owner-phrase link. A plain mention foundlater replaces the owner-phrase row.@@ -46,29 +51,44 @@ The rules below are general to any brain. Each line is covered by a test row inin the title, compiled truth or timeline. They have one of these forms:- takeover: "B takes over / inherits / picks up / assumes X", "X moves / ishanded / is reassigned (from A) to B", "A hands X (off) to B", "B replaces A- on X", "B is now / becomes the owner (lead, AE, CSM) for X";- - join: "B joins X", "B has owned X since <date>". A join adds an owner- without ending anyone else's stint;- - ongoing: "B owns / runs / handles / covers / leads X", "B is the owner of- X", "X is owned by B", "X is B's account", and on an account page the label- lines `Owner:`, `Account owner:`, `Account lead:` and the same frontmatter- keys;+ on X", "B is now / becomes the owner (lead, AE, CSM) for X", "B will own /+ is going to own / is set to own X", and the label line "Outgoing A,+ incoming B";+ - join: "B joins X", "B has owned X since <date>", "B starts / started /+ began on (with, covering) X". A join adds an owner without ending anyone+ else's stint;+ - ongoing: "B owns / runs / handles / covers / leads X", "B has run / has+ owned / has handled X", "B is the owner of X", "X is owned by B", "X is B's+ account", and on an account page the label lines `Owner:`, `Account+ owner:`, `Account lead:` and the same frontmatter keys;- end: "A rolls off / steps away from / leaves / is no longer on X", "A'slast day on X is <date>";- stint: "A ran X from <date> to <date>", "A ran X until <date>";- tables whose header names an account column and an owner column, with- optional start and end columns.+ optional start and end columns, or Outgoing / Incoming / Effective+ columns (a handoff). A parenthesized cell is a note, not a value.++ An adverb after the owner ("actually", "officially", "formally", "also",+ "already", "effectively") does not change the form. In a chat line+ ("[09:14] Name: I'm picking up X"), first-person words mean the speaker.X is an account: a linkable entity page that is not a person, named by itstitle or alias, by "the <descriptor> account" when exactly one account has- that descriptor, or implicitly as the page itself on an account page.- Negated sentences, questions and hypothetical sentences ("might", "if",- "considering", "proposed") are not statements.+ that descriptor, or implicitly. An implicit account is the page itself on an+ account page, else the one account named on the statement's line, else the+ one account named across the page's ownership lines; with two or more, an+ implicit statement sets nothing. A form that begins with the account ("X+ moves from A to B") never takes the page implicitly. An account named in a+ statement that has no page competes in ambiguity (line 9) but is never+ stored or linked. Negated sentences, questions and hypothetical sentences+ ("might", "if", "considering", "proposed") are not statements.3. **Statement dates.** A date written in the sentence wins. Cue-led dates("starting", "effective", "as of", "from", "on") come first, then the firstdate after the verb, then the last date before it. A day-month date without- a year takes the year that puts it nearest the page date. With no date in- the sentence, the statement takes the page's own date. Only a non-fallback+ a year takes the year that puts it nearest the page date. An ongoing+ statement whose date follows a start cue ("since", "starting", "as of",+ "effective", "from") is a join from that date. With no date in the+ sentence, the statement takes the page's own date. Only a non-fallbackpage date counts (`effective_date_source` other than `fallback`). A relativedate with no written date ("next week", "soon") makes the statementundated. An undated statement sets no window.@@ -123,7 +143,8 @@ The rules below are general to any brain. Each line is covered by a test row in12. **Visibility.** A link whose window evidence includes a private page storesthat page as `origin_page_id`. Remote and world-scope readers apply thelink-origin privacy check and do not see the link. Trusted local reads do.- `known_as` rows on the card follow the same rule.+ `known_as` rows on the card follow the same rule. The card shows at most+ 10 `known_as` rows, newest window first, with the `total`.13. **Invalidation.** A page is rescanned when its content revision or theowner-phrase version changes. Windows are rebuilt from every page's storedstatements on each pass, and links are diffed against them. So a windowdiff --git a/test/e2e/owner-phrase-parity.test.ts b/test/e2e/owner-phrase-parity.test.tsnew file mode 100644index 0000000000..f20a9add40--- /dev/null+++ b/test/e2e/owner-phrase-parity.test.ts@@ -0,0 +1,94 @@+/**+ * Owner phrases: PGLite and Postgres parity (docs/guides/owner-phrases.md).+ *+ * Protects: the v240 migration (link_kind CHECK accepting 'owner_phrase',+ * the windowed tables) and the owner-phrase pass producing the same windows,+ * links, counters, visibility and `known_as` rows on both engines, plus a+ * correction, a deletion, disable, and two passes racing over a real+ * connection pool on Postgres (the advisory lock serializes publication).+ * Regression: an engine-specific SQL difference in the jsonb batch writes,+ * the date casts or the visibility predicate.+ *+ * Gated by DATABASE_URL (skips without it); the PGLite half always runs.+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import type { BrainEngine } from '../../src/core/engine.ts';+import { PGLiteEngine } from '../../src/core/pglite-engine.ts';+import { buildGazetteer } from '../../src/core/by-mention.ts';+import { linkableTypesFor, loadSourcePack, readMentionPolicy } from '../../src/core/mentions/policy.ts';+import { runOwnerPhrasePass } from '../../src/core/mentions/owner-phrase/pass.ts';+import { ACME, NIMBUS, doc, ownerPhraseLinks, ownerPhraseSnapshot, seedOwnerPhraseBrain, sweepOwnerPhrases, windowRows } from '../helpers/owner-phrase-brain.ts';+import { hasDatabase, setupDB, teardownDB } from './helpers.ts';++const SKIP_PG = !hasDatabase();+const describeBoth = SKIP_PG ? describe.skip : describe;++async function lifecycle(engine: BrainEngine) {+ const policy = await readMentionPolicy(engine);+ const pack = await loadSourcePack(engine, 'default', { strict: true });+ const opts = { sourceId: 'default', gazetteer: await buildGazetteer(engine, { policy, strict: true }), types: linkableTypesFor(pack, policy), pack, policy, enabled: true, deadline: Infinity };+ await doc(engine, 'updates/acme-correction', 'Correction: Acme Example Freight went to Juniper Example, not Quill.', { date: '2025-04-17' });+ await sweepOwnerPhrases(engine);+ const corrected = { links: await ownerPhraseLinks(engine), windows: await windowRows(engine) };+ await doc(engine, 'notes/new-call', "Juniper's freight account called about a claim.", { date: '2025-04-02' });+ const raced = await Promise.all([runOwnerPhrasePass(engine, opts), runOwnerPhrasePass(engine, opts)]);+ const afterRace = await ownerPhraseLinks(engine);+ await engine.softDeletePage('updates/acme-correction');+ await engine.softDeletePage('updates/acme-handoff');+ await sweepOwnerPhrases(engine);+ const deleted = await ownerPhraseLinks(engine);+ await engine.setConfig('mentions.owner_phrases', 'false');+ const disabled = await sweepOwnerPhrases(engine);+ return { corrected, raced: raced.map(r => [r.state, r.created]).sort(), afterRace, deleted, disabled: { state: disabled?.state, links: await ownerPhraseLinks(engine), windows: await windowRows(engine) } };+}++async function checkConstraint(engine: BrainEngine) {+ const [[a], [b]] = await Promise.all(['notes/undated', ACME].map(s => engine.executeRaw<{ id: number }>('SELECT id FROM pages WHERE slug = $1', [s])));+ const insert = (kind: string) => engine.executeRaw(`INSERT INTO links (from_page_id, to_page_id, link_type, link_source, link_kind) VALUES ($1, $2, 'probe', 'mentions', $3)`, [a!.id, b!.id, kind]);+ await insert('owner_phrase');+ await engine.executeRaw(`DELETE FROM links WHERE link_type = 'probe'`);+ return insert('bogus').then(() => 'accepted', () => 'refused');+}++let pglite: PGLiteEngine;+let pgliteSnap: Awaited<ReturnType<typeof ownerPhraseSnapshot>>;+let pgliteLife: Awaited<ReturnType<typeof lifecycle>>;+beforeAll(async () => {+ pglite = new PGLiteEngine();+ await pglite.connect({});+ await pglite.initSchema();+ await seedOwnerPhraseBrain(pglite);+ pgliteSnap = await ownerPhraseSnapshot(pglite);+ pgliteLife = await lifecycle(pglite);+}, 180_000);+afterAll(async () => { await pglite.disconnect(); });++describe('owner phrases (PGLite half)', () => {+ test('links, correction, race, deletion and disable produce the expected rows', () => {+ expect(pgliteSnap.trusted).toHaveLength(4);+ expect(pgliteLife.corrected.links).not.toContain(`notes/renewal -> ${ACME}`);+ expect(pgliteLife.raced).toEqual([['complete', 0], ['complete', 1]]);+ expect(pgliteLife.afterRace).toContain(`notes/new-call -> ${NIMBUS}`);+ expect(pgliteLife.deleted.filter(l => l.endsWith(ACME))).toEqual([]);+ expect(pgliteLife.disabled).toEqual({ state: 'off', links: [], windows: [] });+ });+});++describeBoth('owner phrases (Postgres parity)', () => {+ let pg: BrainEngine;+ beforeAll(async () => { pg = await setupDB(); }, 180_000);+ afterAll(async () => { await teardownDB(); });++ test('the CHECK accepts owner_phrase and refuses unknown kinds', async () => {+ await seedOwnerPhraseBrain(pg);+ expect(await checkConstraint(pg)).toBe('refused');+ });++ test('windows, links, counters, visibility and known_as match PGLite', async () => {+ expect(await ownerPhraseSnapshot(pg)).toEqual(pgliteSnap);+ });++ test('correction, a pooled race, deletion and disable match PGLite', async () => {+ expect(await lifecycle(pg)).toEqual(pgliteLife);+ });+});diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-default.json b/test/fixtures/goldens/catalog/pglite-engine-init-default.jsonindex cbf296ad1e..e30ccb4055 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-default.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-default.json@@ -124,7 +124,7 @@"links.links_assertion_tense_check": "c CHECK (((assertion_tense IS NULL) OR (assertion_tense = ANY (ARRAY['present'::text, 'past'::text]))))","links.links_from_page_id_fkey": "f FOREIGN KEY (from_page_id) REFERENCES pages(id) ON DELETE CASCADE","links.links_from_to_type_source_origin_unique": "u UNIQUE NULLS NOT DISTINCT (from_page_id, to_page_id, link_type, link_source, origin_page_id)",- "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text]))))",+ "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text, 'owner_phrase'::text]))))","links.links_link_source_check": "c CHECK (((link_source IS NULL) OR ((link_source ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'::text) AND (char_length(link_source) <= 64))))","links.links_origin_page_id_fkey": "f FOREIGN KEY (origin_page_id) REFERENCES pages(id) ON DELETE SET NULL","links.links_pkey": "p PRIMARY KEY (id)",@@ -201,6 +201,15 @@"open_loops.open_loops_pkey": "p PRIMARY KEY (id)","open_loops.open_loops_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","open_loops.open_loops_status_check": "c CHECK ((status = ANY (ARRAY['open'::text, 'done'::text, 'dropped'::text, 'stale'::text])))",+ "owner_phrase_page_state.owner_phrase_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "owner_phrase_page_state.owner_phrase_page_state_pkey": "p PRIMARY KEY (page_id)",+ "owner_phrase_page_state.owner_phrase_page_state_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_pkey": "p PRIMARY KEY (source_id)",+ "owner_phrase_status.owner_phrase_status_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_state_check": "c CHECK ((state = ANY (ARRAY['complete'::text, 'pending'::text, 'failed'::text])))",+ "owner_phrase_windows.owner_phrase_windows_pkey": "p PRIMARY KEY (id)",+ "owner_phrase_windows.owner_phrase_windows_private_page_id_fkey": "f FOREIGN KEY (private_page_id) REFERENCES pages(id) ON DELETE SET NULL",+ "owner_phrase_windows.owner_phrase_windows_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","page_aliases.page_aliases_origin_check": "c CHECK ((origin = ANY (ARRAY['frontmatter'::text, 'declared'::text, 'subject'::text])))","page_aliases.page_aliases_origin_uniq": "u UNIQUE (source_id, alias_norm, slug, origin)","page_aliases.page_aliases_pkey": "p PRIMARY KEY (id)",@@ -673,6 +682,15 @@"open_loops": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "owner_phrase_page_state": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_status": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_windows": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"page_aliases": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1130,6 +1148,12 @@"open_loops_pkey": "CREATE UNIQUE INDEX open_loops_pkey ON public.open_loops USING btree (id)","open_loops_status_idx": "CREATE INDEX open_loops_status_idx ON public.open_loops USING btree (source_id, status, last_activity_at DESC)","open_loops_thread_idx": "CREATE INDEX open_loops_thread_idx ON public.open_loops USING btree (source_id, thread_id) WHERE (status = 'open'::text)",+ "owner_phrase_page_state_pkey": "CREATE UNIQUE INDEX owner_phrase_page_state_pkey ON public.owner_phrase_page_state USING btree (page_id)",+ "owner_phrase_page_state_source_idx": "CREATE INDEX owner_phrase_page_state_source_idx ON public.owner_phrase_page_state USING btree (source_id)",+ "owner_phrase_status_pkey": "CREATE UNIQUE INDEX owner_phrase_status_pkey ON public.owner_phrase_status USING btree (source_id)",+ "owner_phrase_windows_accounts_idx": "CREATE INDEX owner_phrase_windows_accounts_idx ON public.owner_phrase_windows USING gin (account_slugs)",+ "owner_phrase_windows_group_idx": "CREATE INDEX owner_phrase_windows_group_idx ON public.owner_phrase_windows USING btree (source_id, group_key)",+ "owner_phrase_windows_pkey": "CREATE UNIQUE INDEX owner_phrase_windows_pkey ON public.owner_phrase_windows USING btree (id)","page_aliases_lookup_idx": "CREATE INDEX page_aliases_lookup_idx ON public.page_aliases USING btree (source_id, alias_norm)","page_aliases_origin_uniq": "CREATE UNIQUE INDEX page_aliases_origin_uniq ON public.page_aliases USING btree (source_id, alias_norm, slug, origin)","page_aliases_pkey": "CREATE UNIQUE INDEX page_aliases_pkey ON public.page_aliases USING btree (id)",@@ -1325,6 +1349,7 @@"minion_self_fix_log_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=minion_self_fix_log.id","oauth_grant_audit_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=oauth_grant_audit.id","open_loops_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=open_loops.id",+ "owner_phrase_windows_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=owner_phrase_windows.id","page_aliases_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=page_aliases.id","page_generation_clock_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-","page_versions_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=page_versions.id",@@ -2504,6 +2529,58 @@],"flags": "relkind=r rls=false force_rls=false"},+ "owner_phrase_page_state": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 revision uuid/uuid NULL",+ "4 version integer/int4 NOT NULL",+ "5 page_date date/date NULL",+ "6 readings ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "7 agent boolean/bool NOT NULL DEFAULT false",+ "8 cues jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "9 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "10 hits jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "11 scanned_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_status": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 state text/text NOT NULL",+ "3 generation bigint/int8 NOT NULL DEFAULT 0",+ "4 window_hash text/text NULL",+ "5 windows integer/int4 NOT NULL DEFAULT 0",+ "6 links integer/int4 NOT NULL DEFAULT 0",+ "7 documents integer/int4 NOT NULL DEFAULT 0",+ "8 unresolved integer/int4 NOT NULL DEFAULT 0",+ "9 ambiguous integer/int4 NOT NULL DEFAULT 0",+ "10 last_pass_at timestamp with time zone/timestamptz NULL",+ "11 error text/text NULL",+ "12 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_windows": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('owner_phrase_windows_id_seq'::regclass)",+ "2 source_id text/text NOT NULL",+ "3 group_key text/text NOT NULL",+ "4 account_slugs ARRAY/_text NOT NULL",+ "5 owner_key text/text NOT NULL",+ "6 owner_name text/text NOT NULL",+ "7 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "8 valid_from date/date NULL",+ "9 valid_to date/date NULL",+ "10 start_known boolean/bool NOT NULL",+ "11 evidence jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "12 evidence_page_ids ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",+ "13 private_page_id integer/int4 NULL",+ "14 generation bigint/int8 NOT NULL DEFAULT 0"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"page_aliases": {"columns": ["1 id bigint/int8 NOT NULL DEFAULT nextval('page_aliases_id_seq'::regclass)",diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.jsonindex 152c1ca406..e4e6dfcb3b 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-fts-portuguese.json@@ -124,7 +124,7 @@"links.links_assertion_tense_check": "c CHECK (((assertion_tense IS NULL) OR (assertion_tense = ANY (ARRAY['present'::text, 'past'::text]))))","links.links_from_page_id_fkey": "f FOREIGN KEY (from_page_id) REFERENCES pages(id) ON DELETE CASCADE","links.links_from_to_type_source_origin_unique": "u UNIQUE NULLS NOT DISTINCT (from_page_id, to_page_id, link_type, link_source, origin_page_id)",- "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text]))))",+ "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text, 'owner_phrase'::text]))))","links.links_link_source_check": "c CHECK (((link_source IS NULL) OR ((link_source ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'::text) AND (char_length(link_source) <= 64))))","links.links_origin_page_id_fkey": "f FOREIGN KEY (origin_page_id) REFERENCES pages(id) ON DELETE SET NULL","links.links_pkey": "p PRIMARY KEY (id)",@@ -201,6 +201,15 @@"open_loops.open_loops_pkey": "p PRIMARY KEY (id)","open_loops.open_loops_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","open_loops.open_loops_status_check": "c CHECK ((status = ANY (ARRAY['open'::text, 'done'::text, 'dropped'::text, 'stale'::text])))",+ "owner_phrase_page_state.owner_phrase_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "owner_phrase_page_state.owner_phrase_page_state_pkey": "p PRIMARY KEY (page_id)",+ "owner_phrase_page_state.owner_phrase_page_state_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_pkey": "p PRIMARY KEY (source_id)",+ "owner_phrase_status.owner_phrase_status_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_state_check": "c CHECK ((state = ANY (ARRAY['complete'::text, 'pending'::text, 'failed'::text])))",+ "owner_phrase_windows.owner_phrase_windows_pkey": "p PRIMARY KEY (id)",+ "owner_phrase_windows.owner_phrase_windows_private_page_id_fkey": "f FOREIGN KEY (private_page_id) REFERENCES pages(id) ON DELETE SET NULL",+ "owner_phrase_windows.owner_phrase_windows_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","page_aliases.page_aliases_origin_check": "c CHECK ((origin = ANY (ARRAY['frontmatter'::text, 'declared'::text, 'subject'::text])))","page_aliases.page_aliases_origin_uniq": "u UNIQUE (source_id, alias_norm, slug, origin)","page_aliases.page_aliases_pkey": "p PRIMARY KEY (id)",@@ -673,6 +682,15 @@"open_loops": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "owner_phrase_page_state": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_status": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_windows": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"page_aliases": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1130,6 +1148,12 @@"open_loops_pkey": "CREATE UNIQUE INDEX open_loops_pkey ON public.open_loops USING btree (id)","open_loops_status_idx": "CREATE INDEX open_loops_status_idx ON public.open_loops USING btree (source_id, status, last_activity_at DESC)","open_loops_thread_idx": "CREATE INDEX open_loops_thread_idx ON public.open_loops USING btree (source_id, thread_id) WHERE (status = 'open'::text)",+ "owner_phrase_page_state_pkey": "CREATE UNIQUE INDEX owner_phrase_page_state_pkey ON public.owner_phrase_page_state USING btree (page_id)",+ "owner_phrase_page_state_source_idx": "CREATE INDEX owner_phrase_page_state_source_idx ON public.owner_phrase_page_state USING btree (source_id)",+ "owner_phrase_status_pkey": "CREATE UNIQUE INDEX owner_phrase_status_pkey ON public.owner_phrase_status USING btree (source_id)",+ "owner_phrase_windows_accounts_idx": "CREATE INDEX owner_phrase_windows_accounts_idx ON public.owner_phrase_windows USING gin (account_slugs)",+ "owner_phrase_windows_group_idx": "CREATE INDEX owner_phrase_windows_group_idx ON public.owner_phrase_windows USING btree (source_id, group_key)",+ "owner_phrase_windows_pkey": "CREATE UNIQUE INDEX owner_phrase_windows_pkey ON public.owner_phrase_windows USING btree (id)","page_aliases_lookup_idx": "CREATE INDEX page_aliases_lookup_idx ON public.page_aliases USING btree (source_id, alias_norm)","page_aliases_origin_uniq": "CREATE UNIQUE INDEX page_aliases_origin_uniq ON public.page_aliases USING btree (source_id, alias_norm, slug, origin)","page_aliases_pkey": "CREATE UNIQUE INDEX page_aliases_pkey ON public.page_aliases USING btree (id)",@@ -1325,6 +1349,7 @@"minion_self_fix_log_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=minion_self_fix_log.id","oauth_grant_audit_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=oauth_grant_audit.id","open_loops_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=open_loops.id",+ "owner_phrase_windows_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=owner_phrase_windows.id","page_aliases_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=page_aliases.id","page_generation_clock_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-","page_versions_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=page_versions.id",@@ -2504,6 +2529,58 @@],"flags": "relkind=r rls=false force_rls=false"},+ "owner_phrase_page_state": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 revision uuid/uuid NULL",+ "4 version integer/int4 NOT NULL",+ "5 page_date date/date NULL",+ "6 readings ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "7 agent boolean/bool NOT NULL DEFAULT false",+ "8 cues jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "9 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "10 hits jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "11 scanned_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_status": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 state text/text NOT NULL",+ "3 generation bigint/int8 NOT NULL DEFAULT 0",+ "4 window_hash text/text NULL",+ "5 windows integer/int4 NOT NULL DEFAULT 0",+ "6 links integer/int4 NOT NULL DEFAULT 0",+ "7 documents integer/int4 NOT NULL DEFAULT 0",+ "8 unresolved integer/int4 NOT NULL DEFAULT 0",+ "9 ambiguous integer/int4 NOT NULL DEFAULT 0",+ "10 last_pass_at timestamp with time zone/timestamptz NULL",+ "11 error text/text NULL",+ "12 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_windows": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('owner_phrase_windows_id_seq'::regclass)",+ "2 source_id text/text NOT NULL",+ "3 group_key text/text NOT NULL",+ "4 account_slugs ARRAY/_text NOT NULL",+ "5 owner_key text/text NOT NULL",+ "6 owner_name text/text NOT NULL",+ "7 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "8 valid_from date/date NULL",+ "9 valid_to date/date NULL",+ "10 start_known boolean/bool NOT NULL",+ "11 evidence jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "12 evidence_page_ids ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",+ "13 private_page_id integer/int4 NULL",+ "14 generation bigint/int8 NOT NULL DEFAULT 0"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"page_aliases": {"columns": ["1 id bigint/int8 NOT NULL DEFAULT nextval('page_aliases_id_seq'::regclass)",diff --git a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.jsonindex e856bc2caa..a8a27b0193 100644--- a/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json+++ b/test/fixtures/goldens/catalog/pglite-engine-init-high-dims.json@@ -124,7 +124,7 @@"links.links_assertion_tense_check": "c CHECK (((assertion_tense IS NULL) OR (assertion_tense = ANY (ARRAY['present'::text, 'past'::text]))))","links.links_from_page_id_fkey": "f FOREIGN KEY (from_page_id) REFERENCES pages(id) ON DELETE CASCADE","links.links_from_to_type_source_origin_unique": "u UNIQUE NULLS NOT DISTINCT (from_page_id, to_page_id, link_type, link_source, origin_page_id)",- "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text]))))",+ "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text, 'owner_phrase'::text]))))","links.links_link_source_check": "c CHECK (((link_source IS NULL) OR ((link_source ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'::text) AND (char_length(link_source) <= 64))))","links.links_origin_page_id_fkey": "f FOREIGN KEY (origin_page_id) REFERENCES pages(id) ON DELETE SET NULL","links.links_pkey": "p PRIMARY KEY (id)",@@ -201,6 +201,15 @@"open_loops.open_loops_pkey": "p PRIMARY KEY (id)","open_loops.open_loops_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","open_loops.open_loops_status_check": "c CHECK ((status = ANY (ARRAY['open'::text, 'done'::text, 'dropped'::text, 'stale'::text])))",+ "owner_phrase_page_state.owner_phrase_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "owner_phrase_page_state.owner_phrase_page_state_pkey": "p PRIMARY KEY (page_id)",+ "owner_phrase_page_state.owner_phrase_page_state_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_pkey": "p PRIMARY KEY (source_id)",+ "owner_phrase_status.owner_phrase_status_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_state_check": "c CHECK ((state = ANY (ARRAY['complete'::text, 'pending'::text, 'failed'::text])))",+ "owner_phrase_windows.owner_phrase_windows_pkey": "p PRIMARY KEY (id)",+ "owner_phrase_windows.owner_phrase_windows_private_page_id_fkey": "f FOREIGN KEY (private_page_id) REFERENCES pages(id) ON DELETE SET NULL",+ "owner_phrase_windows.owner_phrase_windows_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","page_aliases.page_aliases_origin_check": "c CHECK ((origin = ANY (ARRAY['frontmatter'::text, 'declared'::text, 'subject'::text])))","page_aliases.page_aliases_origin_uniq": "u UNIQUE (source_id, alias_norm, slug, origin)","page_aliases.page_aliases_pkey": "p PRIMARY KEY (id)",@@ -673,6 +682,15 @@"open_loops": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "owner_phrase_page_state": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_status": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_windows": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"page_aliases": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1126,6 +1144,12 @@"open_loops_pkey": "CREATE UNIQUE INDEX open_loops_pkey ON public.open_loops USING btree (id)","open_loops_status_idx": "CREATE INDEX open_loops_status_idx ON public.open_loops USING btree (source_id, status, last_activity_at DESC)","open_loops_thread_idx": "CREATE INDEX open_loops_thread_idx ON public.open_loops USING btree (source_id, thread_id) WHERE (status = 'open'::text)",+ "owner_phrase_page_state_pkey": "CREATE UNIQUE INDEX owner_phrase_page_state_pkey ON public.owner_phrase_page_state USING btree (page_id)",+ "owner_phrase_page_state_source_idx": "CREATE INDEX owner_phrase_page_state_source_idx ON public.owner_phrase_page_state USING btree (source_id)",+ "owner_phrase_status_pkey": "CREATE UNIQUE INDEX owner_phrase_status_pkey ON public.owner_phrase_status USING btree (source_id)",+ "owner_phrase_windows_accounts_idx": "CREATE INDEX owner_phrase_windows_accounts_idx ON public.owner_phrase_windows USING gin (account_slugs)",+ "owner_phrase_windows_group_idx": "CREATE INDEX owner_phrase_windows_group_idx ON public.owner_phrase_windows USING btree (source_id, group_key)",+ "owner_phrase_windows_pkey": "CREATE UNIQUE INDEX owner_phrase_windows_pkey ON public.owner_phrase_windows USING btree (id)","page_aliases_lookup_idx": "CREATE INDEX page_aliases_lookup_idx ON public.page_aliases USING btree (source_id, alias_norm)","page_aliases_origin_uniq": "CREATE UNIQUE INDEX page_aliases_origin_uniq ON public.page_aliases USING btree (source_id, alias_norm, slug, origin)","page_aliases_pkey": "CREATE UNIQUE INDEX page_aliases_pkey ON public.page_aliases USING btree (id)",@@ -1321,6 +1345,7 @@"minion_self_fix_log_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=minion_self_fix_log.id","oauth_grant_audit_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=oauth_grant_audit.id","open_loops_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=open_loops.id",+ "owner_phrase_windows_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=owner_phrase_windows.id","page_aliases_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=page_aliases.id","page_generation_clock_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-","page_versions_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=page_versions.id",@@ -2500,6 +2525,58 @@],"flags": "relkind=r rls=false force_rls=false"},+ "owner_phrase_page_state": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 revision uuid/uuid NULL",+ "4 version integer/int4 NOT NULL",+ "5 page_date date/date NULL",+ "6 readings ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "7 agent boolean/bool NOT NULL DEFAULT false",+ "8 cues jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "9 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "10 hits jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "11 scanned_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_status": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 state text/text NOT NULL",+ "3 generation bigint/int8 NOT NULL DEFAULT 0",+ "4 window_hash text/text NULL",+ "5 windows integer/int4 NOT NULL DEFAULT 0",+ "6 links integer/int4 NOT NULL DEFAULT 0",+ "7 documents integer/int4 NOT NULL DEFAULT 0",+ "8 unresolved integer/int4 NOT NULL DEFAULT 0",+ "9 ambiguous integer/int4 NOT NULL DEFAULT 0",+ "10 last_pass_at timestamp with time zone/timestamptz NULL",+ "11 error text/text NULL",+ "12 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_windows": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('owner_phrase_windows_id_seq'::regclass)",+ "2 source_id text/text NOT NULL",+ "3 group_key text/text NOT NULL",+ "4 account_slugs ARRAY/_text NOT NULL",+ "5 owner_key text/text NOT NULL",+ "6 owner_name text/text NOT NULL",+ "7 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "8 valid_from date/date NULL",+ "9 valid_to date/date NULL",+ "10 start_known boolean/bool NOT NULL",+ "11 evidence jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "12 evidence_page_ids ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",+ "13 private_page_id integer/int4 NULL",+ "14 generation bigint/int8 NOT NULL DEFAULT 0"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"page_aliases": {"columns": ["1 id bigint/int8 NOT NULL DEFAULT nextval('page_aliases_id_seq'::regclass)",diff --git a/test/fixtures/goldens/catalog/pglite-schema-blob-default.json b/test/fixtures/goldens/catalog/pglite-schema-blob-default.jsonindex 0f36bcf4cf..e297c131cf 100644--- a/test/fixtures/goldens/catalog/pglite-schema-blob-default.json+++ b/test/fixtures/goldens/catalog/pglite-schema-blob-default.json@@ -85,7 +85,7 @@"links.links_assertion_tense_check": "c CHECK (((assertion_tense IS NULL) OR (assertion_tense = ANY (ARRAY['present'::text, 'past'::text]))))","links.links_from_page_id_fkey": "f FOREIGN KEY (from_page_id) REFERENCES pages(id) ON DELETE CASCADE","links.links_from_to_type_source_origin_unique": "u UNIQUE NULLS NOT DISTINCT (from_page_id, to_page_id, link_type, link_source, origin_page_id)",- "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text]))))",+ "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text, 'owner_phrase'::text]))))","links.links_link_source_check": "c CHECK (((link_source IS NULL) OR ((link_source ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'::text) AND (char_length(link_source) <= 64))))","links.links_origin_page_id_fkey": "f FOREIGN KEY (origin_page_id) REFERENCES pages(id) ON DELETE SET NULL","links.links_pkey": "p PRIMARY KEY (id)",diff --git a/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.json b/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.jsonindex 00ecc19cf1..94b553e93a 100644--- a/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.json+++ b/test/fixtures/goldens/catalog/pglite-schema-blob-fts-portuguese.json@@ -85,7 +85,7 @@"links.links_assertion_tense_check": "c CHECK (((assertion_tense IS NULL) OR (assertion_tense = ANY (ARRAY['present'::text, 'past'::text]))))","links.links_from_page_id_fkey": "f FOREIGN KEY (from_page_id) REFERENCES pages(id) ON DELETE CASCADE","links.links_from_to_type_source_origin_unique": "u UNIQUE NULLS NOT DISTINCT (from_page_id, to_page_id, link_type, link_source, origin_page_id)",- "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text]))))",+ "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text, 'owner_phrase'::text]))))","links.links_link_source_check": "c CHECK (((link_source IS NULL) OR ((link_source ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'::text) AND (char_length(link_source) <= 64))))","links.links_origin_page_id_fkey": "f FOREIGN KEY (origin_page_id) REFERENCES pages(id) ON DELETE SET NULL","links.links_pkey": "p PRIMARY KEY (id)",diff --git a/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.json b/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.jsonindex 113a0c3928..904a525a6a 100644--- a/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.json+++ b/test/fixtures/goldens/catalog/pglite-schema-blob-high-dims.json@@ -85,7 +85,7 @@"links.links_assertion_tense_check": "c CHECK (((assertion_tense IS NULL) OR (assertion_tense = ANY (ARRAY['present'::text, 'past'::text]))))","links.links_from_page_id_fkey": "f FOREIGN KEY (from_page_id) REFERENCES pages(id) ON DELETE CASCADE","links.links_from_to_type_source_origin_unique": "u UNIQUE NULLS NOT DISTINCT (from_page_id, to_page_id, link_type, link_source, origin_page_id)",- "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text]))))",+ "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text, 'owner_phrase'::text]))))","links.links_link_source_check": "c CHECK (((link_source IS NULL) OR ((link_source ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'::text) AND (char_length(link_source) <= 64))))","links.links_origin_page_id_fkey": "f FOREIGN KEY (origin_page_id) REFERENCES pages(id) ON DELETE SET NULL","links.links_pkey": "p PRIMARY KEY (id)",diff --git a/test/fixtures/goldens/catalog/postgres-db-initschema.json b/test/fixtures/goldens/catalog/postgres-db-initschema.jsonindex d3688874fe..db021af8a0 100644--- a/test/fixtures/goldens/catalog/postgres-db-initschema.json+++ b/test/fixtures/goldens/catalog/postgres-db-initschema.json@@ -98,7 +98,7 @@"links.links_assertion_tense_check": "c CHECK (((assertion_tense IS NULL) OR (assertion_tense = ANY (ARRAY['present'::text, 'past'::text]))))","links.links_from_page_id_fkey": "f FOREIGN KEY (from_page_id) REFERENCES pages(id) ON DELETE CASCADE","links.links_from_to_type_source_origin_unique": "u UNIQUE NULLS NOT DISTINCT (from_page_id, to_page_id, link_type, link_source, origin_page_id)",- "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text]))))",+ "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text, 'owner_phrase'::text]))))","links.links_link_source_check": "c CHECK (((link_source IS NULL) OR ((link_source ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'::text) AND (char_length(link_source) <= 64))))","links.links_origin_page_id_fkey": "f FOREIGN KEY (origin_page_id) REFERENCES pages(id) ON DELETE SET NULL","links.links_pkey": "p PRIMARY KEY (id)",diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-default.json b/test/fixtures/goldens/catalog/postgres-engine-init-default.jsonindex 203128b796..a93007e1b8 100644--- a/test/fixtures/goldens/catalog/postgres-engine-init-default.json+++ b/test/fixtures/goldens/catalog/postgres-engine-init-default.json@@ -127,7 +127,7 @@"links.links_assertion_tense_check": "c CHECK (((assertion_tense IS NULL) OR (assertion_tense = ANY (ARRAY['present'::text, 'past'::text]))))","links.links_from_page_id_fkey": "f FOREIGN KEY (from_page_id) REFERENCES pages(id) ON DELETE CASCADE","links.links_from_to_type_source_origin_unique": "u UNIQUE NULLS NOT DISTINCT (from_page_id, to_page_id, link_type, link_source, origin_page_id)",- "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text]))))",+ "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text, 'owner_phrase'::text]))))","links.links_link_source_check": "c CHECK (((link_source IS NULL) OR ((link_source ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'::text) AND (char_length(link_source) <= 64))))","links.links_origin_page_id_fkey": "f FOREIGN KEY (origin_page_id) REFERENCES pages(id) ON DELETE SET NULL","links.links_pkey": "p PRIMARY KEY (id)",@@ -205,6 +205,15 @@"open_loops.open_loops_pkey": "p PRIMARY KEY (id)","open_loops.open_loops_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","open_loops.open_loops_status_check": "c CHECK ((status = ANY (ARRAY['open'::text, 'done'::text, 'dropped'::text, 'stale'::text])))",+ "owner_phrase_page_state.owner_phrase_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "owner_phrase_page_state.owner_phrase_page_state_pkey": "p PRIMARY KEY (page_id)",+ "owner_phrase_page_state.owner_phrase_page_state_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_pkey": "p PRIMARY KEY (source_id)",+ "owner_phrase_status.owner_phrase_status_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_state_check": "c CHECK ((state = ANY (ARRAY['complete'::text, 'pending'::text, 'failed'::text])))",+ "owner_phrase_windows.owner_phrase_windows_pkey": "p PRIMARY KEY (id)",+ "owner_phrase_windows.owner_phrase_windows_private_page_id_fkey": "f FOREIGN KEY (private_page_id) REFERENCES pages(id) ON DELETE SET NULL",+ "owner_phrase_windows.owner_phrase_windows_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","page_aliases.page_aliases_origin_check": "c CHECK ((origin = ANY (ARRAY['frontmatter'::text, 'declared'::text, 'subject'::text])))","page_aliases.page_aliases_origin_uniq": "u UNIQUE (source_id, alias_norm, slug, origin)","page_aliases.page_aliases_pkey": "p PRIMARY KEY (id)",@@ -680,6 +689,15 @@"open_loops": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "owner_phrase_page_state": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_status": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_windows": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"page_aliases": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1134,6 +1152,12 @@"open_loops_pkey": "CREATE UNIQUE INDEX open_loops_pkey ON public.open_loops USING btree (id)","open_loops_status_idx": "CREATE INDEX open_loops_status_idx ON public.open_loops USING btree (source_id, status, last_activity_at DESC)","open_loops_thread_idx": "CREATE INDEX open_loops_thread_idx ON public.open_loops USING btree (source_id, thread_id) WHERE (status = 'open'::text)",+ "owner_phrase_page_state_pkey": "CREATE UNIQUE INDEX owner_phrase_page_state_pkey ON public.owner_phrase_page_state USING btree (page_id)",+ "owner_phrase_page_state_source_idx": "CREATE INDEX owner_phrase_page_state_source_idx ON public.owner_phrase_page_state USING btree (source_id)",+ "owner_phrase_status_pkey": "CREATE UNIQUE INDEX owner_phrase_status_pkey ON public.owner_phrase_status USING btree (source_id)",+ "owner_phrase_windows_accounts_idx": "CREATE INDEX owner_phrase_windows_accounts_idx ON public.owner_phrase_windows USING gin (account_slugs)",+ "owner_phrase_windows_group_idx": "CREATE INDEX owner_phrase_windows_group_idx ON public.owner_phrase_windows USING btree (source_id, group_key)",+ "owner_phrase_windows_pkey": "CREATE UNIQUE INDEX owner_phrase_windows_pkey ON public.owner_phrase_windows USING btree (id)","page_aliases_lookup_idx": "CREATE INDEX page_aliases_lookup_idx ON public.page_aliases USING btree (source_id, alias_norm)","page_aliases_origin_uniq": "CREATE UNIQUE INDEX page_aliases_origin_uniq ON public.page_aliases USING btree (source_id, alias_norm, slug, origin)","page_aliases_pkey": "CREATE UNIQUE INDEX page_aliases_pkey ON public.page_aliases USING btree (id)",@@ -1327,6 +1351,7 @@"minion_self_fix_log_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=minion_self_fix_log.id","oauth_grant_audit_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=oauth_grant_audit.id","open_loops_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=open_loops.id",+ "owner_phrase_windows_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=owner_phrase_windows.id","page_aliases_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=page_aliases.id","page_generation_clock_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-","page_versions_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=page_versions.id",@@ -2516,6 +2541,58 @@],"flags": "relkind=r rls=true force_rls=false"},+ "owner_phrase_page_state": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 revision uuid/uuid NULL",+ "4 version integer/int4 NOT NULL",+ "5 page_date date/date NULL",+ "6 readings ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "7 agent boolean/bool NOT NULL DEFAULT false",+ "8 cues jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "9 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "10 hits jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "11 scanned_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_status": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 state text/text NOT NULL",+ "3 generation bigint/int8 NOT NULL DEFAULT 0",+ "4 window_hash text/text NULL",+ "5 windows integer/int4 NOT NULL DEFAULT 0",+ "6 links integer/int4 NOT NULL DEFAULT 0",+ "7 documents integer/int4 NOT NULL DEFAULT 0",+ "8 unresolved integer/int4 NOT NULL DEFAULT 0",+ "9 ambiguous integer/int4 NOT NULL DEFAULT 0",+ "10 last_pass_at timestamp with time zone/timestamptz NULL",+ "11 error text/text NULL",+ "12 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_windows": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('owner_phrase_windows_id_seq'::regclass)",+ "2 source_id text/text NOT NULL",+ "3 group_key text/text NOT NULL",+ "4 account_slugs ARRAY/_text NOT NULL",+ "5 owner_key text/text NOT NULL",+ "6 owner_name text/text NOT NULL",+ "7 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "8 valid_from date/date NULL",+ "9 valid_to date/date NULL",+ "10 start_known boolean/bool NOT NULL",+ "11 evidence jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "12 evidence_page_ids ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",+ "13 private_page_id integer/int4 NULL",+ "14 generation bigint/int8 NOT NULL DEFAULT 0"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"page_aliases": {"columns": ["1 id bigint/int8 NOT NULL DEFAULT nextval('page_aliases_id_seq'::regclass)",diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.jsonindex b932210248..9727946a86 100644--- a/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json+++ b/test/fixtures/goldens/catalog/postgres-engine-init-fts-portuguese.json@@ -127,7 +127,7 @@"links.links_assertion_tense_check": "c CHECK (((assertion_tense IS NULL) OR (assertion_tense = ANY (ARRAY['present'::text, 'past'::text]))))","links.links_from_page_id_fkey": "f FOREIGN KEY (from_page_id) REFERENCES pages(id) ON DELETE CASCADE","links.links_from_to_type_source_origin_unique": "u UNIQUE NULLS NOT DISTINCT (from_page_id, to_page_id, link_type, link_source, origin_page_id)",- "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text]))))",+ "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text, 'owner_phrase'::text]))))","links.links_link_source_check": "c CHECK (((link_source IS NULL) OR ((link_source ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'::text) AND (char_length(link_source) <= 64))))","links.links_origin_page_id_fkey": "f FOREIGN KEY (origin_page_id) REFERENCES pages(id) ON DELETE SET NULL","links.links_pkey": "p PRIMARY KEY (id)",@@ -205,6 +205,15 @@"open_loops.open_loops_pkey": "p PRIMARY KEY (id)","open_loops.open_loops_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","open_loops.open_loops_status_check": "c CHECK ((status = ANY (ARRAY['open'::text, 'done'::text, 'dropped'::text, 'stale'::text])))",+ "owner_phrase_page_state.owner_phrase_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "owner_phrase_page_state.owner_phrase_page_state_pkey": "p PRIMARY KEY (page_id)",+ "owner_phrase_page_state.owner_phrase_page_state_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_pkey": "p PRIMARY KEY (source_id)",+ "owner_phrase_status.owner_phrase_status_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_state_check": "c CHECK ((state = ANY (ARRAY['complete'::text, 'pending'::text, 'failed'::text])))",+ "owner_phrase_windows.owner_phrase_windows_pkey": "p PRIMARY KEY (id)",+ "owner_phrase_windows.owner_phrase_windows_private_page_id_fkey": "f FOREIGN KEY (private_page_id) REFERENCES pages(id) ON DELETE SET NULL",+ "owner_phrase_windows.owner_phrase_windows_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","page_aliases.page_aliases_origin_check": "c CHECK ((origin = ANY (ARRAY['frontmatter'::text, 'declared'::text, 'subject'::text])))","page_aliases.page_aliases_origin_uniq": "u UNIQUE (source_id, alias_norm, slug, origin)","page_aliases.page_aliases_pkey": "p PRIMARY KEY (id)",@@ -680,6 +689,15 @@"open_loops": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "owner_phrase_page_state": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_status": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_windows": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"page_aliases": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1134,6 +1152,12 @@"open_loops_pkey": "CREATE UNIQUE INDEX open_loops_pkey ON public.open_loops USING btree (id)","open_loops_status_idx": "CREATE INDEX open_loops_status_idx ON public.open_loops USING btree (source_id, status, last_activity_at DESC)","open_loops_thread_idx": "CREATE INDEX open_loops_thread_idx ON public.open_loops USING btree (source_id, thread_id) WHERE (status = 'open'::text)",+ "owner_phrase_page_state_pkey": "CREATE UNIQUE INDEX owner_phrase_page_state_pkey ON public.owner_phrase_page_state USING btree (page_id)",+ "owner_phrase_page_state_source_idx": "CREATE INDEX owner_phrase_page_state_source_idx ON public.owner_phrase_page_state USING btree (source_id)",+ "owner_phrase_status_pkey": "CREATE UNIQUE INDEX owner_phrase_status_pkey ON public.owner_phrase_status USING btree (source_id)",+ "owner_phrase_windows_accounts_idx": "CREATE INDEX owner_phrase_windows_accounts_idx ON public.owner_phrase_windows USING gin (account_slugs)",+ "owner_phrase_windows_group_idx": "CREATE INDEX owner_phrase_windows_group_idx ON public.owner_phrase_windows USING btree (source_id, group_key)",+ "owner_phrase_windows_pkey": "CREATE UNIQUE INDEX owner_phrase_windows_pkey ON public.owner_phrase_windows USING btree (id)","page_aliases_lookup_idx": "CREATE INDEX page_aliases_lookup_idx ON public.page_aliases USING btree (source_id, alias_norm)","page_aliases_origin_uniq": "CREATE UNIQUE INDEX page_aliases_origin_uniq ON public.page_aliases USING btree (source_id, alias_norm, slug, origin)","page_aliases_pkey": "CREATE UNIQUE INDEX page_aliases_pkey ON public.page_aliases USING btree (id)",@@ -1327,6 +1351,7 @@"minion_self_fix_log_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=minion_self_fix_log.id","oauth_grant_audit_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=oauth_grant_audit.id","open_loops_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=open_loops.id",+ "owner_phrase_windows_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=owner_phrase_windows.id","page_aliases_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=page_aliases.id","page_generation_clock_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-","page_versions_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=page_versions.id",@@ -2516,6 +2541,58 @@],"flags": "relkind=r rls=true force_rls=false"},+ "owner_phrase_page_state": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 revision uuid/uuid NULL",+ "4 version integer/int4 NOT NULL",+ "5 page_date date/date NULL",+ "6 readings ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "7 agent boolean/bool NOT NULL DEFAULT false",+ "8 cues jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "9 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "10 hits jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "11 scanned_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_status": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 state text/text NOT NULL",+ "3 generation bigint/int8 NOT NULL DEFAULT 0",+ "4 window_hash text/text NULL",+ "5 windows integer/int4 NOT NULL DEFAULT 0",+ "6 links integer/int4 NOT NULL DEFAULT 0",+ "7 documents integer/int4 NOT NULL DEFAULT 0",+ "8 unresolved integer/int4 NOT NULL DEFAULT 0",+ "9 ambiguous integer/int4 NOT NULL DEFAULT 0",+ "10 last_pass_at timestamp with time zone/timestamptz NULL",+ "11 error text/text NULL",+ "12 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_windows": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('owner_phrase_windows_id_seq'::regclass)",+ "2 source_id text/text NOT NULL",+ "3 group_key text/text NOT NULL",+ "4 account_slugs ARRAY/_text NOT NULL",+ "5 owner_key text/text NOT NULL",+ "6 owner_name text/text NOT NULL",+ "7 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "8 valid_from date/date NULL",+ "9 valid_to date/date NULL",+ "10 start_known boolean/bool NOT NULL",+ "11 evidence jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "12 evidence_page_ids ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",+ "13 private_page_id integer/int4 NULL",+ "14 generation bigint/int8 NOT NULL DEFAULT 0"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"page_aliases": {"columns": ["1 id bigint/int8 NOT NULL DEFAULT nextval('page_aliases_id_seq'::regclass)",diff --git a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.jsonindex 241f39db24..56a315fde2 100644--- a/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json+++ b/test/fixtures/goldens/catalog/postgres-engine-init-high-dims.json@@ -127,7 +127,7 @@"links.links_assertion_tense_check": "c CHECK (((assertion_tense IS NULL) OR (assertion_tense = ANY (ARRAY['present'::text, 'past'::text]))))","links.links_from_page_id_fkey": "f FOREIGN KEY (from_page_id) REFERENCES pages(id) ON DELETE CASCADE","links.links_from_to_type_source_origin_unique": "u UNIQUE NULLS NOT DISTINCT (from_page_id, to_page_id, link_type, link_source, origin_page_id)",- "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text]))))",+ "links.links_link_kind_check": "c CHECK (((link_kind IS NULL) OR (link_kind = ANY (ARRAY['plain'::text, 'typed_ner'::text, 'owner_phrase'::text]))))","links.links_link_source_check": "c CHECK (((link_source IS NULL) OR ((link_source ~ '^[a-z][a-z0-9]*(-[a-z0-9]+)*$'::text) AND (char_length(link_source) <= 64))))","links.links_origin_page_id_fkey": "f FOREIGN KEY (origin_page_id) REFERENCES pages(id) ON DELETE SET NULL","links.links_pkey": "p PRIMARY KEY (id)",@@ -205,6 +205,15 @@"open_loops.open_loops_pkey": "p PRIMARY KEY (id)","open_loops.open_loops_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","open_loops.open_loops_status_check": "c CHECK ((status = ANY (ARRAY['open'::text, 'done'::text, 'dropped'::text, 'stale'::text])))",+ "owner_phrase_page_state.owner_phrase_page_state_page_id_fkey": "f FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE",+ "owner_phrase_page_state.owner_phrase_page_state_pkey": "p PRIMARY KEY (page_id)",+ "owner_phrase_page_state.owner_phrase_page_state_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_pkey": "p PRIMARY KEY (source_id)",+ "owner_phrase_status.owner_phrase_status_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE",+ "owner_phrase_status.owner_phrase_status_state_check": "c CHECK ((state = ANY (ARRAY['complete'::text, 'pending'::text, 'failed'::text])))",+ "owner_phrase_windows.owner_phrase_windows_pkey": "p PRIMARY KEY (id)",+ "owner_phrase_windows.owner_phrase_windows_private_page_id_fkey": "f FOREIGN KEY (private_page_id) REFERENCES pages(id) ON DELETE SET NULL",+ "owner_phrase_windows.owner_phrase_windows_source_id_fkey": "f FOREIGN KEY (source_id) REFERENCES sources(id) ON DELETE CASCADE","page_aliases.page_aliases_origin_check": "c CHECK ((origin = ANY (ARRAY['frontmatter'::text, 'declared'::text, 'subject'::text])))","page_aliases.page_aliases_origin_uniq": "u UNIQUE (source_id, alias_norm, slug, origin)","page_aliases.page_aliases_pkey": "p PRIMARY KEY (id)",@@ -680,6 +689,15 @@"open_loops": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],+ "owner_phrase_page_state": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_status": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],+ "owner_phrase_windows": [+ "<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"+ ],"page_aliases": ["<current_role> -> <current_role> WITH GRANT OPTION: DELETE,INSERT,REFERENCES,SELECT,TRIGGER,TRUNCATE,UPDATE"],@@ -1130,6 +1148,12 @@"open_loops_pkey": "CREATE UNIQUE INDEX open_loops_pkey ON public.open_loops USING btree (id)","open_loops_status_idx": "CREATE INDEX open_loops_status_idx ON public.open_loops USING btree (source_id, status, last_activity_at DESC)","open_loops_thread_idx": "CREATE INDEX open_loops_thread_idx ON public.open_loops USING btree (source_id, thread_id) WHERE (status = 'open'::text)",+ "owner_phrase_page_state_pkey": "CREATE UNIQUE INDEX owner_phrase_page_state_pkey ON public.owner_phrase_page_state USING btree (page_id)",+ "owner_phrase_page_state_source_idx": "CREATE INDEX owner_phrase_page_state_source_idx ON public.owner_phrase_page_state USING btree (source_id)",+ "owner_phrase_status_pkey": "CREATE UNIQUE INDEX owner_phrase_status_pkey ON public.owner_phrase_status USING btree (source_id)",+ "owner_phrase_windows_accounts_idx": "CREATE INDEX owner_phrase_windows_accounts_idx ON public.owner_phrase_windows USING gin (account_slugs)",+ "owner_phrase_windows_group_idx": "CREATE INDEX owner_phrase_windows_group_idx ON public.owner_phrase_windows USING btree (source_id, group_key)",+ "owner_phrase_windows_pkey": "CREATE UNIQUE INDEX owner_phrase_windows_pkey ON public.owner_phrase_windows USING btree (id)","page_aliases_lookup_idx": "CREATE INDEX page_aliases_lookup_idx ON public.page_aliases USING btree (source_id, alias_norm)","page_aliases_origin_uniq": "CREATE UNIQUE INDEX page_aliases_origin_uniq ON public.page_aliases USING btree (source_id, alias_norm, slug, origin)","page_aliases_pkey": "CREATE UNIQUE INDEX page_aliases_pkey ON public.page_aliases USING btree (id)",@@ -1323,6 +1347,7 @@"minion_self_fix_log_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=minion_self_fix_log.id","oauth_grant_audit_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=oauth_grant_audit.id","open_loops_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=open_loops.id",+ "owner_phrase_windows_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=owner_phrase_windows.id","page_aliases_id_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=page_aliases.id","page_generation_clock_seq": "bigint start=1 min=1 max=9223372036854775807 increment=1 cycle=false cache=1 owned_by=-","page_versions_id_seq": "integer start=1 min=1 max=2147483647 increment=1 cycle=false cache=1 owned_by=page_versions.id",@@ -2512,6 +2537,58 @@],"flags": "relkind=r rls=true force_rls=false"},+ "owner_phrase_page_state": {+ "columns": [+ "1 page_id integer/int4 NOT NULL",+ "2 source_id text/text NOT NULL",+ "3 revision uuid/uuid NULL",+ "4 version integer/int4 NOT NULL",+ "5 page_date date/date NULL",+ "6 readings ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "7 agent boolean/bool NOT NULL DEFAULT false",+ "8 cues jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "9 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "10 hits jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "11 scanned_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_status": {+ "columns": [+ "1 source_id text/text NOT NULL",+ "2 state text/text NOT NULL",+ "3 generation bigint/int8 NOT NULL DEFAULT 0",+ "4 window_hash text/text NULL",+ "5 windows integer/int4 NOT NULL DEFAULT 0",+ "6 links integer/int4 NOT NULL DEFAULT 0",+ "7 documents integer/int4 NOT NULL DEFAULT 0",+ "8 unresolved integer/int4 NOT NULL DEFAULT 0",+ "9 ambiguous integer/int4 NOT NULL DEFAULT 0",+ "10 last_pass_at timestamp with time zone/timestamptz NULL",+ "11 error text/text NULL",+ "12 updated_at timestamp with time zone/timestamptz NOT NULL DEFAULT now()"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },+ "owner_phrase_windows": {+ "columns": [+ "1 id bigint/int8 NOT NULL DEFAULT nextval('owner_phrase_windows_id_seq'::regclass)",+ "2 source_id text/text NOT NULL",+ "3 group_key text/text NOT NULL",+ "4 account_slugs ARRAY/_text NOT NULL",+ "5 owner_key text/text NOT NULL",+ "6 owner_name text/text NOT NULL",+ "7 descriptors ARRAY/_text NOT NULL DEFAULT '{}'::text[]",+ "8 valid_from date/date NULL",+ "9 valid_to date/date NULL",+ "10 start_known boolean/bool NOT NULL",+ "11 evidence jsonb/jsonb NOT NULL DEFAULT '[]'::jsonb",+ "12 evidence_page_ids ARRAY/_int4 NOT NULL DEFAULT '{}'::integer[]",+ "13 private_page_id integer/int4 NULL",+ "14 generation bigint/int8 NOT NULL DEFAULT 0"+ ],+ "flags": "relkind=r rls=true force_rls=false"+ },"page_aliases": {"columns": ["1 id bigint/int8 NOT NULL DEFAULT nextval('page_aliases_id_seq'::regclass)",diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.jsonindex 21e023ce33..f65398efac 100644--- a/test/fixtures/goldens/migrations/records.json+++ b/test/fixtures/goldens/migrations/records.json@@ -1,6 +1,6 @@{"golden": {- "count": 234,+ "count": 235,"gaps": [17,18,@@ -52,7 +52,7 @@"sqlQueryForEngine": "71fb1ccec1b22cdc1662876dbd8c17ed81e9ab83485c6965cdf5caa4fc4a4ab5","verifyProjectionStatistics": "0d231b04ecfbc5a4109d6fca9567bf4e8c9e9db6c3fbbb35212e026579ed6f67"},- "latest": 239,+ "latest": 240,"records": [{"handler": {@@ -3623,6 +3623,19 @@"transaction": "absent","verify": "absent","version": 239+ },+ {+ "handler": "absent",+ "idempotent": true,+ "name": "owner_phrase_windows",+ "sql": {+ "length": 2707,+ "sha256": "d02bcdb4bc07f65d7980750ea37e84aa152ac1a65fb7d8f075c24901e521bf49"+ },+ "sqlFor": "absent",+ "transaction": "absent",+ "verify": "absent",+ "version": 240}],"versions": [@@ -3859,7 +3872,8 @@236,237,238,- 239+ 239,+ 240]},"normalizer": "migrations-record-v1"diff --git a/test/graduation-inventory.test.ts b/test/graduation-inventory.test.tsindex 0f2618f67c..0546a285b2 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: 122, rebind: 2, rebuild: 2, discard: 7, schema_owned: 4 });+ expect(counts).toEqual({ carry: 125, rebind: 2, rebuild: 2, discard: 7, 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 });diff --git a/test/helpers/owner-phrase-brain.ts b/test/helpers/owner-phrase-brain.tsnew file mode 100644index 0000000000..18e6d7b52c--- /dev/null+++ b/test/helpers/owner-phrase-brain.ts@@ -0,0 +1,92 @@+/**+ * Owner-phrase test corpus (docs/guides/owner-phrases.md): a small general+ * brain of account pages, people, dated team updates and call notes that+ * name accounts only by "<owner>'s <descriptor> account". Shared by the+ * PGLite DB test and the Postgres parity test so both engines run the same+ * rows. Placeholder names only.+ */+import type { BrainEngine } from '../../src/core/engine.ts';+import { setCliOptions } from '../../src/core/cli-options.ts';+import { extractStaleFromDB } from '../../src/commands/extract.ts';+import { importFromContent } from '../../src/core/import-file.ts';+import { serializeMarkdown } from '../../src/core/markdown.ts';+import { buildEntityCard } from '../../src/core/verbs/entity-card.ts';+import { privateLinkOriginFilterFragment, privatePagesFilterFragment } from '../../src/core/search/private-visibility.ts';+import type { PageType } from '../../src/core/types.ts';++export const ACME = 'companies/acme-example-freight';+export const NIMBUS = 'companies/nimbus-example-freight';+export const WIDGET = 'companies/widget-example-health';++export async function doc(engine: BrainEngine, slug: string, body: string, opts: { type?: string; date?: string; title?: string; private?: boolean } = {}): Promise<void> {+ const frontmatter: Record<string, unknown> = { ...(opts.date ? { date: opts.date } : {}), ...(opts.private ? { visibility: 'private' } : {}) };+ await importFromContent(engine, slug, serializeMarkdown(frontmatter, body, '', { type: (opts.type ?? 'note') as PageType, title: opts.title ?? slug, tags: [] }),+ { noEmbed: true, forceRechunk: true });+}++export async function seedOwnerPhraseBrain(engine: BrainEngine, opts: { enabled?: boolean } = {}): Promise<void> {+ await engine.setConfig('schema_pack', 'gbrain-base-v2');+ if (opts.enabled !== false) await engine.setConfig('mentions.owner_phrases', 'true');+ await doc(engine, 'people/quill-example', 'Account manager.', { type: 'person', title: 'Quill Example' });+ await doc(engine, 'people/rowan-example', 'Account manager.', { type: 'person', title: 'Rowan Example' });+ await doc(engine, 'people/juniper-example', 'Account manager.', { type: 'person', title: 'Juniper Example' });+ await doc(engine, ACME, 'Segment: logistics', { type: 'company', title: 'Acme Example Freight' });+ await doc(engine, NIMBUS, 'Segment: logistics', { type: 'company', title: 'Nimbus Example Freight' });+ await doc(engine, WIDGET, 'Segment: benefits', { type: 'company', title: 'Widget Example Health' });+ // Advance handoff: Rowan's stint ends April 30, Quill's starts May 1.+ await doc(engine, 'updates/acme-handoff', 'From May 1, Quill Example takes over Acme Example Freight from Rowan Example.', { date: '2025-04-15' });+ await doc(engine, 'notes/rate-review', "Rowan's freight account asked for a rate review.", { date: '2025-04-20' });+ await doc(engine, 'notes/rate-followup', "Rowan's freight account asked again about the rate review.", { date: '2025-05-10' });+ await doc(engine, 'notes/renewal', "Quill's freight account renewed for two years.", { date: '2025-05-12' });+ // A second freight account: Juniper owns it, then hands it to Quill on June 1.+ await doc(engine, 'updates/nimbus-owner', 'Juniper Example owns Nimbus Example Freight.', { date: '2025-01-01' });+ await doc(engine, 'updates/nimbus-handoff', 'Nimbus Example Freight moves from Juniper Example to Quill Example on 2025-06-01.', { date: '2025-05-20' });+ await doc(engine, 'notes/escalation', "Quill's freight account escalated a missed pickup.", { date: '2025-07-01' });+ await doc(engine, 'notes/juniper-call', "Juniper's freight account asked about invoices.", { date: '2025-03-03' });+ // No page date: never linked.+ await doc(engine, 'notes/undated', "Quill's freight account wants a call.");+ // Evidence only on a private page: owner-trusted reads see the link, untrusted reads do not.+ await doc(engine, 'updates/widget-handoff', 'Widget Example Health moves from Rowan Example to Quill Example, effective February 1.', { date: '2025-01-25', private: true });+ await doc(engine, 'notes/benefits-call', "Quill's health account asked about billing.", { date: '2025-03-01' });+ // An agent-written page sets no window.+ await doc(engine, 'notes/agent-guess', 'Juniper Example owns Widget Example Health.', { type: 'agent-note', date: '2025-02-10' });+ await doc(engine, 'notes/juniper-health', "Juniper's health account sent a contract.", { date: '2025-03-05' });+}++export async function sweepOwnerPhrases(engine: BrainEngine) {+ setCliOptions({ quiet: true, progressJson: false, progressInterval: 1000, explain: false, timeoutMs: null, brain: null });+ const r = await extractStaleFromDB(engine, { dryRun: false, jsonMode: false, quiet: true, catchUp: true });+ return r.mentions?.ownerPhrases;+}++/** `doc -> account` for every owner-phrase link; `remote` applies the untrusted visibility predicate. */+export async function ownerPhraseLinks(engine: BrainEngine, remote = false): Promise<string[]> {+ const rows = await engine.executeRaw<{ f: string; t: string }>(+ `SELECT f.slug AS f, t.slug AS t FROM links l JOIN pages f ON f.id = l.from_page_id JOIN pages t ON t.id = l.to_page_id+ WHERE l.link_source = 'mentions' AND l.link_kind = 'owner_phrase'+ ${remote ? `AND ${privateLinkOriginFilterFragment('l')} AND ${privatePagesFilterFragment('f')} AND ${privatePagesFilterFragment('t')}` : ''}+ ORDER BY 1, 2`);+ return rows.map(r => `${r.f} -> ${r.t}`);+}++export async function windowRows(engine: BrainEngine): Promise<string[]> {+ const rows = await engine.executeRaw<{ g: string; o: string; f: string | null; t: string | null; p: number | null }>(+ `SELECT group_key AS g, owner_name AS o, valid_from::text AS f, valid_to::text AS t, private_page_id AS p FROM owner_phrase_windows ORDER BY 1, 2, 3`);+ return rows.map(r => `${r.g} ${r.o} ${r.f ?? '?'}..${r.t ?? 'open'}${r.p == null ? '' : ' (private)'}`);+}++export async function ownerPhraseSnapshot(engine: BrainEngine) {+ const counters = await sweepOwnerPhrases(engine);+ const card = async (remote: boolean) => (await buildEntityCard(engine, 'default', 'Widget Example Health', { remote, includeReferences: true })).card?.known_as;+ const [status] = await engine.executeRaw<Record<string, unknown>>(+ 'SELECT state, windows, links, documents, unresolved, ambiguous FROM owner_phrase_status WHERE source_id = $1', ['default']);+ return {+ counters: counters && { state: counters.state, links: counters.links, documents: counters.documents, unresolved: counters.unresolved, ambiguous: counters.ambiguous, windows: counters.windows },+ status: status && Object.fromEntries(Object.entries(status).map(([k, v]) => [k, typeof v === 'string' ? v : Number(v)])),+ trusted: await ownerPhraseLinks(engine),+ remote: await ownerPhraseLinks(engine, true),+ windows: await windowRows(engine),+ knownAsTrusted: (await card(false))?.rows.map(r => `${r.owner} ${r.from ?? '?'}..${r.to ?? 'open'}`),+ knownAsRemote: (await card(true))?.rows.map(r => `${r.owner} ${r.from ?? '?'}..${r.to ?? 'open'}`) ?? [],+ };+}diff --git a/test/owner-phrase-pass.test.ts b/test/owner-phrase-pass.test.tsnew file mode 100644index 0000000000..76ab6e712f--- /dev/null+++ b/test/owner-phrase-pass.test.ts@@ -0,0 +1,194 @@+/**+ * Owner phrases, the stored pass on PGLite (docs/guides/owner-phrases.md):+ * migration, windows, linking inside and outside windows, ambiguity refusal,+ * visibility, corrections, deletion, enable/disable, concurrency, the policy+ * fingerprint and final-score invariance across every link-counting ranking+ * consumer.+ *+ * Protects: owner-phrase links stored as `link_source='mentions'`,+ * `link_kind='owner_phrase'` only while `mentions.owner_phrases` is on; a+ * window change alone relinking unedited documents; private-only evidence+ * never reaching untrusted reads (links and `known_as`); plain mention links,+ * policy fingerprints and final ranking scores unchanged by the key.+ * Regression: an owner phrase linked outside its window or to one of two+ * matching accounts, or an owner-phrase link that moves a search score.+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { createHash } from 'node:crypto';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { policyFingerprint } from '../src/core/mentions/pass.ts';+import { linkableTypesFor, loadSourcePack, readMentionPolicy } from '../src/core/mentions/policy.ts';+import { buildGazetteer } from '../src/core/by-mention.ts';+import { runOwnerPhrasePass } from '../src/core/mentions/owner-phrase/pass.ts';+import { buildEntityCard } from '../src/core/verbs/entity-card.ts';+import { entityAnchoredPages } from '../src/core/search/entity-anchor.ts';+import { applyGeneratedDemotion } from '../src/core/search/provenance-demotion.ts';+import type { SearchResult } from '../src/core/types.ts';+import { ACME, NIMBUS, WIDGET, doc, ownerPhraseLinks, ownerPhraseSnapshot, seedOwnerPhraseBrain, sweepOwnerPhrases, windowRows } from './helpers/owner-phrase-brain.ts';++let engine: PGLiteEngine;+let snap: Awaited<ReturnType<typeof ownerPhraseSnapshot>>;++beforeAll(async () => {+ engine = new PGLiteEngine();+ await engine.connect({});+ await engine.initSchema();+ await seedOwnerPhraseBrain(engine);+ snap = await ownerPhraseSnapshot(engine);+}, 180_000);+afterAll(async () => { await engine.disconnect(); });++const plainLinks = async () => (await engine.executeRaw<{ f: string; t: string; k: string | null }>(+ `SELECT f.slug AS f, t.slug AS t, l.link_kind AS k FROM links l JOIN pages f ON f.id = l.from_page_id JOIN pages t ON t.id = l.to_page_id+ WHERE l.link_kind IS DISTINCT FROM 'owner_phrase' ORDER BY 1, 2, 3`)).map(r => `${r.f} -> ${r.t} ${r.k ?? ''}`);+const idOf = async (slug: string) => Number((await engine.executeRaw<{ id: number }>('SELECT id FROM pages WHERE slug = $1', [slug]))[0]!.id);++describe('migration', () => {+ test('the link_kind CHECK accepts owner_phrase and still refuses unknown kinds', async () => {+ const [a, b] = [await idOf('notes/undated'), await idOf(ACME)];+ await engine.executeRaw(`INSERT INTO links (from_page_id, to_page_id, link_type, link_source, link_kind) VALUES ($1, $2, 'probe', 'mentions', 'owner_phrase')`, [a, b]);+ await engine.executeRaw(`DELETE FROM links WHERE link_type = 'probe'`);+ await expect(engine.executeRaw(`INSERT INTO links (from_page_id, to_page_id, link_type, link_source, link_kind) VALUES ($1, $2, 'probe', 'mentions', 'bogus')`, [a, b])).rejects.toThrow();+ const tables = (await engine.executeRaw<{ t: string }>(`SELECT table_name AS t FROM information_schema.tables WHERE table_name LIKE 'owner_phrase_%' ORDER BY 1`)).map(r => r.t);+ expect(tables).toEqual(['owner_phrase_page_state', 'owner_phrase_status', 'owner_phrase_windows']);+ });+});++describe('windows and links', () => {+ test('windows: an advance handoff, an ongoing owner with an unknown start, private evidence marked', () => {+ expect(snap.windows).toEqual([+ `${ACME} Quill Example 2025-05-01..open`, `${ACME} Rowan Example ?..2025-04-30`,+ `${NIMBUS} Juniper Example ?..2025-05-31`, `${NIMBUS} Quill Example 2025-06-01..open`,+ `${WIDGET} Quill Example 2025-02-01..open (private)`, `${WIDGET} Rowan Example ?..2025-01-31 (private)`,+ ]);+ });++ test('a phrase links inside its owner window only; two matching accounts, no page date, an agent-only window and no owner never link', () => {+ expect(snap.trusted).toEqual([`notes/benefits-call -> ${WIDGET}`, `notes/juniper-call -> ${NIMBUS}`, `notes/rate-review -> ${ACME}`, `notes/renewal -> ${ACME}`]);+ for (const absent of ['notes/rate-followup', 'notes/escalation', 'notes/undated', 'notes/juniper-health']) expect(snap.trusted.join('\n')).not.toContain(absent);+ });++ test('the firing counter reports links, documents, unresolved and ambiguous phrases, and the status row matches', () => {+ expect(snap.counters).toEqual({ state: 'complete', links: 4, documents: 4, unresolved: 3, ambiguous: 1, windows: 6 });+ expect(snap.status).toEqual({ state: 'complete', windows: 6, links: 4, documents: 4, unresolved: 3, ambiguous: 1 });+ });++ test('visibility: a link whose only evidence is private, and its known_as window, are hidden from untrusted reads', () => {+ expect(snap.remote).toEqual(snap.trusted.filter(l => !l.startsWith('notes/benefits-call')));+ expect(snap.knownAsTrusted).toEqual(['Quill Example 2025-02-01..open', 'Rowan Example ?..2025-01-31']);+ expect(snap.knownAsRemote).toEqual([]);+ });++ test('owner-phrase links reach the card through referenced_by, and owner phrases never become aliases', async () => {+ const card = (await buildEntityCard(engine, 'default', 'Acme Example Freight', { remote: true, includeReferences: true })).card!;+ expect(card.referenced_by!.flatMap(g => g.rows.map(r => r.slug)).sort()).toEqual(['notes/rate-review', 'notes/renewal', 'updates/acme-handoff']);+ expect(card.known_as!.rows.map(r => r.owner)).toEqual(['Quill Example', 'Rowan Example']);+ expect(card.aka ?? []).not.toEqual(expect.arrayContaining([expect.stringMatching(/freight account/i)]));+ const aliases = await engine.executeRaw<{ n: number }>(`SELECT count(*)::int AS n FROM page_aliases WHERE alias_norm LIKE '%account%'`);+ expect(Number(aliases[0]!.n)).toBe(0);+ });++ test('a rerun with nothing changed writes nothing', async () => {+ const r = await sweepOwnerPhrases(engine);+ expect(r).toMatchObject({ state: 'complete', created: 0, removed: 0, links: 4 });+ });+});++describe('policy fingerprint', () => {+ test('the key off leaves every existing fingerprint unchanged; on changes it', async () => {+ const policy = await readMentionPolicy(engine);+ const types = ['company', 'person'];+ const legacy = createHash('sha256').update(JSON.stringify({+ types, crossSource: false, ignore: [...policy.ignore].map(n => n.toLowerCase()).sort(),+ aliasDeny: [...policy.aliasDeny].map(n => n.toLowerCase()).sort(), multiword: policy.multiwordAliases, siblings: policy.siblingMerge,+ })).digest('hex').slice(0, 16);+ expect(policyFingerprint(types, false, policy)).toBe(legacy);+ expect(policyFingerprint(types, false, policy, false)).toBe(legacy);+ expect(policyFingerprint(types, false, policy, true)).not.toBe(legacy);+ });+});++describe('final-score invariance', () => {+ async function readers() {+ const slugs = ['notes/rate-review', 'notes/renewal', 'notes/benefits-call', 'notes/juniper-call', 'notes/generated-summary', ACME, NIMBUS, WIDGET];+ const ids = await Promise.all(slugs.map(idOf));+ const bySlug = <V>(m: Map<number, V>) => Object.fromEntries(slugs.map((s, i) => [s, m.get(ids[i]!)]).filter(([, v]) => v !== undefined));+ const refs = ['notes/rate-review', ACME, NIMBUS, WIDGET].map(slug => ({ slug, source_id: 'default' }));+ const pool = (): SearchResult[] => [ids[4]!, ids[5]!].map((page_id, i) => ({ page_id, slug: i ? ACME : 'notes/generated-summary', score: 1 - i * 0.1 }) as unknown as SearchResult);+ const demoted = pool();+ await applyGeneratedDemotion(engine, demoted, 'Acme Example Freight renewal', { sourceId: 'default' });+ return {+ backlinks: bySlug(await engine.getBacklinkCounts(ids)),+ adjacency: bySlug(await engine.getAdjacencyBoosts(ids)),+ salience: [...(await engine.getSalienceScores(refs)).entries()].sort(),+ chain: (await engine.relationalChainHop([ids[5]!], { linkTypes: ['mentions'], toward: 'subject', subjectTypes: [], objectTypes: [], degreeLinkTypes: ['mentions'], neighborCap: 10 })).length,+ anchored: (await entityAnchoredPages(engine, 'default', ACME)).pages.map(p => p.slug).sort(),+ demotion: demoted.map(r => `${r.slug}:${r.score}`),+ plain: await plainLinks(),+ };+ }++ test('every link-counting consumer gives the same result with the key on and off, including threshold crossings', async () => {+ await doc(engine, 'notes/generated-summary', "Quill's freight account renewed; summary of the week.", { date: '2025-05-13' });+ await engine.executeRaw(`UPDATE pages SET frontmatter = frontmatter || '{"dream_generated": true}'::jsonb WHERE slug = 'notes/generated-summary'`);+ await sweepOwnerPhrases(engine);+ expect(await ownerPhraseLinks(engine)).toContain(`notes/generated-summary -> ${ACME}`);+ const on = await readers();+ // Threshold crossings a counted owner-phrase link would cause: a first backlink, a first adjacency hit, an anchored page, a demotion.+ expect(on.backlinks[ACME] ?? 0).toBe(0);+ expect(on.adjacency).toEqual({});+ expect(on.anchored).not.toContain('notes/rate-review');+ expect(on.demotion).toEqual(['notes/generated-summary:1', `${ACME}:0.9`]);++ await engine.setConfig('mentions.owner_phrases', 'false');+ const off = await sweepOwnerPhrases(engine);+ expect(off).toMatchObject({ state: 'off', removed: 5 });+ expect(await ownerPhraseLinks(engine)).toEqual([]);+ expect(await readers()).toEqual(on);+ });++ test('disable cleared windows, scans and status; re-enable restores the same links', async () => {+ expect(await windowRows(engine)).toEqual([]);+ const left = await engine.executeRaw<{ n: number }>('SELECT (SELECT count(*) FROM owner_phrase_page_state) + (SELECT count(*) FROM owner_phrase_status) AS n');+ expect(Number(left[0]!.n)).toBe(0);+ await engine.setConfig('mentions.owner_phrases', 'true');+ await sweepOwnerPhrases(engine);+ expect(await ownerPhraseLinks(engine)).toEqual([...snap.trusted, `notes/generated-summary -> ${ACME}`].sort());+ });+});++describe('invalidation', () => {+ test('a correction ends the wrong stint and relinks documents that were not edited; the generation advances', async () => {+ const before = Number((await engine.executeRaw<{ g: string }>('SELECT generation::text AS g FROM owner_phrase_status'))[0]!.g);+ await doc(engine, 'updates/acme-correction', 'Correction: Acme Example Freight went to Juniper Example, not Quill.', { date: '2025-04-17' });+ await sweepOwnerPhrases(engine);+ const links = await ownerPhraseLinks(engine);+ expect(links).not.toContain(`notes/renewal -> ${ACME}`);+ expect(links).toContain(`notes/rate-review -> ${ACME}`);+ expect(await windowRows(engine)).toContain(`${ACME} Juniper Example 2025-05-01..open`);+ expect(Number((await engine.executeRaw<{ g: string }>('SELECT generation::text AS g FROM owner_phrase_status'))[0]!.g)).toBe(before + 1);+ });++ test('deleting the only statement removes the windows and links it supported', async () => {+ await engine.softDeletePage('updates/acme-correction');+ await engine.softDeletePage('updates/acme-handoff');+ await sweepOwnerPhrases(engine);+ const links = await ownerPhraseLinks(engine);+ expect(links.filter(l => l.endsWith(ACME))).toEqual([]);+ expect((await windowRows(engine)).filter(w => w.startsWith(ACME))).toEqual([]);+ });++ test('two concurrent passes publish one consistent link set; a pass out of time stays pending and writes nothing', async () => {+ const policy = await readMentionPolicy(engine);+ const sequential = await ownerPhraseLinks(engine);+ await doc(engine, 'notes/new-call', "Juniper's freight account called about a claim.", { date: '2025-04-02' });+ const pack = await loadSourcePack(engine, 'default', { strict: true });+ const opts = { sourceId: 'default', gazetteer: await buildGazetteer(engine, { policy, strict: true }), types: linkableTypesFor(pack, policy), pack, policy, enabled: true };+ expect(await runOwnerPhrasePass(engine, { ...opts, deadline: Date.now() - 1 })).toMatchObject({ state: 'pending', created: 0, removed: 0 });+ expect(await ownerPhraseLinks(engine)).toEqual(sequential);+ const [a, b] = await Promise.all([runOwnerPhrasePass(engine, { ...opts, deadline: Infinity }), runOwnerPhrasePass(engine, { ...opts, deadline: Infinity })]);+ expect([a.state, b.state]).toEqual(['complete', 'complete']);+ expect(a.created + b.created).toBe(1);+ expect(await ownerPhraseLinks(engine)).toEqual([...sequential, `notes/new-call -> ${NIMBUS}`].sort());+ });+});