Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(sources): set-path at the bound checkout repairs a stale local_path (#5569)
time-attack99d889650874
diff --git a/src/core/persistence/source-lifecycle.ts b/src/core/persistence/source-lifecycle.tsindex 4e9f992400..343dd64816 100644--- a/src/core/persistence/source-lifecycle.ts+++ b/src/core/persistence/source-lifecycle.ts@@ -197,7 +197,7 @@ export async function runManagedSourceLifecycle(engine:BrainEngine,input:SourceL`Claim '${input.sourceId}' at the local_path the command in fix reports, or move it to the new directory with gbrain sources set-path ${input.sourceId}; nothing was claimed.`,{fix:sourcesListFix()});const expired=input.expiredOnly?await tx.executeRaw(`SELECT id FROM sources WHERE id=$1 AND ${EXPIRED_ARCHIVE_SQL}`,[input.sourceId]):null;const noop=expired?.length===0 || input.operation==='archive'&&source?.archived || input.operation==='restore'&&!source?.archived- || input.operation==='claim'&&!!currentBinding || input.operation==='rebind'&&sameBinding;+ || ['claim','rebind'].includes(input.operation)&&sameBinding&&source?.local_path===root!.source;if(noop){await lockTopologyPrincipal(tx,principal);return topologyReceipt(await recordTopologyChange(tx,{principal,requestId,intent,operation:input.operation,sourceId:input.sourceId,incarnation:source!.incarnation,worktrees},diff --git a/test/persistence-source-lifecycle.test.ts b/test/persistence-source-lifecycle.test.tsindex 9004780172..10195f4303 100644--- a/test/persistence-source-lifecycle.test.ts+++ b/test/persistence-source-lifecycle.test.ts@@ -1,7 +1,7 @@import { afterAll, beforeAll, describe, expect, test } from 'bun:test';import { randomUUID } from 'node:crypto';import { execFileSync } from 'node:child_process';-import { cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';+import { cpSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';import { basename, join } from 'node:path';import { isPhysicalRootMetadata } from '../src/core/persistence/physical-root.ts';import { tmpdir } from 'node:os';@@ -87,6 +87,20 @@ test('running publication refuses lifecycle before metadata or generation changeexpect((await engine.executeRaw<{archived:boolean}>('SELECT archived FROM sources WHERE id=$1',[source]))[0].archived).toBe(false);}),60_000);+test('set-path at the bound checkout repairs a stale sources.local_path instead of no-oping (#5569)',()=>fixture(async(home,source,root)=>{+ const stale=join(home,'old-location');+ await engine.transaction(async tx=>{+ await tx.executeRaw("SELECT set_config('gbrain.topology_change','on',true)");+ await tx.executeRaw('UPDATE sources SET local_path=$2 WHERE id=$1',[source,stale]);+ });+ const result=await runManagedSourceLifecycle(engine,{operation:'rebind',sourceId:source,path:root}) as {noop?:boolean};+ expect(result.noop).toBeUndefined();+ const [row]=await engine.executeRaw<{local_path:string}>('SELECT local_path FROM sources WHERE id=$1',[source]);+ expect(row.local_path).toBe(realpathSync(root));+ const again=await runManagedSourceLifecycle(engine,{operation:'rebind',sourceId:source,path:root}) as {noop?:boolean};+ expect(again.noop).toBe(true);+}));+test('rebind requires exact manifest including deletion and old path remains fenced',()=>fixture(async(home,source,root)=>{const candidate=join(home,'candidate');cpSync(root,candidate,{recursive:true,filter:path=>!isPhysicalRootMetadata(basename(path))});writeFileSync(join(candidate,'extra.md'),'Unexpected');