Add account browsing simulation
This commit is contained in:
1 parent
e2d7dc4b82
commit
27012399ec
31 files changed
+1476
-28
No files matched your search
@@ -43,6 +43,7 @@ describe('AccountRuntimeLoop mode gating', () => {
|
||||
function loopHarness(
|
||||
getBotMode: () => 'running' | 'scan' | 'stopped',
|
||||
growthService?: { tick: ReturnType<typeof vi.fn>; recoverAfterRestart: ReturnType<typeof vi.fn> },
|
||||
browsingService?: { tick: ReturnType<typeof vi.fn> },
|
||||
) {
|
||||
const conversationAutomation = { processPendingConversations: vi.fn().mockResolvedValue([]) };
|
||||
const responseChecker = { checkForResponses: vi.fn().mockResolvedValue([]) };
|
||||
@@ -65,13 +66,17 @@ describe('AccountRuntimeLoop mode gating', () => {
|
||||
establishmentService: { start: vi.fn(), stop: vi.fn() },
|
||||
browserClient: { close: vi.fn().mockResolvedValue(undefined) },
|
||||
...(growthService ? { growthService } : {}),
|
||||
...(browsingService ? { browsingService } : {}),
|
||||
};
|
||||
const config = { reddit: { pollIntervalMs: 1_000 } };
|
||||
const logger = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() };
|
||||
const loop = new AccountRuntimeLoop(
|
||||
resources as never, config as never, logger as never, getBotMode, { } as never,
|
||||
);
|
||||
return { loop, conversationAutomation, responseChecker, mediaSyncService, chatService, growthService };
|
||||
return {
|
||||
loop, conversationAutomation, responseChecker, mediaSyncService, chatService,
|
||||
growthService, browsingService,
|
||||
};
|
||||
}
|
||||
|
||||
/** Lets the loop complete at least one full pass before we assert. */
|
||||
@@ -204,4 +209,39 @@ describe('AccountRuntimeLoop mode gating', () => {
|
||||
await expect(runBriefly(fixture.loop)).resolves.toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('browsing simulation', () => {
|
||||
const browsingStub = () => ({ tick: vi.fn().mockResolvedValue({ kind: 'idle', reason: 'test' }) });
|
||||
|
||||
it.each(['running', 'scan'] as const)('runs in %s mode after growth', async (mode) => {
|
||||
const growth = { tick: vi.fn().mockResolvedValue({ kind: 'idle' }), recoverAfterRestart: vi.fn() };
|
||||
const browsing = browsingStub();
|
||||
const fixture = loopHarness(() => mode, growth, browsing);
|
||||
|
||||
await runBriefly(fixture.loop);
|
||||
|
||||
expect(browsing.tick).toHaveBeenCalledWith(expect.anything());
|
||||
expect(growth.tick.mock.invocationCallOrder[0])
|
||||
.toBeLessThan(browsing.tick.mock.invocationCallOrder[0]);
|
||||
});
|
||||
|
||||
it('does not run while stopped', async () => {
|
||||
const browsing = browsingStub();
|
||||
const fixture = loopHarness(() => 'stopped', undefined, browsing);
|
||||
|
||||
await runBriefly(fixture.loop);
|
||||
|
||||
expect(browsing.tick).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('isolates browsing failures from reply handling', async () => {
|
||||
const browsing = { tick: vi.fn().mockRejectedValue(new Error('simulation exploded')) };
|
||||
const fixture = loopHarness(() => 'running', undefined, browsing);
|
||||
|
||||
await runBriefly(fixture.loop);
|
||||
|
||||
expect(browsing.tick).toHaveBeenCalled();
|
||||
expect(fixture.conversationAutomation.processPendingConversations).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user