MCPcopy Index your code
hub / github.com/tiann/hapi / createSessionStub

Function createSessionStub

cli/src/opencode/opencodeRemoteLauncher.test.ts:111–167  ·  view source on GitHub ↗
(items: Array<{ message: string; mode: OpencodeMode }>)

Source from the content-addressed store, hash-verified

109}
110
111function createSessionStub(items: Array<{ message: string; mode: OpencodeMode }>) {
112 const queue = new MessageQueue2<OpencodeMode>((mode) => JSON.stringify(mode));
113 items.forEach(({ message, mode }, index) => {
114 if (index === 0 && items.length > 1) {
115 queue.pushIsolateAndClear(message, mode);
116 } else {
117 queue.push(message, mode);
118 }
119 });
120 queue.close();
121
122 const sessionEvents: Array<{ type: string; [key: string]: unknown }> = [];
123 const rpcHandlers = new Map<string, (params: unknown) => unknown>();
124 const setModelReasoningEffort = vi.fn();
125 const pushKeepAlive = vi.fn();
126
127 const client = {
128 rpcHandlerManager: {
129 registerHandler(method: string, handler: (params: unknown) => unknown) {
130 rpcHandlers.set(method, handler);
131 }
132 },
133 sendAgentMessage(_message: unknown) {},
134 sendUserMessage(_text: string) {},
135 sendSessionEvent(event: { type: string; [key: string]: unknown }) {
136 sessionEvents.push(event);
137 }
138 };
139
140 const session = {
141 path: '/tmp/hapi-opencode-test',
142 logPath: '/tmp/hapi-opencode-test/test.log',
143 client,
144 queue,
145 sessionId: null as string | null,
146 thinking: false,
147 getPermissionMode() {
148 return 'default' as const;
149 },
150 setModel(_model: string | null) {},
151 setModelReasoningEffort,
152 pushKeepAlive,
153 onThinkingChange(thinking: boolean) {
154 session.thinking = thinking;
155 },
156 onSessionFound(id: string) {
157 session.sessionId = id;
158 },
159 sendAgentMessage(_message: unknown) {},
160 sendSessionEvent(event: { type: string; [key: string]: unknown }) {
161 client.sendSessionEvent(event);
162 },
163 sendUserMessage(_text: string) {}
164 };
165
166 return { session, sessionEvents, rpcHandlers, setModelReasoningEffort, pushKeepAlive };
167}
168

Callers 1

Calls 3

pushIsolateAndClearMethod · 0.95
pushMethod · 0.95
closeMethod · 0.95

Tested by

no test coverage detected