Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Count merge-commit changes when doctor decides a read-only mirror holds only access policy

garrytan3c52ad3b5686
diff --git a/src/commands/doctor/checks/git-convergence.ts b/src/commands/doctor/checks/git-convergence.ts
index ffcde52147..7e008db36d 100644
--- a/src/commands/doctor/checks/git-convergence.ts
+++ b/src/commands/doctor/checks/git-convergence.ts
@@ -97,7 +97,8 @@ function publishableRemote(top: string, branch: string | null): boolean {
/**
* GST-2634: marks each root whose sources are all read-only mirrors (mirror_read_only), and exempts the unpushed commits of
* a root that can never publish them: every source has sync off, there is no publishable remote or every source is
- * mirror_read_only, and every commit ahead touches only a source's access policy files.
+ * mirror_read_only, and what HEAD adds over its fork point with upstream (merge commits included) is only a source's
+ * access policy files.
*/
async function markReadOnlyMirrors(engine: BrainEngine, reports: RootReport[], now: number): Promise<void> {
const sources = new Map((await engine.executeRaw<{ id: string; local_path: string | null; config: unknown }>('SELECT id, local_path, config FROM sources')
@@ -112,7 +113,7 @@ async function markReadOnlyMirrors(engine: BrainEngine, reports: RootReport[], n
const prefix = relative(canonicalPath(report.root), canonicalPath(row!.local_path ?? report.root)).split(sep).join('/');
return [POLICY_FILE, APPROVED_FILE].map(file => prefix ? `${prefix}/${file}` : file);
}));
- const paths = git(report.root, ['log', '@{u}..HEAD', '--format=', '--name-only', '--no-renames']);
+ const paths = git(report.root, ['diff', '--name-only', '--no-renames', '@{u}...HEAD']);
if (paths === null || !paths.split('\n').filter(Boolean).every(path => policyPaths.has(path))) continue;
report.policy_only_mirror = true;
report.status = report.oldest_dirty_at && now - Date.parse(report.oldest_dirty_at) > GIT_CONVERGENCE_WARN_MS ? 'warn' : 'ok';
diff --git a/test/doctor-git-convergence-mirror-gst2634.test.ts b/test/doctor-git-convergence-mirror-gst2634.test.ts
index 10990ac066..c2a74feed7 100644
--- a/test/doctor-git-convergence-mirror-gst2634.test.ts
+++ b/test/doctor-git-convergence-mirror-gst2634.test.ts
@@ -71,6 +71,24 @@ test('the same mirror with a page file in the ahead commit still fails', async (
expect(check?.status).toBe('fail');
});
+test('a page change that only a merge commit ahead of upstream carries still fails', async () => {
+ const work = mirror('merge-ahead', ['.gbrain/access.yml'], true);
+ const main = git(work, ['branch', '--show-current']);
+ git(work, ['checkout', '-q', '-b', 'side', 'origin/' + main]);
+ mkdirSync(join(work, '.gbrain'), { recursive: true });
+ writeFileSync(join(work, '.gbrain/access.approved'), 'approved\n');
+ git(work, ['add', '-A']); git(work, ['commit', '-q', '-m', 'approved rules']);
+ git(work, ['checkout', '-q', main]);
+ git(work, ['merge', '-q', '--no-ff', '--no-commit', 'side']);
+ writeFileSync(join(work, 'note.md'), 'edited in the merge\n');
+ git(work, ['add', '-A']);
+ const date = new Date(Date.now() - 30 * HOUR).toISOString();
+ git(work, ['commit', '-q', '-m', 'merge side'], { GIT_AUTHOR_DATE: date, GIT_COMMITTER_DATE: date });
+ await addSource('mirror-m', work, { syncEnabled: false });
+ const check = await gitConvergenceCheck(engine);
+ expect(check?.status).toBe('fail');
+});
+
test('a mirror_read_only source: policy-only is info, and a page commit fails without a push or git-durability fix', async () => {
await addSource('mirror-b', mirror('ro-policy', ['.gbrain/access.yml'], false), { syncEnabled: false, mirror_read_only: true });
expect((await gitConvergenceCheck(engine))?.severity).toBe('info');