Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

test(pi): settle synthetic polling runs before close

shenjiachenge43b51c24e13
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
index 4969cee325..52cefd2be5 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
@@ -830,6 +830,7 @@ describe('pi auto-review dispatch & spawn config (mocked pi process)', () => {
});
const pollCount = () => scan.mock.calls.filter(([root]) => root.startsWith(agentHome + path.sep)).length;
let handle: PiTestSessionHandle | undefined;
+ let settleMockRun: (() => void) | undefined;
try {
handle = await start();
// Wait for the initial filesystem iterator to finish before sampling cadence.
@@ -855,11 +856,16 @@ describe('pi auto-review dispatch & spawn config (mocked pi process)', () => {
mkdirSync(runDir, { recursive: true });
writeFileSync(path.join(runDir, 'runner.cjs'), '');
writeFileSync(path.join(runDir, 'config.json'), '{}');
- writeFileSync(path.join(runDir, 'status.json'), JSON.stringify({
+ const status = {
version: 1, runId, taskId: 'poll-wake', parentSessionId: 's1',
runtimeOwnerId: captured.env.CINDY_PI_SUBAGENT_OWNER_ID,
runnerInstanceId: `launch-pending-${runId}`, state: 'queued',
startedAt: now, updatedAt: now, tasks: [],
+ };
+ const statusFile = path.join(runDir, 'status.json');
+ writeFileSync(statusFile, JSON.stringify(status));
+ settleMockRun = () => writeFileSync(statusFile, JSON.stringify({
+ ...status, state: 'stopped', updatedAt: Date.now(), endedAt: Date.now(),
}));
fireSubagentRunnerRequest('poll-launch', 'launch', runId);
await waitForResponse('poll-launch');
@@ -882,8 +888,15 @@ describe('pi auto-review dispatch & spawn config (mocked pi process)', () => {
} finally {
holdScan = false; releaseScan?.();
clock.mockRestore();
- await handle?.close();
- interval.mockRestore(); scan.mockRestore();
+ try {
+ // No real runner consumes stop in this fixture. Retire its synthetic
+ // run before account-boundary close, rather than spending the 4s grace
+ // inside a 5s test and leaking these mocks into the next parameter case.
+ try { settleMockRun?.(); }
+ finally { await handle?.close(); }
+ } finally {
+ interval.mockRestore(); scan.mockRestore();
+ }
}
});