MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / fakeIO

Function fakeIO

test/bot-stream-pump.test.ts:6–19  ·  view source on GitHub ↗

A fake transport that records every send/edit, with a hand-driven clock.

(maxLen = 50, minIntervalMs = 1000)

Source from the content-addressed store, hash-verified

4
5/** A fake transport that records every send/edit, with a hand-driven clock. */
6function fakeIO(maxLen = 50, minIntervalMs = 1000) {
7 const log: Array<{ op: 'send' | 'edit'; id: string; text: string }> = [];
8 let clock = 0;
9 let n = 0;
10 const messages = new Map<string, string>();
11 const io: PumpIO = {
12 maxLen,
13 minIntervalMs,
14 now: () => clock,
15 send: async (text) => { const id = `m${++n}`; messages.set(id, text); log.push({ op: 'send', id, text }); return { id } as MessageRef; },
16 edit: async (ref, text) => { messages.set(ref.id, text); log.push({ op: 'edit', id: ref.id, text }); },
17 };
18 return { io, log, messages, tick: (ms: number) => { clock += ms; }, sends: () => log.filter(l => l.op === 'send').length, edits: () => log.filter(l => l.op === 'edit').length };
19}
20
21describe('StreamPump', () => {
22 it('throttles: many rapid pushes inside one window cause at most the first send', async () => {

Callers 1

Calls 2

setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected