Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(connectors): fixture runs on the production wait budget; withPausedOwnerBudget only where a test expects writer_pending

time-attack0b20a4c7c28c
diff --git a/test/connector-checkpoint-identity.test.ts b/test/connector-checkpoint-identity.test.ts
index 87f2474c1e..b021333b09 100644
--- a/test/connector-checkpoint-identity.test.ts
+++ b/test/connector-checkpoint-identity.test.ts
@@ -6,7 +6,7 @@ import { parseGoogleSourceConfig, runGoogleSync } from '../src/core/google/googl
import { disposePersistenceConsumer, startPersistenceConsumer, waitForWrite } from '../src/core/persistence/service.ts';
import type { WriteRequest } from '../src/core/persistence/model.ts';
import { withEnv } from './helpers/with-env.ts';
-import { createConnectorFixture, options, json, googleConfig, contact } from './helpers/connector-fixture.ts';
+import { createConnectorFixture, options, json, googleConfig, contact, withPausedOwnerBudget } from './helpers/connector-fixture.ts';
const { engines, env, source, boundSource, setup, teardown } = createConnectorFixture();
beforeAll(setup, 120_000);
@@ -82,7 +82,7 @@ test('#5686: a connector write still pending when the stamp lands publishes inst
await engine.executeRaw("UPDATE persistence_worktrees SET state='draining' WHERE id=$1::uuid", [f.binding.worktree_id]);
await engine.executeRaw('UPDATE persistence_brain SET enabled=true WHERE singleton=1');
const { fetcher } = peopleFetcher();
- try { await runGoogleSync(engine, f.id, parseGoogleSourceConfig(googleConfig, f.dir), options, fetcher); } catch { /* pending admission */ }
+ try { await withPausedOwnerBudget(() => runGoogleSync(engine, f.id, parseGoogleSourceConfig(googleConfig, f.dir), options, fetcher)); } catch { /* pending admission */ }
const pending = await engine.executeRaw<WriteRequest>("SELECT * FROM persistence_requests WHERE source_id=$1 AND intent->>'kind' LIKE '%import' AND state='queued'", [f.id]);
expect(pending.length).toBeGreaterThan(0);
await stamp(engine, f.id);
diff --git a/test/connector-wave3.test.ts b/test/connector-wave3.test.ts
index 78260834a8..fc5ad82f4f 100644
--- a/test/connector-wave3.test.ts
+++ b/test/connector-wave3.test.ts
@@ -25,7 +25,7 @@ import { ALL_SOURCES } from '../src/core/source-id.ts';
import type { WriteRequest } from '../src/core/persistence/model.ts';
import type { OperationContext } from '../src/core/ops/contract.ts';
import { withEnv } from './helpers/with-env.ts';
-import { createConnectorFixture, options, json, googleConfig, githubConfig, contact, issueFixture, githubFetch, withGoogleAccount, connectorPendingSet, withHealthyOwnerBudget } from './helpers/connector-fixture.ts';
+import { createConnectorFixture, options, json, googleConfig, githubConfig, contact, issueFixture, githubFetch, withGoogleAccount, connectorPendingSet, withPausedOwnerBudget } from './helpers/connector-fixture.ts';
const { home, engines, env, source, boundSource, setup, teardown } = createConnectorFixture();
beforeAll(setup, 120_000);
@@ -215,7 +215,7 @@ test('pending set: a pending write that later fails is re-fetched under a new re
const f = await boundSource(engine, githubConfig);
await engine.executeRaw("UPDATE persistence_worktrees SET state='draining' WHERE id=$1::uuid", [f.binding.worktree_id]);
const run = () => runGitHubSync(engine, f.id, parseGitHubSourceConfig(githubConfig, f.dir), { ...options, githubItem: { repo: 'acme-example/app', number: 1, kind: 'issue' } }, githubFetch());
- expect(await run()).toMatchObject({ status: 'partial', reason: 'writer_pending' });
+ expect(await withPausedOwnerBudget(() => run())).toMatchObject({ status: 'partial', reason: 'writer_pending' });
const [entry] = await connectorPendingSet(engine, f.id);
const [accepted] = await engine.executeRaw<WriteRequest>('SELECT * FROM persistence_requests WHERE source_id=$1 AND request_id=$2::uuid', [f.id, entry.requestId]);
await disposePersistenceConsumer(engine);
@@ -253,7 +253,7 @@ test('pending set: a committed-then-compacted pending receipt and a crash before
await engine.executeRaw("UPDATE persistence_worktrees SET state='draining' WHERE id=$1::uuid", [f.binding.worktree_id]);
const dup = async (url: string) => url.includes('/settings/sendAs') ? json({ sendAs: [] })
: json({ connections: [contact('first', 'First Example'), contact('first', 'First Example')], nextSyncToken: 'contacts-dup' });
- expect(await google(engine, f, dup)).toMatchObject({ status: 'partial', reason: 'writer_pending' });
+ expect(await withPausedOwnerBudget(() => google(engine, f, dup))).toMatchObject({ status: 'partial', reason: 'writer_pending' });
const imports = await engine.executeRaw<WriteRequest>("SELECT * FROM persistence_requests WHERE source_id=$1 AND intent->>'kind'='connector_v2_import'", [f.id]);
expect(imports).toHaveLength(1);
await disposePersistenceConsumer(engine);
@@ -507,22 +507,22 @@ test('pending set: a checkpoint still pending at the end of a run is recorded an
const f = await boundSource(engine, googleConfig);
let token = 0;
const { fetcher } = people(() => [contact('first', 'First Example')], { token: () => `contacts-${++token}` });
- await withHealthyOwnerBudget(() => google(engine, f, fetcher));
+ await google(engine, f, fetcher);
await engine.executeRaw("UPDATE persistence_worktrees SET state='draining' WHERE id=$1::uuid", [f.binding.worktree_id]);
await disposePersistenceConsumer(engine);
- expect(await google(engine, f, fetcher)).toMatchObject({ status: 'partial', reason: 'writer_pending' });
+ expect(await withPausedOwnerBudget(() => google(engine, f, fetcher))).toMatchObject({ status: 'partial', reason: 'writer_pending' });
const [checkpoint] = await connectorPendingSet(engine, f.id);
expect(checkpoint).toMatchObject({ itemRef: '__managed_connector_checkpoint__' });
await disposePersistenceConsumer(engine);
await engine.executeRaw("UPDATE persistence_worktrees SET state='active' WHERE id=$1::uuid", [f.binding.worktree_id]);
- expect((await withHealthyOwnerBudget(() => google(engine, f, fetcher))).status).not.toBe('partial');
+ expect((await google(engine, f, fetcher)).status).not.toBe('partial');
expect(await connectorPendingSet(engine, f.id)).toEqual([]);
}
for (const engine of engines) {
const f = await boundSource(engine, githubConfig);
await engine.executeRaw("UPDATE persistence_worktrees SET state='draining' WHERE id=$1::uuid", [f.binding.worktree_id]);
const run = (fetch: ReturnType<typeof githubFetch>, extra: object = {}) => runGitHubSync(engine, f.id, parseGitHubSourceConfig(githubConfig, f.dir), { ...options, ...extra }, fetch);
- expect(await run(githubFetch())).toMatchObject({ status: 'partial', reason: 'writer_pending' });
+ expect(await withPausedOwnerBudget(() => run(githubFetch()))).toMatchObject({ status: 'partial', reason: 'writer_pending' });
const [entry] = await connectorPendingSet(engine, f.id);
const [accepted] = await engine.executeRaw<WriteRequest>('SELECT * FROM persistence_requests WHERE request_id=$1::uuid', [entry.requestId]);
await disposePersistenceConsumer(engine);
@@ -535,10 +535,10 @@ test('pending set: a checkpoint still pending at the end of a run is recorded an
rmSync(path);
await disposePersistenceConsumer(engine);
// The provider no longer lists the item: a delta run cannot tell deletion from absence, so it keeps the entry.
- expect((await withHealthyOwnerBudget(() => run(githubFetch({ deleted: true })))).status).not.toBe('partial');
+ expect((await run(githubFetch({ deleted: true }))).status).not.toBe('partial');
expect((await connectorPendingSet(engine, f.id)).map(pending => pending.requestId)).toEqual([accepted.request_id]);
await disposePersistenceConsumer(engine);
- await withHealthyOwnerBudget(() => run(githubFetch({ deleted: true }), { full: true }));
+ await run(githubFetch({ deleted: true }), { full: true });
expect(await connectorPendingSet(engine, f.id)).toEqual([]);
expect((await readConnectorSourceStatuses(engine)).get(f.id)!.last_run).toMatchObject({ dropped_upstream: 1 });
}
diff --git a/test/fix-wave-3-integration.test.ts b/test/fix-wave-3-integration.test.ts
index 47109d3b39..c2a9b8b4e0 100644
--- a/test/fix-wave-3-integration.test.ts
+++ b/test/fix-wave-3-integration.test.ts
@@ -56,7 +56,7 @@ import { handleToolCall } from '../src/mcp/server.ts';
import { ALL_SOURCES } from '../src/core/source-id.ts';
import { withEnv } from './helpers/with-env.ts';
import { capture } from './helpers/wave-scenarios.ts';
-import { createConnectorFixture, options, json, googleConfig, githubConfig, issueFixture, githubFetch, contact, withGoogleAccount } from './helpers/connector-fixture.ts';
+import { createConnectorFixture, options, json, googleConfig, githubConfig, issueFixture, githubFetch, contact, withGoogleAccount, withPausedOwnerBudget } from './helpers/connector-fixture.ts';
import { parseGitHubSourceConfig, runGitHubSync } from '../src/core/github-source.ts';
import { renderFactsTable } from '../src/core/facts-fence.ts';
@@ -111,7 +111,7 @@ test('check 1 (S1): a cycle stamp mid-sweep while connector pages are pending; t
await engine.executeRaw('UPDATE persistence_brain SET enabled=true WHERE singleton=1');
const stamp = async () => { const now = new Date().toISOString(); await engine.updateSourceConfig(f.id, { last_source_cycle_at: now, last_full_cycle_at: now }); };
const fetcher = people(() => [contact('first', 'First Example'), contact('second', 'Second Example')], { onList: stamp });
- try { await google(engine, f, fetcher); } catch { /* the sweep stops on its wait budget with writes pending */ }
+ try { await withPausedOwnerBudget(() => google(engine, f, fetcher)); } catch { /* the sweep stops on its wait budget with writes pending */ }
const pending = await engine.executeRaw<WriteRequest>("SELECT * FROM persistence_requests WHERE source_id=$1 AND intent->>'kind' LIKE '%import' AND state='queued'", [f.id]);
expect(pending.length).toBe(2);
await stamp();
diff --git a/test/helpers/connector-fixture.ts b/test/helpers/connector-fixture.ts
index ff9ebbac8b..08608c2c80 100644
--- a/test/helpers/connector-fixture.ts
+++ b/test/helpers/connector-fixture.ts
@@ -52,8 +52,7 @@ export function createConnectorFixture() {
let closePostgres: (() => Promise<void>) | undefined;
const env = { GBRAIN_HOME: home, CONNECTOR_TEST_TOKEN: 'synthetic-local-fixture' };
const setup = async () => {
- // Paused-owner fixtures stop on a 1.5 s wait budget instead of the production 30 s.
- connectorWaitBudget.ms = testWaitMs(1_500);
+ connectorWaitBudget.ms = CONNECTOR_WAIT_BUDGET_MS;
if (backends.includes('pglite')) {
engines.push(await connectTemplateBrain(join(home, 'database')));
}
@@ -154,9 +153,10 @@ export async function settleConnectorWrites(engine: BrainEngine, sourceId: strin
* published (a healthy owner) runs on the production budget, so a slow host waits for the owner instead of
* stopping the sweep `writer_pending`. A committed write returns at once, so this costs nothing on a fast host.
*/
-export async function withHealthyOwnerBudget<T>(run: () => Promise<T>): Promise<T> {
+/** A run that expects `writer_pending` against a paused owner stops on a 1.5 s budget instead of the production 30 s. */
+export async function withPausedOwnerBudget<T>(run: () => Promise<T>): Promise<T> {
const budget = connectorWaitBudget.ms;
- connectorWaitBudget.ms = CONNECTOR_WAIT_BUDGET_MS;
+ connectorWaitBudget.ms = testWaitMs(1_500);
try { return await run(); } finally { connectorWaitBudget.ms = budget; }
}
diff --git a/test/persistence-connector-retry.test.ts b/test/persistence-connector-retry.test.ts
index f6b0d1a50a..914fa6251d 100644
--- a/test/persistence-connector-retry.test.ts
+++ b/test/persistence-connector-retry.test.ts
@@ -12,7 +12,7 @@ import { beginConnectorSync } from '../src/core/persistence/connector-sync.ts';
import { compactWriteReceipts } from '../src/core/persistence/journal.ts';
import { purgeStaleCheckpoints } from '../src/core/op-checkpoint.ts';
import { withEnv } from './helpers/with-env.ts';
-import { createConnectorFixture, options, json, googleConfig, githubConfig, contact, issueFixture, githubFetch, sourceCheckpoint, sourceCursor, cursorOf, connectorPendingSet } from './helpers/connector-fixture.ts';
+import { createConnectorFixture, options, json, googleConfig, githubConfig, contact, issueFixture, githubFetch, sourceCheckpoint, sourceCursor, cursorOf, connectorPendingSet, withPausedOwnerBudget } from './helpers/connector-fixture.ts';
const { engines, env, backends, source, boundSource, standaloneConnector, setup, teardown } = createConnectorFixture();
beforeAll(setup, 120_000);
@@ -202,11 +202,11 @@ test('checkpoint replay keeps its originally admitted page dependencies when ano
await disposePersistenceConsumer(engine);
await engine.executeRaw("UPDATE persistence_worktrees SET state='draining' WHERE id=$1::uuid", [f.binding.worktree_id]);
const state = { cursor: 'same-logical-checkpoint' };
- await expect(first.saveState(state, true)).rejects.toMatchObject({ code: 'write_pending' });
+ await expect(withPausedOwnerBudget(() => first.saveState(state, true))).rejects.toMatchObject({ code: 'write_pending' });
const [accepted] = await engine.executeRaw<WriteRequest>("SELECT * FROM persistence_requests WHERE source_id=$1 AND intent->>'kind'='connector_v2_checkpoint'", [f.id]);
const [dependency] = await engine.executeRaw<WriteRequest>("SELECT * FROM persistence_requests WHERE source_id=$1 AND slug='notes/first'", [f.id]);
expect(accepted.intent?.receipts).toEqual([dependency.id]);
- await expect(second.saveState(state, true)).rejects.toMatchObject({ code: 'write_pending', writeRequest: { request_id: accepted.request_id } });
+ await expect(withPausedOwnerBudget(() => second.saveState(state, true))).rejects.toMatchObject({ code: 'write_pending', writeRequest: { request_id: accepted.request_id } });
expect(await engine.executeRaw("SELECT id FROM persistence_requests WHERE source_id=$1 AND intent->>'kind'='connector_v2_checkpoint'", [f.id])).toHaveLength(1);
expect((await engine.executeRaw<WriteRequest>('SELECT * FROM persistence_requests WHERE id=$1::uuid', [accepted.id]))[0].intent?.receipts).toEqual([dependency.id]);
await disposePersistenceConsumer(engine);
@@ -257,7 +257,7 @@ test('concurrent connector approvals and a restarted paused owner retain one pen
const [original] = await engine.executeRaw<WriteRequest>("SELECT * FROM persistence_requests WHERE source_id=$1 AND state='failed'", [f.id]);
await engine.executeRaw("UPDATE persistence_worktrees SET state='draining' WHERE id=$1::uuid", [original.worktree_id]);
const sessions = await Promise.all([1, 2].map(() => beginConnectorSync(engine, f.id, 'github', f.cfg, { ...options, retryFailed: true })));
- const results = await Promise.allSettled(sessions.map(session => session!.importMarkdown(original.intent!.sourcePath as string, original.intent!.content as string)));
+ const results = await withPausedOwnerBudget(() => Promise.allSettled(sessions.map(session => session!.importMarkdown(original.intent!.sourcePath as string, original.intent!.content as string))));
const [retry] = await engine.executeRaw<WriteRequest>("SELECT * FROM persistence_requests WHERE source_id=$1 AND intent->>'retryOf'=$2", [f.id, original.request_id]);
expect(retry).toMatchObject({ state: 'queued' });
// #5600: a session that admitted or replayed the replacement reports accepted-pending progress; a racing approval refuses write_pending on the same receipt.
@@ -272,7 +272,7 @@ test('concurrent connector approvals and a restarted paused owner retain one pen
expect(restarted.stdout).not.toContain('CONNECTOR_FIXTURE_FETCH');
expect(JSON.parse(restarted.stdout.split('CONNECTOR_ERROR ')[1].trim())).toMatchObject({ code: 'write_pending', receipt: { request_id: retry.request_id } });
const count = await engine.executeRaw('SELECT id FROM persistence_requests WHERE source_id=$1 ORDER BY sequence', [f.id]);
- expect(await f.run()).toMatchObject({ status: 'partial', reason: 'writer_pending' });
+ expect(await withPausedOwnerBudget(() => f.run())).toMatchObject({ status: 'partial', reason: 'writer_pending' });
expect((await connectorPendingSet(engine, f.id)).map(entry => entry.requestId)).toEqual([retry.request_id]);
expect(await engine.executeRaw('SELECT id FROM persistence_requests WHERE source_id=$1 ORDER BY sequence', [f.id])).toEqual(count);
await disposePersistenceConsumer(engine);
diff --git a/test/persistence-connectors.test.ts b/test/persistence-connectors.test.ts
index 57180caed8..09f4a1c15c 100644
--- a/test/persistence-connectors.test.ts
+++ b/test/persistence-connectors.test.ts
@@ -23,7 +23,7 @@ import { publishMutation } from '../src/core/persistence/coordinator.ts';
import { claimNextWrite } from '../src/core/persistence/journal.ts';
import { localHostId } from '../src/core/persistence/identity.ts';
import { TEST_WRITE_ATTRIBUTION } from './helpers/write-attribution.ts';
-import { createConnectorFixture, options, json, googleConfig, githubConfig, contact, issueFixture, githubFetch, sourceCheckpoint, connectorPendingSet } from './helpers/connector-fixture.ts';
+import { createConnectorFixture, options, json, googleConfig, githubConfig, contact, issueFixture, githubFetch, sourceCheckpoint, connectorPendingSet, withPausedOwnerBudget } from './helpers/connector-fixture.ts';
const { home, engines, env, source, boundSource, setup, teardown } = createConnectorFixture();
beforeAll(setup, 120_000);
@@ -260,9 +260,9 @@ test('paused connector owner returns one stable receipt and resident restart con
const cfg = parseGitHubSourceConfig(githubConfig, f.dir);
const run = () => runGitHubSync(engine, f.id, cfg, options, githubFetch());
// #5600: an accepted pending write is progress; the run ends partial with the receipt in its pending set.
- expect(await run()).toMatchObject({ status: 'partial', reason: 'writer_pending' });
+ expect(await withPausedOwnerBudget(() => run())).toMatchObject({ status: 'partial', reason: 'writer_pending' });
const [pending] = await connectorPendingSet(engine, f.id);
- expect(await run()).toMatchObject({ status: 'partial', reason: 'writer_pending' });
+ expect(await withPausedOwnerBudget(() => run())).toMatchObject({ status: 'partial', reason: 'writer_pending' });
expect((await connectorPendingSet(engine, f.id)).map(entry => entry.requestId)).toEqual([pending.requestId]);
const rows = await engine.executeRaw<WriteRequest>('SELECT * FROM persistence_requests WHERE source_id=$1', [f.id]);
expect(rows).toHaveLength(1);
@@ -388,7 +388,7 @@ test('a file edit after bound connector admission survives resident replay and p
const checkpoint = await sourceCheckpoint(engine, f.id);
await engine.executeRaw("UPDATE persistence_worktrees SET state='draining' WHERE id=$1::uuid", [f.binding.worktree_id]);
body = 'New API body';
- expect(await run()).toMatchObject({ status: 'partial', reason: 'writer_pending' });
+ expect(await withPausedOwnerBudget(() => run())).toMatchObject({ status: 'partial', reason: 'writer_pending' });
const [accepted] = await engine.executeRaw<WriteRequest>("SELECT * FROM persistence_requests WHERE source_id=$1 AND state='queued' ORDER BY sequence LIMIT 1", [f.id]);
await disposePersistenceConsumer(engine);
const path = join(f.dir, 'gh/acme-example/app/1.md');
@@ -441,7 +441,7 @@ test('resident publication revalidates accepted connector revisions, incarnation
const binding = await claimWorktree(engine, f.id, f.dir);
await engine.executeRaw("UPDATE persistence_worktrees SET state='draining' WHERE id=$1::uuid", [binding.worktree_id]);
await engine.executeRaw('UPDATE persistence_brain SET enabled=true WHERE singleton=1');
- expect(await runGitHubSync(engine, f.id, parseGitHubSourceConfig(githubConfig, f.dir), options, githubFetch())).toMatchObject({ status: 'partial', reason: 'writer_pending' });
+ expect(await withPausedOwnerBudget(() => runGitHubSync(engine, f.id, parseGitHubSourceConfig(githubConfig, f.dir), options, githubFetch()))).toMatchObject({ status: 'partial', reason: 'writer_pending' });
const [accepted] = await engine.executeRaw<WriteRequest>('SELECT * FROM persistence_requests WHERE source_id=$1', [f.id]);
await disposePersistenceConsumer(engine);
const [writer] = await engine.executeRaw<{ grant_ceiling: unknown }>('SELECT grant_ceiling FROM persistence_local_writers WHERE id=$1::uuid', [accepted.principal_id]);
@@ -520,7 +520,7 @@ test('a fact withdrawn between bound connector preparation and publication leave
const original = readFileSync(path, 'utf8'), before = (await engine.readPageSnapshot(slug, { sourceId: f.id }))!;
await engine.executeRaw("UPDATE persistence_worktrees SET state='draining' WHERE id=$1::uuid", [f.binding.worktree_id]);
body = `Facts: ${renderFactsTable([{ rowNum: 1, claim, kind: 'fact', confidence: 1, visibility: 'world', notability: 'medium', active: true, context: 'test evidence' }])}`;
- expect(await run()).toMatchObject({ status: 'partial', reason: 'writer_pending' });
+ expect(await withPausedOwnerBudget(() => run())).toMatchObject({ status: 'partial', reason: 'writer_pending' });
await disposePersistenceConsumer(engine);
await engine.executeRaw("UPDATE persistence_worktrees SET state='active' WHERE id=$1::uuid", [f.binding.worktree_id]);
const claimed = (await claimNextWrite(engine, localHostId()))!;
diff --git a/test/persistence-test-seams.test.ts b/test/persistence-test-seams.test.ts
index 6180df2c55..0c179accce 100644
--- a/test/persistence-test-seams.test.ts
+++ b/test/persistence-test-seams.test.ts
@@ -16,7 +16,7 @@ import { afterAll, expect, test } from 'bun:test';
import { MAINTENANCE_PUBLISH_WAIT_MS, MAINTENANCE_WRITE_WAIT_MS, MaintenanceWriteWait, __setMaintenanceWriteWaitForTests, maintenancePublishWaitMs } from '../src/core/persistence/maintenance-wait.ts';
import { EFFECT_RENEWAL_INTERVAL_MS, __setEffectRenewalIntervalForTests, effectRenewalInterval } from '../src/core/persistence/effects.ts';
import { CONNECTOR_WAIT_BUDGET_MS, connectorWaitBudget } from '../src/core/persistence/connector-sync.ts';
-import { createConnectorFixture } from './helpers/connector-fixture.ts';
+import { createConnectorFixture, withPausedOwnerBudget } from './helpers/connector-fixture.ts';
function expectProductionDefaults(): void {
expect(maintenancePublishWaitMs()).toBe(MAINTENANCE_PUBLISH_WAIT_MS);
@@ -57,7 +57,10 @@ test('the effect renewal seam restores the previous interval', () => {
test('the connector fixture restores the production wait budget on teardown', async () => {
const fixture = createConnectorFixture();
await fixture.setup();
- try { expect(connectorWaitBudget.ms).toBeLessThan(CONNECTOR_WAIT_BUDGET_MS); }
- finally { await fixture.teardown(); }
+ try {
+ expect(connectorWaitBudget.ms).toBe(CONNECTOR_WAIT_BUDGET_MS);
+ await withPausedOwnerBudget(async () => { expect(connectorWaitBudget.ms).toBeLessThan(CONNECTOR_WAIT_BUDGET_MS); });
+ expect(connectorWaitBudget.ms).toBe(CONNECTOR_WAIT_BUDGET_MS);
+ } finally { await fixture.teardown(); }
expectProductionDefaults();
}, 120_000);