MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / wrapApiForFaultInjection

Function wrapApiForFaultInjection

source code/bridge/bridgeDebug.ts:86–137  ·  view source on GitHub ↗
(
  api: BridgeApiClient,
)

Source from the content-addressed store, hash-verified

84 * Only called when USER_TYPE === 'ant' — zero overhead in external builds.
85 */
86export function wrapApiForFaultInjection(
87 api: BridgeApiClient,
88): BridgeApiClient {
89 function consume(method: BridgeFault['method']): BridgeFault | null {
90 const idx = faultQueue.findIndex(f => f.method === method)
91 if (idx === -1) return null
92 const fault = faultQueue[idx]!
93 fault.count--
94 if (fault.count <= 0) faultQueue.splice(idx, 1)
95 return fault
96 }
97
98 function throwFault(fault: BridgeFault, context: string): never {
99 logForDebugging(
100 `[bridge:debug] Injecting ${fault.kind} fault into ${context}: status=${fault.status} errorType=${fault.errorType ?? 'none'}`,
101 )
102 if (fault.kind === 'fatal') {
103 throw new BridgeFatalError(
104 `[injected] ${context} ${fault.status}`,
105 fault.status,
106 fault.errorType,
107 )
108 }
109 // Transient: mimic an axios rejection (5xx / network). No .status on
110 // the error itself — that's how the catch blocks distinguish.
111 throw new Error(`[injected transient] ${context} ${fault.status}`)
112 }
113
114 return {
115 ...api,
116 async pollForWork(envId, secret, signal, reclaimMs) {
117 const f = consume('pollForWork')
118 if (f) throwFault(f, 'Poll')
119 return api.pollForWork(envId, secret, signal, reclaimMs)
120 },
121 async registerBridgeEnvironment(config) {
122 const f = consume('registerBridgeEnvironment')
123 if (f) throwFault(f, 'Registration')
124 return api.registerBridgeEnvironment(config)
125 },
126 async reconnectSession(envId, sessionId) {
127 const f = consume('reconnectSession')
128 if (f) throwFault(f, 'ReconnectSession')
129 return api.reconnectSession(envId, sessionId)
130 },
131 async heartbeatWork(envId, workId, token) {
132 const f = consume('heartbeatWork')
133 if (f) throwFault(f, 'Heartbeat')
134 return api.heartbeatWork(envId, workId, token)
135 },
136 }
137}

Callers 1

initBridgeCoreFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected