Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(repair): fences Postgres arm, models.fence_repair routing and the time budget stop (#6188)

garrytanf3e385e93dcc
diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txt
index 56369fdc79..960bf7929e 100644
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@ -73,6 +73,7 @@ test/persistence-sync-fence-holds.test.ts
test/persistence-sync-holds.test.ts
test/persistence-writer-fences.test.ts
test/repair-embedding-effects.test.ts
+test/repair-fences.test.ts
test/repair-frontmatter.test.ts
test/scripts/test-stress-postgres.test.ts
test/shared-content-freshness.test.ts
diff --git a/test/repair-fences.test.ts b/test/repair-fences.test.ts
index 2aafe853ee..9d87b20614 100644
--- a/test/repair-fences.test.ts
+++ b/test/repair-fences.test.ts
@@ -51,6 +51,8 @@ import { planRepairSteps, runRepairSteps } from '../src/core/remediation/repairs
import { fencesRepair, type FencesPreviewDetails } from '../src/core/repair/fences.ts';
import { readUncommittedFenceRepairs } from '../src/core/fence-repair/uncommitted.ts';
import { parseRepairArgs, runRepairCommand } from '../src/commands/repair.ts';
+import { runModels } from '../src/commands/models.ts';
+import { resolveFenceRepairModel } from '../src/core/repair/fences.ts';
import { _resetCliExitVerdictForTests, currentExitCode } from '../src/core/cli-force-exit.ts';
import { isolatedPersistencePostgres } from './helpers/persistence-postgres.ts';
import { testBackends } from './helpers/test-backends.ts';
@@ -465,3 +467,33 @@ test('doctor --remediate: the plan counts the fences model estimate as paid, and
expect(calls).toHaveLength(0);
expect(s.read('people/model.md')).toBe(md('Model', noHeader()));
}), 240_000);
+
+test('models.fence_repair: gbrain models lists it on the deep tier, and setting it changes the model the repair calls', async () => withEnv(env, async () => {
+ const engine = legacyEngine;
+ const report = async () => {
+ const chunks: string[] = [];
+ const write = process.stdout.write.bind(process.stdout);
+ process.stdout.write = ((chunk: string) => { chunks.push(String(chunk)); return true; }) as typeof process.stdout.write;
+ try { await runModels(engine, ['--json']); } finally { process.stdout.write = write; }
+ return JSON.parse(chunks.join('')) as { per_task: Array<{ key: string; tier: string; resolved: string; source: string }> };
+ };
+ const before = (await report()).per_task.find(row => row.key === 'models.fence_repair')!;
+ expect(before.tier).toBe('deep');
+ expect(before.resolved).toBe(await resolveFenceRepairModel(engine));
+ await engine.setConfig('models.fence_repair', 'anthropic:claude-sonnet-5-5');
+ const after = (await report()).per_task.find(row => row.key === 'models.fence_repair')!;
+ expect(after.resolved).toBe('anthropic:claude-sonnet-5-5');
+ expect(await resolveFenceRepairModel(engine)).toBe('anthropic:claude-sonnet-5-5');
+ await engine.executeRaw("DELETE FROM config WHERE key='models.fence_repair'");
+}), 60_000);
+
+test('a run past its deadline stops with time_budget before any item and calls no model', () => each(async engine => {
+ const s = await managed(engine, { 'people/model.md': md('Model', noHeader()) });
+ await s.sync();
+ transport(() => answer(CLAIM));
+ const runner = await repairRunner(engine, { apply: true, noEmbed: true, logger: quiet });
+ const result = await runner.run('fences', await resolveRepairScope(engine, s.id), { deadline: Date.now() - 1 });
+ expect(result.stopped).toMatchObject({ reason: 'time_budget' });
+ expect(result).toMatchObject({ applied: 0, remaining: { time_budget: 1 } });
+ expect(calls).toHaveLength(0);
+}), 240_000);