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

Function createSessionStub

cli/src/codex/codexLocalLauncher.test.ts:68–143  ·  view source on GitHub ↗
(
    permissionMode: 'default' | 'read-only' | 'safe-yolo' | 'yolo',
    codexArgs?: string[],
    path = '/tmp/worktree',
    initialTranscriptPath: string | null = null,
    replayTranscriptHistoryOnStart = false
)

Source from the content-addressed store, hash-verified

66}
67
68function createSessionStub(
69 permissionMode: 'default' | 'read-only' | 'safe-yolo' | 'yolo',
70 codexArgs?: string[],
71 path = '/tmp/worktree',
72 initialTranscriptPath: string | null = null,
73 replayTranscriptHistoryOnStart = false
74) {
75 const sessionEvents: Array<{ type: string; message?: string }> = [];
76 const userMessages: string[] = [];
77 const agentMessages: unknown[] = [];
78 let localLaunchFailure: { message: string; exitReason: 'switch' | 'exit' } | null = null;
79 let sessionId: string | null = null;
80 let transcriptPath: string | null = initialTranscriptPath;
81 const transcriptPathCallbacks: Array<(path: string) => void> = [];
82
83 return {
84 session: {
85 get sessionId() {
86 return sessionId;
87 },
88 get transcriptPath() {
89 return transcriptPath;
90 },
91 path,
92 startedBy: 'terminal' as const,
93 startingMode: 'local' as const,
94 codexArgs,
95 replayTranscriptHistoryOnStart,
96 client: {
97 rpcHandlerManager: {
98 registerHandler: () => {}
99 }
100 },
101 getPermissionMode: () => permissionMode,
102 getModelReasoningEffort: () => null,
103 onSessionFound: (value: string) => {
104 sessionId = value;
105 },
106 onTranscriptPathFound: (pathValue: string) => {
107 transcriptPath = pathValue;
108 for (const callback of transcriptPathCallbacks) {
109 callback(pathValue);
110 }
111 },
112 addTranscriptPathCallback: (callback: (path: string) => void) => {
113 transcriptPathCallbacks.push(callback);
114 },
115 removeTranscriptPathCallback: (callback: (path: string) => void) => {
116 const index = transcriptPathCallbacks.indexOf(callback);
117 if (index !== -1) {
118 transcriptPathCallbacks.splice(index, 1);
119 }
120 },
121 resetTranscriptPath: () => {
122 transcriptPath = null;
123 },
124 sendSessionEvent: (event: { type: string; message?: string }) => {
125 sessionEvents.push(event);

Callers 1

Calls 2

createQueueStubFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected