Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(connector): healthy-owner runs in the pending-set test wait on the production budget
time-attack7a27aeeabc0d
diff --git a/test/connector-wave3.test.ts b/test/connector-wave3.test.tsindex 0950c33441..78260834a8 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 } from './helpers/connector-fixture.ts';+import { createConnectorFixture, options, json, googleConfig, githubConfig, contact, issueFixture, githubFetch, withGoogleAccount, connectorPendingSet, withHealthyOwnerBudget } from './helpers/connector-fixture.ts';const { home, engines, env, source, boundSource, setup, teardown } = createConnectorFixture();beforeAll(setup, 120_000);@@ -507,7 +507,7 @@ test('pending set: a checkpoint still pending at the end of a run is recorded anconst f = await boundSource(engine, googleConfig);let token = 0;const { fetcher } = people(() => [contact('first', 'First Example')], { token: () => `contacts-${++token}` });- await google(engine, f, fetcher);+ await withHealthyOwnerBudget(() => 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' });@@ -515,7 +515,7 @@ test('pending set: a checkpoint still pending at the end of a run is recorded anexpect(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 google(engine, f, fetcher)).status).not.toBe('partial');+ expect((await withHealthyOwnerBudget(() => google(engine, f, fetcher))).status).not.toBe('partial');expect(await connectorPendingSet(engine, f.id)).toEqual([]);}for (const engine of engines) {@@ -535,10 +535,10 @@ test('pending set: a checkpoint still pending at the end of a run is recorded anrmSync(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 run(githubFetch({ deleted: true }))).status).not.toBe('partial');+ expect((await withHealthyOwnerBudget(() => 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 run(githubFetch({ deleted: true }), { full: true });+ await withHealthyOwnerBudget(() => 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/helpers/connector-fixture.ts b/test/helpers/connector-fixture.tsindex a0e4733fa5..ff9ebbac8b 100644--- a/test/helpers/connector-fixture.ts+++ b/test/helpers/connector-fixture.ts@@ -149,6 +149,17 @@ export async function settleConnectorWrites(engine: BrainEngine, sourceId: strinexpect(settled.map(row => [row.slug, row.state])).toEqual(rows.map(row => [row.slug, 'committed']));}+/**+ * The fixture's 1.5 s wait budget is for runs against a paused owner. A run whose assertions need every write+ * 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> {+ const budget = connectorWaitBudget.ms;+ connectorWaitBudget.ms = CONNECTOR_WAIT_BUDGET_MS;+ try { return await run(); } finally { connectorWaitBudget.ms = budget; }+}+/** #5600: the pending set a managed connector run ended with (connector state row). */export async function connectorPendingSet(engine: BrainEngine, sourceId: string) {const [source] = await engine.executeRaw<{ incarnation: string }>('SELECT incarnation::text FROM sources WHERE id=$1', [sourceId]);