MCPcopy Create free account
hub / github.com/tiann/hapi / createSessionStub

Function createSessionStub

cli/src/gemini/geminiRemoteLauncher.test.ts:79–131  ·  view source on GitHub ↗
(items: Array<{ message: string; mode: GeminiMode }>)

Source from the content-addressed store, hash-verified

77}
78
79function createSessionStub(items: Array<{ message: string; mode: GeminiMode }>) {
80 const queue = new MessageQueue2<GeminiMode>((mode) => JSON.stringify(mode));
81 items.forEach(({ message, mode }, index) => {
82 if (index === 0 && items.length > 1) {
83 queue.pushIsolateAndClear(message, mode);
84 } else {
85 queue.push(message, mode);
86 }
87 });
88 queue.close();
89
90 const sessionEvents: Array<{ type: string; [key: string]: unknown }> = [];
91 const rpcHandlers = new Map<string, (params: unknown) => unknown>();
92
93 const client = {
94 rpcHandlerManager: {
95 registerHandler(method: string, handler: (params: unknown) => unknown) {
96 rpcHandlers.set(method, handler);
97 }
98 },
99 sendAgentMessage(_message: unknown) {},
100 sendUserMessage(_text: string) {},
101 sendSessionEvent(event: { type: string; [key: string]: unknown }) {
102 sessionEvents.push(event);
103 }
104 };
105
106 const session = {
107 path: '/tmp/hapi-gemini-test',
108 logPath: '/tmp/hapi-gemini-test/test.log',
109 client,
110 queue,
111 sessionId: null as string | null,
112 thinking: false,
113 getPermissionMode() {
114 return 'default' as const;
115 },
116 setModel(_model: string | null) {},
117 onThinkingChange(thinking: boolean) {
118 session.thinking = thinking;
119 },
120 onSessionFound(id: string) {
121 session.sessionId = id;
122 },
123 sendAgentMessage(_message: unknown) {},
124 sendSessionEvent(event: { type: string; [key: string]: unknown }) {
125 client.sendSessionEvent(event);
126 },
127 sendUserMessage(_text: string) {}
128 };
129
130 return { session, sessionEvents, rpcHandlers };
131}
132
133describe('geminiRemoteLauncher inline model switch', () => {
134 afterEach(() => {

Callers 1

Calls 3

pushIsolateAndClearMethod · 0.95
pushMethod · 0.95
closeMethod · 0.95

Tested by

no test coverage detected