MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / buildCtx

Function buildCtx

ui-tui/src/__tests__/billingCommand.test.ts:55–82  ·  view source on GitHub ↗
(results: Record<string, unknown>)

Source from the content-addressed store, hash-verified

53
54/** Build a ctx whose rpc routes by method name to a supplied map of results. */
55const buildCtx = (results: Record<string, unknown>) => {
56 const sys = vi.fn()
57 const calls: Array<{ method: string; params: unknown }> = []
58
59 const rpc = vi.fn((method: string, params: unknown) => {
60 calls.push({ method, params })
61
62 return Promise.resolve(results[method])
63 })
64
65 const ctx = {
66 gateway: { rpc },
67 guarded,
68 guardedErr: vi.fn(),
69 sid: 'sid-1',
70 stale: () => false,
71 transcript: { page: vi.fn(), panel: vi.fn(), sys }
72 }
73
74 const run = async (arg: string) => {
75 billingCommand.run(arg, ctx as any, 'billing')
76 await rpc.mock.results[0]?.value
77 await Promise.resolve()
78 await Promise.resolve()
79 }
80
81 return { calls, ctx, rpc, run, sys }
82}
83
84const printed = (sys: ReturnType<typeof vi.fn>) => sys.mock.calls.map(c => c[0]).join('\n')
85

Callers 1

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected