Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(atoms): follow a rename alias only while no page row holds the old slug (#7462)
garrytan87a508edb1c3
diff --git a/src/core/persistence/atom-origin.ts b/src/core/persistence/atom-origin.tsindex 1094bb43cc..846e2527ee 100644--- a/src/core/persistence/atom-origin.ts+++ b/src/core/persistence/atom-origin.ts@@ -13,11 +13,11 @@ export function renamedSlugSql(sourceIdSql: string, slugSql: string): string {WHERE renamed.source_id=${sourceIdSql} AND renamed.alias_slug=${slugSql} AND renamed.notes='rename')`;}-/** SQL: the slug atom `a`'s origin page holds now: its `source_slug` while a live page holds it, else the slug a rename moved that page to. */+/** SQL: the slug atom `a`'s origin page holds now: its `source_slug` while any page row holds it, deleted or not, else the slug a rename moved that page to. A page created later at the old slug, even one deleted since, is never passed over for the renamed page. */export function atomOriginSlugSql(a: string): string {const slug = `(${a}.frontmatter->>'source_slug')`;return `COALESCE(CASE WHEN NOT EXISTS (SELECT 1 FROM pages live_origin WHERE live_origin.source_id=${a}.source_id- AND live_origin.slug=${slug} AND live_origin.deleted_at IS NULL) THEN ${renamedSlugSql(`${a}.source_id`, slug)} END, ${slug})`;+ AND live_origin.slug=${slug}) THEN ${renamedSlugSql(`${a}.source_id`, slug)} END, ${slug})`;}/** SQL array of every slug that may name atom `a`'s origin (its `source_slug` and that slug's rename target), for rules where either page being private makes the atom private. */diff --git a/test/rename-atom-lineage-7462.test.ts b/test/rename-atom-lineage-7462.test.tsindex da2f6a25bc..131f8c504e 100644--- a/test/rename-atom-lineage-7462.test.ts+++ b/test/rename-atom-lineage-7462.test.ts@@ -161,6 +161,19 @@ for (const backend of testBackends()) {expect(await looserAtoms('source-b')).toBe(1);});+ test('a deleted page at the old slug keeps its unstamped atom private in the lineage repair', async () => {+ await seedSource('source-h');+ await note('source-h', 'notes/reused', 'World body.', 'world');+ expect(await move('source-h', 'notes/reused', 'archive/reused')).toBe('renamed');+ const reused = await note('source-h', 'notes/reused', 'Private body.', 'private');+ await engine.putPage('atoms/reused-claim', { type: 'atom', title: 'atoms/reused-claim', compiled_truth: 'Extracted claim.',+ frontmatter: { source_slug: 'notes/reused', source_hash: reused.content_hash!.slice(0, 16) } }, { sourceId: 'source-h' });+ await engine.softDeletePage('notes/reused', { sourceId: 'source-h' });+ const plan = await visibilityRepair.plan(engine, scope('source-h'), null, { apply: false, driftClass: 'lineage' });+ expect(plan.items.map(entry => [entry.slug, entry.change?.to])).toEqual([['atoms/reused-claim', 'private']]);+ expect(await readableAtoms('source-h')).toEqual([]);+ });+test('an alias that is not a rename is not followed', async () => {await seedSource('source-c');const page = await note('source-c', 'notes/topic', 'Some body.', 'world');