Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test: register findDuplicatePages in engine surface, SQL-text, RLS inventory and export goldens; serial row for the git memo probe

time-attackb226ecf4c996
diff --git a/scripts/serial-files.tsv b/scripts/serial-files.tsv
index 30395f63a9..223dc235ce 100644
--- a/scripts/serial-files.tsv
+++ b/scripts/serial-files.tsv
@@ -377,3 +377,4 @@ test/write-path-no-egress.serial.test.ts global-state global-state: binds a loca
test/write-path-zero-llm.serial.test.ts R1 R1: mutates process.env (ANTHROPIC_API_KEY, OPENAI_API_KEY) so gated chat and embedding paths are live
test/writeback-nudge.serial.test.ts global-state global-state: patches process stdout/stderr/console
test/writeback-review-fixes.serial.test.ts global-state global-state: process-wide test seams __resetCheckpointHarvestForTests; patches process stdout/stderr/console
+test/git-listing-memo.serial.test.ts R1 R1: puts a git-counting shim on process.env.PATH for every spawn in the process (git child processes inherit it, so withEnv cannot scope it)
diff --git a/test/engine-surface-coverage.test.ts b/test/engine-surface-coverage.test.ts
index 281ffeb274..1a51b9aba0 100644
--- a/test/engine-surface-coverage.test.ts
+++ b/test/engine-surface-coverage.test.ts
@@ -50,7 +50,7 @@ const INTERFACE_METHODS: readonly string[] = [
// Lifecycle
'connect', 'disconnect', 'reconnect', 'initSchema', 'transaction', 'transactionDirect', 'registerBeforeDisconnect', 'withReservedConnection',
// Pages CRUD
- 'getPage', 'readPageSnapshot', 'readPageSnapshotsBatch', 'lockPageKeys', 'putPage', 'findDuplicatePage', 'deletePage', 'deletePages', 'resolveSlugsByPaths',
+ 'getPage', 'readPageSnapshot', 'readPageSnapshotsBatch', 'lockPageKeys', 'putPage', 'findDuplicatePage', 'findDuplicatePages', 'deletePage', 'deletePages', 'resolveSlugsByPaths',
'softDeletePage', 'softDeletePages', 'restorePage', 'purgeDeletedPages', 'listPages', 'resolveSlugs', 'getAllSlugs',
'listAllPageRefs', 'listAllSources', 'updateSourceConfig', 'listPrefixSampledPages', 'listCorpusSample',
// Search
diff --git a/test/fixtures/goldens/exports/runtime.json b/test/fixtures/goldens/exports/runtime.json
index 5c56277bd9..f1c9406053 100644
--- a/test/fixtures/goldens/exports/runtime.json
+++ b/test/fixtures/goldens/exports/runtime.json
@@ -49,6 +49,7 @@
"findByTitleFuzzy",
"findCandidateDuplicates",
"findDuplicatePage",
+ "findDuplicatePages",
"findOntologyConflicts",
"findOrphanPages",
"findTrajectory",
@@ -232,6 +233,7 @@
"findByTitleFuzzy",
"findCandidateDuplicates",
"findDuplicatePage",
+ "findDuplicatePages",
"findOntologyConflicts",
"findOrphanPages",
"findTrajectory",
diff --git a/test/fixtures/goldens/exports/types.json b/test/fixtures/goldens/exports/types.json
index be5cf8449a..3dc603582a 100644
--- a/test/fixtures/goldens/exports/types.json
+++ b/test/fixtures/goldens/exports/types.json
@@ -86,6 +86,7 @@
"findByTitleFuzzy: (name: string, dirPrefix?: string, minSimilarity?: number, sourceId?: string) => Promise<{ slug: string; similarity: number; } | null>",
"findCandidateDuplicates: (source_id: string, entitySlug: string, factText: string, opts?: { k?: number; embedding?: Float32Array; embeddingModel?: string | null; attributedTo?: FactAttribution | null; }) => Promise<FactRow[]>",
"findDuplicatePage?: ((sourceId: string, opts: { hash: string; frontmatterId?: string | null; excludeSlug?: string; }) => Promise<{ slug: string; id: number; } | null>) | undefined",
+ "findDuplicatePages?: ((sourceId: string, inputs: ReadonlyArray<{ hash: string; frontmatterId?: string | null; excludeSlug?: string; }>) => Promise<Array<{ slug: string; id: number; } | null>>) | undefined",
"findOntologyConflicts: (opts?: PageReadScope & { minConfidence?: number; visibility?: OntologyReadOpts[\"visibility\"]; }) => Promise<OntologyConflict[]>",
"findOrphanPages: (opts?: PageReadScope & { sourceId?: string; sourceIds?: string[]; mode?: \"inbound\" | \"islanded\"; }) => Promise<Array<{ slug: string; title: string; domain: string | null; type?: string | null; quarantined?: boolean; source_id?: string; }>>",
"findTrajectory: (opts: TrajectoryOpts) => Promise<TrajectoryPoint[]>",
@@ -171,7 +172,7 @@
"putPage: (slug: string, page: PageInput, opts?: PageWriteOptions) => Promise<Page>",
"putRawData: (slug: string, source: string, data: object, opts?: { sourceId?: string; }) => Promise<void>",
"readPageSnapshot: (slug: string, opts?: PageSnapshotOptions) => Promise<PageSnapshot | null>",
- "readPageSnapshotsBatch: (refs: ReadonlyArray<{ slug: string; sourceId: string; }>, opts?: { maxBytes?: number; }) => Promise<PageSnapshotBatch>",
+ "readPageSnapshotsBatch: (refs: ReadonlyArray<{ slug: string; sourceId: string; }>, opts?: { maxBytes?: number; includeDeleted?: boolean; absentIsNull?: boolean; }) => Promise<PageSnapshotBatch>",
"readonly kind: \"postgres\" | \"pglite\"",
"reconnect: (ctx?: { error?: unknown; }) => Promise<void>",
"refreshPageBody: (slug: string, sourceId: string, compiledTruth: string, timeline: string, contentHash: string) => Promise<void>",
@@ -1048,6 +1049,7 @@
"findByTitleFuzzy: (name: string, dirPrefix?: string, minSimilarity?: number, sourceId?: string) => Promise<{ slug: string; similarity: number; } | null>",
"findCandidateDuplicates: (source_id: string, entitySlug: string, factText: string, opts?: { k?: number; embedding?: Float32Array; embeddingModel?: string | null; attributedTo?: FactAttribution | null; }) => Promise<FactRow[]>",
"findDuplicatePage: (sourceId: string, opts: { hash: string; frontmatterId?: string | null; excludeSlug?: string; }) => Promise<{ slug: string; id: number; } | null>",
+ "findDuplicatePages: (sourceId: string, inputs: Parameters<typeof findDuplicatePages>[2]) => Promise<({ slug: string; id: number; } | null)[]>",
"findOntologyConflicts: (opts?: PageReadScope & { minConfidence?: number; visibility?: OntologyReadOpts[\"visibility\"]; }) => Promise<OntologyConflict[]>",
"findOrphanPages: (opts?: { sourceId?: string; sourceIds?: string[]; excludePrivate?: boolean; mode?: \"inbound\" | \"islanded\"; }) => Promise<Array<{ slug: string; title: string; domain: string | null; type?: string | null; quarantined?: boolean; source_id?: string; }>>",
"findTrajectory: (opts: TrajectoryOpts) => Promise<TrajectoryPoint[]>",
@@ -1170,7 +1172,7 @@
"putPage: (slug: string, page: PageInput, opts?: PageWriteOptions) => Promise<Page>",
"putRawData: (slug: string, source: string, data: object, opts?: { sourceId?: string; }) => Promise<void>",
"readPageSnapshot: (slug: string, opts?: PageSnapshotOptions) => Promise<PageSnapshot | null>",
- "readPageSnapshotsBatch: (refs: ReadonlyArray<{ slug: string; sourceId: string; }>, opts?: { maxBytes?: number; }) => Promise<PageSnapshotBatch>",
+ "readPageSnapshotsBatch: (refs: ReadonlyArray<{ slug: string; sourceId: string; }>, opts?: { maxBytes?: number; includeDeleted?: boolean; absentIsNull?: boolean; }) => Promise<PageSnapshotBatch>",
"readonly kind: \"postgres\"",
"reconnect: (ctx?: { error?: unknown; }) => Promise<void>",
"refreshPageBody: (slug: string, sourceId: string, compiledTruth: string, timeline: string, contentHash: string) => Promise<void>",
@@ -3264,6 +3266,7 @@
"findByTitleFuzzy: (name: string, dirPrefix?: string, minSimilarity?: number, sourceId?: string) => Promise<{ slug: string; similarity: number; } | null>",
"findCandidateDuplicates: (source_id: string, entitySlug: string, factText: string, opts?: { k?: number; embedding?: Float32Array; embeddingModel?: string | null; attributedTo?: FactAttribution | null; }) => Promise<FactRow[]>",
"findDuplicatePage?: ((sourceId: string, opts: { hash: string; frontmatterId?: string | null; excludeSlug?: string; }) => Promise<{ slug: string; id: number; } | null>) | undefined",
+ "findDuplicatePages?: ((sourceId: string, inputs: ReadonlyArray<{ hash: string; frontmatterId?: string | null; excludeSlug?: string; }>) => Promise<Array<{ slug: string; id: number; } | null>>) | undefined",
"findOntologyConflicts: (opts?: PageReadScope & { minConfidence?: number; visibility?: OntologyReadOpts[\"visibility\"]; }) => Promise<OntologyConflict[]>",
"findOrphanPages: (opts?: PageReadScope & { sourceId?: string; sourceIds?: string[]; mode?: \"inbound\" | \"islanded\"; }) => Promise<Array<{ slug: string; title: string; domain: string | null; type?: string | null; quarantined?: boolean; source_id?: string; }>>",
"findTrajectory: (opts: TrajectoryOpts) => Promise<TrajectoryPoint[]>",
@@ -3349,7 +3352,7 @@
"putPage: (slug: string, page: PageInput, opts?: PageWriteOptions) => Promise<Page>",
"putRawData: (slug: string, source: string, data: object, opts?: { sourceId?: string; }) => Promise<void>",
"readPageSnapshot: (slug: string, opts?: PageSnapshotOptions) => Promise<PageSnapshot | null>",
- "readPageSnapshotsBatch: (refs: ReadonlyArray<{ slug: string; sourceId: string; }>, opts?: { maxBytes?: number; }) => Promise<PageSnapshotBatch>",
+ "readPageSnapshotsBatch: (refs: ReadonlyArray<{ slug: string; sourceId: string; }>, opts?: { maxBytes?: number; includeDeleted?: boolean; absentIsNull?: boolean; }) => Promise<PageSnapshotBatch>",
"readonly kind: \"postgres\" | \"pglite\"",
"reconnect: (ctx?: { error?: unknown; }) => Promise<void>",
"refreshPageBody: (slug: string, sourceId: string, compiledTruth: string, timeline: string, contentHash: string) => Promise<void>",
@@ -6249,6 +6252,7 @@
"findByTitleFuzzy: (name: string, dirPrefix?: string, minSimilarity?: number, sourceId?: string) => Promise<{ slug: string; similarity: number; } | null>",
"findCandidateDuplicates: (source_id: string, entitySlug: string, factText: string, opts?: { k?: number; embedding?: Float32Array; embeddingModel?: string | null; attributedTo?: FactAttribution | null; }) => Promise<FactRow[]>",
"findDuplicatePage: (sourceId: string, opts: { hash: string; frontmatterId?: string | null; excludeSlug?: string; }) => Promise<{ slug: string; id: number; } | null>",
+ "findDuplicatePages: (sourceId: string, inputs: Parameters<typeof pagesImpl.findDuplicatePages>[2]) => Promise<({ slug: string; id: number; } | null)[]>",
"findOntologyConflicts: (opts?: PageReadScope & { minConfidence?: number; visibility?: OntologyReadOpts[\"visibility\"]; }) => Promise<OntologyConflict[]>",
"findOrphanPages: (opts?: { sourceId?: string; sourceIds?: string[]; excludePrivate?: boolean; mode?: \"inbound\" | \"islanded\"; }) => Promise<Array<{ slug: string; title: string; domain: string | null; type?: string | null; quarantined?: boolean; source_id?: string; }>>",
"findTrajectory: (opts: TrajectoryOpts) => Promise<TrajectoryPoint[]>",
@@ -6366,7 +6370,7 @@
"putPage: (slug: string, page: PageInput, opts?: PageWriteOptions) => Promise<Page>",
"putRawData: (slug: string, source: string, data: object, opts?: { sourceId?: string; }) => Promise<void>",
"readPageSnapshot: (slug: string, opts?: PageSnapshotOptions) => Promise<PageSnapshot | null>",
- "readPageSnapshotsBatch: (refs: ReadonlyArray<{ slug: string; sourceId: string; }>, opts?: { maxBytes?: number; }) => Promise<PageSnapshotBatch>",
+ "readPageSnapshotsBatch: (refs: ReadonlyArray<{ slug: string; sourceId: string; }>, opts?: { maxBytes?: number; includeDeleted?: boolean; absentIsNull?: boolean; }) => Promise<PageSnapshotBatch>",
"readonly kind: \"pglite\"",
"reconnect: (_ctx?: { error?: unknown; }) => Promise<void>",
"refreshPageBody: (slug: string, sourceId: string, compiledTruth: string, timeline: string, contentHash: string) => Promise<void>",
diff --git a/test/fixtures/goldens/rls-scope-inventory.json b/test/fixtures/goldens/rls-scope-inventory.json
index 11e84ab13f..5b5863fa3b 100644
--- a/test/fixtures/goldens/rls-scope-inventory.json
+++ b/test/fixtures/goldens/rls-scope-inventory.json
@@ -500,6 +500,19 @@
"src-a"
]
},
+ "findDuplicatePages#default": {
+ "flagOffLanes": [
+ "pool"
+ ],
+ "flagOffOpensTransaction": false,
+ "flagOn": "scoped",
+ "flagOnLanes": [
+ "tx"
+ ],
+ "flagOnScopes": [
+ "src-a"
+ ]
+ },
"findOntologyConflicts#default": {
"flagOffLanes": [
"pool"
@@ -3367,13 +3380,14 @@
}
},
"static": {
- "callSites": 24,
+ "callSites": 25,
"directMethods": {
"_searchKeywordCJK": 1,
"countChunklessPagesWithContent": 1,
"countStaleChunks": 1,
"countStalePagesForExtraction": 1,
"findDuplicatePage": 1,
+ "findDuplicatePages": 1,
"getAllSlugs": 1,
"getBacklinks": 1,
"getChunkWindows": 1,
@@ -3438,6 +3452,7 @@
"findByTitleFuzzy": "none",
"findCandidateDuplicates": "none",
"findDuplicatePage": "direct",
+ "findDuplicatePages": "direct",
"findOntologyConflicts": "none",
"findOrphanPages": "none",
"findTrajectory": "none",
diff --git a/test/fixtures/goldens/sql-text/_classification.json b/test/fixtures/goldens/sql-text/_classification.json
index 8a2408e072..bd603e59bc 100644
--- a/test/fixtures/goldens/sql-text/_classification.json
+++ b/test/fixtures/goldens/sql-text/_classification.json
@@ -18,7 +18,7 @@
"out-of-scope:search (FTS/vector hot paths, dialect-specific, not a W1 domain)": 3,
"out-of-scope:shared-read-enrichment (already one SQL copy in search/read-enrichment.ts)": 9,
"out-of-scope:stats-health (brain-wide aggregates)": 2,
- "pages": 34,
+ "pages": 35,
"salience": 5,
"sources": 2,
"tags": 3,
@@ -69,6 +69,7 @@
"findByTitleFuzzy": "pages",
"findCandidateDuplicates": "facts",
"findDuplicatePage": "pages",
+ "findDuplicatePages": "pages",
"findOntologyConflicts": "facts",
"findOrphanPages": "links",
"findTrajectory": "facts",
diff --git a/test/fixtures/goldens/sql-text/_driver.json b/test/fixtures/goldens/sql-text/_driver.json
index 6bdd51ca64..7cc56b8727 100644
--- a/test/fixtures/goldens/sql-text/_driver.json
+++ b/test/fixtures/goldens/sql-text/_driver.json
@@ -2271,7 +2271,7 @@
"via": "tagged"
},
{
- "paramCount": 3,
+ "paramCount": 4,
"unsafeOptions": {
"prepare": true,
"simple": false
@@ -2662,6 +2662,19 @@
}
]
},
+ "findDuplicatePages": {
+ "default": [
+ {
+ "paramCount": 2,
+ "unsafeOptions": {
+ "cancelFence": false,
+ "prepare": true,
+ "simple": false
+ },
+ "via": "unsafe"
+ }
+ ]
+ },
"getAllSlugs": {
"default": [
{
@@ -3321,7 +3334,7 @@
"readPageSnapshotsBatch": {
"default": [
{
- "paramCount": 3,
+ "paramCount": 4,
"unsafeOptions": {
"prepare": true,
"simple": false
diff --git a/test/fixtures/goldens/sql-text/links.json b/test/fixtures/goldens/sql-text/links.json
index 61d74104ed..8e1bb14c24 100644
--- a/test/fixtures/goldens/sql-text/links.json
+++ b/test/fixtures/goldens/sql-text/links.json
@@ -513,10 +513,11 @@
"params": [
"array<string>",
"array<string>",
+ "boolean",
"number"
],
- "sql": "WITH wanted AS ( SELECT v.slug AS batch_slug, v.source_id AS batch_source_id, v.n AS batch_n, p.id AS batch_page_id, COALESCE(sum(octet_length(p.compiled_truth) + COALESCE(octet_length(p.timeline), 0)) OVER (ORDER BY v.n ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), 0) AS batch_prior_bytes FROM unnest($1::text[], $2::text[]) WITH ORDINALITY AS v(slug, source_id, n) LEFT JOIN pages p ON p.slug = v.slug AND p.source_id = v.source_id AND p.deleted_at IS NULL ), chosen AS ( SELECT w.batch_n, w.batch_slug, w.batch_source_id, p.* FROM wanted w LEFT JOIN pages p ON p.id = w.batch_page_id WHERE w.batch_n = 1 OR w.batch_prior_bytes < $3 ) SELECT p.*, (SELECT s.incarnation FROM sources s WHERE s.id=p.source_id) AS source_incarnation, COALESCE((SELECT jsonb_agg(t.tag ORDER BY t.tag) FROM tags t WHERE t.page_id=p.id), '[]'::jsonb) AS snapshot_tags, wd.snapshot_withdrawals, wd.snapshot_global_purges, CASE WHEN wd.snapshot_withdrawals <> '[]'::jsonb OR (wd.snapshot_global_purges->>'count')::int > 0 THEN (SELECT string_agg(regexp_replace(lower(line), '[[:space:]]+', ' ', 'g'), chr(10) ORDER BY ord) FROM unnest(string_to_array(p.compiled_truth,chr(10))) WITH ORDINALITY AS lines(line,ord)) END AS fingerprint_body, CASE WHEN wd.snapshot_withdrawals <> '[]'::jsonb OR (wd.snapshot_global_purges->>'count')::int > 0 THEN (SELECT string_agg(regexp_replace(lower(line), '[[:space:]]+', ' ', 'g'), chr(10) ORDER BY ord) FROM unnest(string_to_array(p.timeline,chr(10))) WITH ORDINALITY AS lines(line,ord)) END AS fingerprint_timeline FROM chosen p CROSS JOIN LATERAL (SELECT COALESCE((SELECT jsonb_agg(jsonb_build_object('visibility',w.visibility,'fact_hash',w.fact_hash,'withdrawn_at',w.withdrawn_at) ORDER BY w.visibility,w.fact_hash) FROM (SELECT visibility,fact_hash,min(withdrawn_at) AS withdrawn_at FROM fact_withdrawals WHERE source_id=p.source_id AND (subject='*' OR subject=p.slug) GROUP BY visibility,fact_hash) w), '[]'::jsonb) || COALESCE((SELECT jsonb_agg(jsonb_build_object('visibility',x.visibility,'fact_hash',x.fact_hash,'withdrawn_at',x.purged_at,'purged',true) ORDER BY x.visibility,x.fact_hash) FROM (SELECT visibility,fact_hash,min(purged_at) AS purged_at FROM fact_purges WHERE source_id=p.source_id AND subject=p.slug GROUP BY visibility,fact_hash) x), '[]'::jsonb) AS snapshot_withdrawals, (SELECT jsonb_build_object('count',count(*),'latest',max(g.purged_at)) FROM fact_purges g WHERE g.source_id=p.source_id AND g.subject='*') AS snapshot_global_purges) wd ORDER BY p.batch_n",
- "textSha256": "282bfad54f9c86257513a754823a393e24bd1d50ebac9d9b3de5f8738529310e"
+ "sql": "WITH wanted AS ( SELECT v.slug AS batch_slug, v.source_id AS batch_source_id, v.n AS batch_n, p.id AS batch_page_id, COALESCE(sum(octet_length(p.compiled_truth) + COALESCE(octet_length(p.timeline), 0)) OVER (ORDER BY v.n ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), 0) AS batch_prior_bytes FROM unnest($1::text[], $2::text[]) WITH ORDINALITY AS v(slug, source_id, n) LEFT JOIN pages p ON p.slug = v.slug AND p.source_id = v.source_id AND ($3::boolean OR p.deleted_at IS NULL) ), chosen AS ( SELECT w.batch_n, w.batch_slug, w.batch_source_id, p.* FROM wanted w LEFT JOIN pages p ON p.id = w.batch_page_id WHERE w.batch_n = 1 OR w.batch_prior_bytes < $4 ) SELECT p.*, (SELECT s.incarnation FROM sources s WHERE s.id=p.source_id) AS source_incarnation, COALESCE((SELECT jsonb_agg(t.tag ORDER BY t.tag) FROM tags t WHERE t.page_id=p.id), '[]'::jsonb) AS snapshot_tags, wd.snapshot_withdrawals, wd.snapshot_global_purges, CASE WHEN wd.snapshot_withdrawals <> '[]'::jsonb OR (wd.snapshot_global_purges->>'count')::int > 0 THEN (SELECT string_agg(regexp_replace(lower(line), '[[:space:]]+', ' ', 'g'), chr(10) ORDER BY ord) FROM unnest(string_to_array(p.compiled_truth,chr(10))) WITH ORDINALITY AS lines(line,ord)) END AS fingerprint_body, CASE WHEN wd.snapshot_withdrawals <> '[]'::jsonb OR (wd.snapshot_global_purges->>'count')::int > 0 THEN (SELECT string_agg(regexp_replace(lower(line), '[[:space:]]+', ' ', 'g'), chr(10) ORDER BY ord) FROM unnest(string_to_array(p.timeline,chr(10))) WITH ORDINALITY AS lines(line,ord)) END AS fingerprint_timeline FROM chosen p CROSS JOIN LATERAL (SELECT COALESCE((SELECT jsonb_agg(jsonb_build_object('visibility',w.visibility,'fact_hash',w.fact_hash,'withdrawn_at',w.withdrawn_at) ORDER BY w.visibility,w.fact_hash) FROM (SELECT visibility,fact_hash,min(withdrawn_at) AS withdrawn_at FROM fact_withdrawals WHERE source_id=p.source_id AND (subject='*' OR subject=p.slug) GROUP BY visibility,fact_hash) w), '[]'::jsonb) || COALESCE((SELECT jsonb_agg(jsonb_build_object('visibility',x.visibility,'fact_hash',x.fact_hash,'withdrawn_at',x.purged_at,'purged',true) ORDER BY x.visibility,x.fact_hash) FROM (SELECT visibility,fact_hash,min(purged_at) AS purged_at FROM fact_purges WHERE source_id=p.source_id AND subject=p.slug GROUP BY visibility,fact_hash) x), '[]'::jsonb) AS snapshot_withdrawals, (SELECT jsonb_build_object('count',count(*),'latest',max(g.purged_at)) FROM fact_purges g WHERE g.source_id=p.source_id AND g.subject='*') AS snapshot_global_purges) wd ORDER BY p.batch_n",
+ "textSha256": "6697c4ea2aa0153ccf9a62abf45ec8a06ff1b51fcfb23edac1eed9ac61aaecf9"
},
{
"lane": "tx",
diff --git a/test/fixtures/goldens/sql-text/pages.json b/test/fixtures/goldens/sql-text/pages.json
index de3ef79fa6..60293ffb3c 100644
--- a/test/fixtures/goldens/sql-text/pages.json
+++ b/test/fixtures/goldens/sql-text/pages.json
@@ -207,6 +207,19 @@
}
]
},
+ "findDuplicatePages": {
+ "default": [
+ {
+ "lane": "pool",
+ "params": [
+ "string",
+ "string"
+ ],
+ "sql": "SELECT DISTINCT ON (k.n) k.n, p.id, p.slug FROM jsonb_to_recordset($1::text::jsonb) AS k(n int, hash text, frontmatter_id text, exclude_slug text) JOIN pages p ON p.source_id = $2 AND p.deleted_at IS NULL AND (p.content_hash = k.hash OR (p.frontmatter->>'id' = k.frontmatter_id AND k.frontmatter_id IS NOT NULL)) AND (k.exclude_slug IS NULL OR p.slug <> k.exclude_slug) ORDER BY k.n, (p.frontmatter->>'id' IS NOT DISTINCT FROM k.frontmatter_id) DESC, p.id",
+ "textSha256": "5b29f12f7789361b6f440a9ce65564b4f85bfd8941cf37df432b1972db547798"
+ }
+ ]
+ },
"getAllSlugs": {
"default": [
{
@@ -1016,10 +1029,11 @@
"params": [
"array<string>",
"array<string>",
+ "boolean",
"number"
],
- "sql": "WITH wanted AS ( SELECT v.slug AS batch_slug, v.source_id AS batch_source_id, v.n AS batch_n, p.id AS batch_page_id, COALESCE(sum(octet_length(p.compiled_truth) + COALESCE(octet_length(p.timeline), 0)) OVER (ORDER BY v.n ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), 0) AS batch_prior_bytes FROM unnest($1::text[], $2::text[]) WITH ORDINALITY AS v(slug, source_id, n) LEFT JOIN pages p ON p.slug = v.slug AND p.source_id = v.source_id AND p.deleted_at IS NULL ), chosen AS ( SELECT w.batch_n, w.batch_slug, w.batch_source_id, p.* FROM wanted w LEFT JOIN pages p ON p.id = w.batch_page_id WHERE w.batch_n = 1 OR w.batch_prior_bytes < $3 ) SELECT p.*, (SELECT s.incarnation FROM sources s WHERE s.id=p.source_id) AS source_incarnation, COALESCE((SELECT jsonb_agg(t.tag ORDER BY t.tag) FROM tags t WHERE t.page_id=p.id), '[]'::jsonb) AS snapshot_tags, wd.snapshot_withdrawals, wd.snapshot_global_purges, CASE WHEN wd.snapshot_withdrawals <> '[]'::jsonb OR (wd.snapshot_global_purges->>'count')::int > 0 THEN (SELECT string_agg(regexp_replace(lower(line), '[[:space:]]+', ' ', 'g'), chr(10) ORDER BY ord) FROM unnest(string_to_array(p.compiled_truth,chr(10))) WITH ORDINALITY AS lines(line,ord)) END AS fingerprint_body, CASE WHEN wd.snapshot_withdrawals <> '[]'::jsonb OR (wd.snapshot_global_purges->>'count')::int > 0 THEN (SELECT string_agg(regexp_replace(lower(line), '[[:space:]]+', ' ', 'g'), chr(10) ORDER BY ord) FROM unnest(string_to_array(p.timeline,chr(10))) WITH ORDINALITY AS lines(line,ord)) END AS fingerprint_timeline FROM chosen p CROSS JOIN LATERAL (SELECT COALESCE((SELECT jsonb_agg(jsonb_build_object('visibility',w.visibility,'fact_hash',w.fact_hash,'withdrawn_at',w.withdrawn_at) ORDER BY w.visibility,w.fact_hash) FROM (SELECT visibility,fact_hash,min(withdrawn_at) AS withdrawn_at FROM fact_withdrawals WHERE source_id=p.source_id AND (subject='*' OR subject=p.slug) GROUP BY visibility,fact_hash) w), '[]'::jsonb) || COALESCE((SELECT jsonb_agg(jsonb_build_object('visibility',x.visibility,'fact_hash',x.fact_hash,'withdrawn_at',x.purged_at,'purged',true) ORDER BY x.visibility,x.fact_hash) FROM (SELECT visibility,fact_hash,min(purged_at) AS purged_at FROM fact_purges WHERE source_id=p.source_id AND subject=p.slug GROUP BY visibility,fact_hash) x), '[]'::jsonb) AS snapshot_withdrawals, (SELECT jsonb_build_object('count',count(*),'latest',max(g.purged_at)) FROM fact_purges g WHERE g.source_id=p.source_id AND g.subject='*') AS snapshot_global_purges) wd ORDER BY p.batch_n",
- "textSha256": "282bfad54f9c86257513a754823a393e24bd1d50ebac9d9b3de5f8738529310e"
+ "sql": "WITH wanted AS ( SELECT v.slug AS batch_slug, v.source_id AS batch_source_id, v.n AS batch_n, p.id AS batch_page_id, COALESCE(sum(octet_length(p.compiled_truth) + COALESCE(octet_length(p.timeline), 0)) OVER (ORDER BY v.n ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), 0) AS batch_prior_bytes FROM unnest($1::text[], $2::text[]) WITH ORDINALITY AS v(slug, source_id, n) LEFT JOIN pages p ON p.slug = v.slug AND p.source_id = v.source_id AND ($3::boolean OR p.deleted_at IS NULL) ), chosen AS ( SELECT w.batch_n, w.batch_slug, w.batch_source_id, p.* FROM wanted w LEFT JOIN pages p ON p.id = w.batch_page_id WHERE w.batch_n = 1 OR w.batch_prior_bytes < $4 ) SELECT p.*, (SELECT s.incarnation FROM sources s WHERE s.id=p.source_id) AS source_incarnation, COALESCE((SELECT jsonb_agg(t.tag ORDER BY t.tag) FROM tags t WHERE t.page_id=p.id), '[]'::jsonb) AS snapshot_tags, wd.snapshot_withdrawals, wd.snapshot_global_purges, CASE WHEN wd.snapshot_withdrawals <> '[]'::jsonb OR (wd.snapshot_global_purges->>'count')::int > 0 THEN (SELECT string_agg(regexp_replace(lower(line), '[[:space:]]+', ' ', 'g'), chr(10) ORDER BY ord) FROM unnest(string_to_array(p.compiled_truth,chr(10))) WITH ORDINALITY AS lines(line,ord)) END AS fingerprint_body, CASE WHEN wd.snapshot_withdrawals <> '[]'::jsonb OR (wd.snapshot_global_purges->>'count')::int > 0 THEN (SELECT string_agg(regexp_replace(lower(line), '[[:space:]]+', ' ', 'g'), chr(10) ORDER BY ord) FROM unnest(string_to_array(p.timeline,chr(10))) WITH ORDINALITY AS lines(line,ord)) END AS fingerprint_timeline FROM chosen p CROSS JOIN LATERAL (SELECT COALESCE((SELECT jsonb_agg(jsonb_build_object('visibility',w.visibility,'fact_hash',w.fact_hash,'withdrawn_at',w.withdrawn_at) ORDER BY w.visibility,w.fact_hash) FROM (SELECT visibility,fact_hash,min(withdrawn_at) AS withdrawn_at FROM fact_withdrawals WHERE source_id=p.source_id AND (subject='*' OR subject=p.slug) GROUP BY visibility,fact_hash) w), '[]'::jsonb) || COALESCE((SELECT jsonb_agg(jsonb_build_object('visibility',x.visibility,'fact_hash',x.fact_hash,'withdrawn_at',x.purged_at,'purged',true) ORDER BY x.visibility,x.fact_hash) FROM (SELECT visibility,fact_hash,min(purged_at) AS purged_at FROM fact_purges WHERE source_id=p.source_id AND subject=p.slug GROUP BY visibility,fact_hash) x), '[]'::jsonb) AS snapshot_withdrawals, (SELECT jsonb_build_object('count',count(*),'latest',max(g.purged_at)) FROM fact_purges g WHERE g.source_id=p.source_id AND g.subject='*') AS snapshot_global_purges) wd ORDER BY p.batch_n",
+ "textSha256": "6697c4ea2aa0153ccf9a62abf45ec8a06ff1b51fcfb23edac1eed9ac61aaecf9"
}
]
},
diff --git a/test/helpers/postgres-engine-sql-cases.ts b/test/helpers/postgres-engine-sql-cases.ts
index ab59b38618..2a01d1f112 100644
--- a/test/helpers/postgres-engine-sql-cases.ts
+++ b/test/helpers/postgres-engine-sql-cases.ts
@@ -80,7 +80,7 @@ export const DOMAIN_OF: Record<string, string> = {
'vectorIterativeScanSupported': OOS.helper,
// pages
- 'getPage': 'pages', 'readPageSnapshot': 'pages', 'readPageSnapshotsBatch': 'pages', 'lockPageKeys': 'pages', 'findDuplicatePage': 'pages',
+ 'getPage': 'pages', 'readPageSnapshot': 'pages', 'readPageSnapshotsBatch': 'pages', 'lockPageKeys': 'pages', 'findDuplicatePage': 'pages', 'findDuplicatePages': 'pages',
'putPage': 'pages', 'deletePage': 'pages', 'deletePages': 'pages', 'resolveSlugsByPaths': 'pages',
'softDeletePage': 'pages', 'softDeletePages': 'pages', 'restorePage': 'pages', 'purgeDeletedPages': 'pages',
'refreshPageBody': 'pages', 'updatePageContextualRetrievalState': 'pages', 'listPages': 'pages',
@@ -285,6 +285,9 @@ export const SQL_CASES: SqlCase[] = [
...variants('findDuplicatePage', [
['default', (e) => e.findDuplicatePage(SRC, { hash: 'hash-1' }), [[/FROM pages/, [{ id: 1, slug: SLUG }]]]],
]),
+ ...variants('findDuplicatePages', [
+ ['default', (e) => e.findDuplicatePages(SRC, [{ hash: 'hash-1' }, { hash: 'hash-2', frontmatterId: 'fm-1', excludeSlug: SLUG }])],
+ ]),
...variants('putPage', [
['default', (e) => e.putPage(SLUG, page), [pageRet]],
['blankBody', (e) => e.putPage(SLUG, { ...page, compiled_truth: '' }), [pageRet]],
diff --git a/test/postgres-rls-scope-inventory.test.ts b/test/postgres-rls-scope-inventory.test.ts
index 5e49ed0ee0..7dbb5eee18 100644
--- a/test/postgres-rls-scope-inventory.test.ts
+++ b/test/postgres-rls-scope-inventory.test.ts
@@ -152,8 +152,8 @@ describe('EO4 RLS scope inventory (master)', () => {
const scoping = astScoping(capture.ast);
const callSites = Object.values(capture.ast).reduce((a, m) => a + m.directCallSites, 0);
- expect(callSites).toBe(24);
- expect(Object.values(capture.ast).filter((m) => m.directCallSites > 0).length).toBe(24);
+ expect(callSites).toBe(25);
+ expect(Object.values(capture.ast).filter((m) => m.directCallSites > 0).length).toBe(25);
const byMethod = new Map<string, RuntimeObservation[]>();
for (const [key, obs] of Object.entries(capture.runtime)) {