Skip to content

Commit 51bfe8c

Browse files
committed
Apply prettier formatting to files from recent commit
1 parent 4582ef2 commit 51bfe8c

File tree

24 files changed

+275
-167
lines changed

24 files changed

+275
-167
lines changed

agents/e2e/context-pruner.e2e.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ function isToolCallPart(part: unknown): part is ToolCallPart {
3030
/**
3131
* Type guard to check if a message is a tool message with toolCallId.
3232
*/
33-
function isToolMessageWithId(msg: Message): msg is ToolMessage & { toolCallId: string } {
34-
return msg.role === 'tool' && 'toolCallId' in msg && typeof msg.toolCallId === 'string'
33+
function isToolMessageWithId(
34+
msg: Message,
35+
): msg is ToolMessage & { toolCallId: string } {
36+
return (
37+
msg.role === 'tool' &&
38+
'toolCallId' in msg &&
39+
typeof msg.toolCallId === 'string'
40+
)
3541
}
3642
/**
3743
* Integration tests for the context-pruner agent.

cli/src/__tests__/unit/copy-button.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,3 @@ describe('CopyButton - copied state reset timing', () => {
159159
expect(mockTimers.getPendingCount()).toBe(1)
160160
})
161161
})
162-

cli/src/hooks/__tests__/use-usage-query.test.ts

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import { createMockLogger } from '@codebuff/common/testing/mocks/logger'
2-
import {
3-
describe,
4-
test,
5-
expect,
6-
beforeEach,
7-
afterEach,
8-
mock,
9-
} from 'bun:test'
2+
import { describe, test, expect, beforeEach, afterEach, mock } from 'bun:test'
103

114
import type { ClientEnv } from '@codebuff/common/types/contracts/env'
125

@@ -240,7 +233,7 @@ describe('fetchUsageData', () => {
240233
globalThis.fetch = mock(
241234
async () => new Response('Server Error', { status: 503 }),
242235
) as unknown as typeof fetch
243-
236+
244237
const mockLogger = createMockLogger()
245238

246239
await expect(
@@ -279,7 +272,9 @@ describe('usageQueryKeys', () => {
279272
}
280273

281274
setActivityQueryData(usageQueryKeys.current(), mockData)
282-
expect(getActivityQueryData<typeof mockData>(usageQueryKeys.current())).toEqual(mockData)
275+
expect(
276+
getActivityQueryData<typeof mockData>(usageQueryKeys.current()),
277+
).toEqual(mockData)
283278
})
284279
})
285280

@@ -303,13 +298,17 @@ describe('useRefreshUsage behavior', () => {
303298

304299
// Pre-populate cache
305300
setActivityQueryData(usageQueryKeys.current(), mockData)
306-
expect(getActivityQueryData<typeof mockData>(usageQueryKeys.current())).toEqual(mockData)
301+
expect(
302+
getActivityQueryData<typeof mockData>(usageQueryKeys.current()),
303+
).toEqual(mockData)
307304

308305
// Call the underlying invalidation function (what useRefreshUsage wraps)
309306
invalidateActivityQuery(usageQueryKeys.current())
310307

311308
// Data should still exist (invalidation doesn't remove data)
312-
expect(getActivityQueryData<typeof mockData>(usageQueryKeys.current())).toEqual(mockData)
309+
expect(
310+
getActivityQueryData<typeof mockData>(usageQueryKeys.current()),
311+
).toEqual(mockData)
313312
})
314313

315314
test('invalidation marks data as stale for refetching', () => {
@@ -324,7 +323,9 @@ describe('useRefreshUsage behavior', () => {
324323
invalidateActivityQuery(usageQueryKeys.current())
325324

326325
// Data is still accessible (stale but usable)
327-
const cached = getActivityQueryData<typeof mockData>(usageQueryKeys.current())
326+
const cached = getActivityQueryData<typeof mockData>(
327+
usageQueryKeys.current(),
328+
)
328329
expect(cached?.usage).toBe(200)
329330
expect(cached?.remainingBalance).toBe(300)
330331
})
@@ -345,7 +346,9 @@ describe('usage query cache behavior', () => {
345346
}
346347

347348
setActivityQueryData(usageQueryKeys.current(), mockData)
348-
expect(getActivityQueryData<typeof mockData>(usageQueryKeys.current())).toEqual(mockData)
349+
expect(
350+
getActivityQueryData<typeof mockData>(usageQueryKeys.current()),
351+
).toEqual(mockData)
349352
})
350353

351354
test('should update cache when new data is set', () => {
@@ -364,10 +367,14 @@ describe('usage query cache behavior', () => {
364367
}
365368

366369
setActivityQueryData(usageQueryKeys.current(), initialData)
367-
expect(getActivityQueryData<typeof initialData>(usageQueryKeys.current())?.usage).toBe(100)
370+
expect(
371+
getActivityQueryData<typeof initialData>(usageQueryKeys.current())?.usage,
372+
).toBe(100)
368373

369374
setActivityQueryData(usageQueryKeys.current(), updatedData)
370-
expect(getActivityQueryData<typeof initialData>(usageQueryKeys.current())?.usage).toBe(150)
375+
expect(
376+
getActivityQueryData<typeof initialData>(usageQueryKeys.current())?.usage,
377+
).toBe(150)
371378
})
372379

373380
test('should preserve data after invalidation', () => {
@@ -382,7 +389,9 @@ describe('usage query cache behavior', () => {
382389
invalidateActivityQuery(usageQueryKeys.current())
383390

384391
// Data should still be accessible
385-
const cached = getActivityQueryData<typeof mockData>(usageQueryKeys.current())
392+
const cached = getActivityQueryData<typeof mockData>(
393+
usageQueryKeys.current(),
394+
)
386395
expect(cached).toEqual(mockData)
387396
})
388397

@@ -395,10 +404,14 @@ describe('usage query cache behavior', () => {
395404
}
396405

397406
setActivityQueryData(usageQueryKeys.current(), mockData)
398-
expect(getActivityQueryData<typeof mockData>(usageQueryKeys.current())).toBeDefined()
407+
expect(
408+
getActivityQueryData<typeof mockData>(usageQueryKeys.current()),
409+
).toBeDefined()
399410

400411
removeActivityQuery(usageQueryKeys.current())
401-
expect(getActivityQueryData<typeof mockData>(usageQueryKeys.current())).toBeUndefined()
412+
expect(
413+
getActivityQueryData<typeof mockData>(usageQueryKeys.current()),
414+
).toBeUndefined()
402415
})
403416

404417
test('should handle balance breakdown with all credit types', () => {
@@ -417,7 +430,9 @@ describe('usage query cache behavior', () => {
417430
}
418431

419432
setActivityQueryData(usageQueryKeys.current(), mockData)
420-
const cached = getActivityQueryData<typeof mockData>(usageQueryKeys.current())
433+
const cached = getActivityQueryData<typeof mockData>(
434+
usageQueryKeys.current(),
435+
)
421436

422437
expect(cached?.balanceBreakdown?.free).toBe(300)
423438
expect(cached?.balanceBreakdown?.paid).toBe(700)
@@ -436,7 +451,9 @@ describe('usage query cache behavior', () => {
436451
}
437452

438453
setActivityQueryData(usageQueryKeys.current(), mockData)
439-
const cached = getActivityQueryData<typeof mockData>(usageQueryKeys.current())
454+
const cached = getActivityQueryData<typeof mockData>(
455+
usageQueryKeys.current(),
456+
)
440457

441458
expect(cached?.usage).toBe(0)
442459
expect(cached?.remainingBalance).toBe(0)
@@ -452,10 +469,14 @@ describe('usage query cache behavior', () => {
452469
}
453470

454471
setActivityQueryData(usageQueryKeys.current(), mockData)
455-
expect(getActivityQueryData<typeof mockData>(usageQueryKeys.current())).toBeDefined()
472+
expect(
473+
getActivityQueryData<typeof mockData>(usageQueryKeys.current()),
474+
).toBeDefined()
456475

457476
resetActivityQueryCache()
458-
expect(getActivityQueryData<typeof mockData>(usageQueryKeys.current())).toBeUndefined()
477+
expect(
478+
getActivityQueryData<typeof mockData>(usageQueryKeys.current()),
479+
).toBeUndefined()
459480
})
460481

461482
test('multiple invalidations preserve data', () => {
@@ -474,6 +495,8 @@ describe('usage query cache behavior', () => {
474495
invalidateActivityQuery(usageQueryKeys.current())
475496

476497
// Data should still be there
477-
expect(getActivityQueryData<typeof mockData>(usageQueryKeys.current())).toEqual(mockData)
498+
expect(
499+
getActivityQueryData<typeof mockData>(usageQueryKeys.current()),
500+
).toEqual(mockData)
478501
})
479502
})

common/src/testing/fixtures/agent-runtime.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ export const TEST_AGENT_RUNTIME_IMPL = Object.freeze({
9898
trackEvent: () => {},
9999
logger: testLogger,
100100
fetch: testFetch,
101-
getUserInfoFromApiKey: async <T extends string>({ fields }: { apiKey: string; fields: readonly T[] }) => {
101+
getUserInfoFromApiKey: async <T extends string>({
102+
fields,
103+
}: {
104+
apiKey: string
105+
fields: readonly T[]
106+
}) => {
102107
const user = {
103108
id: 'test-user-id',
104109
email: 'test@example.com',
@@ -107,7 +112,9 @@ export const TEST_AGENT_RUNTIME_IMPL = Object.freeze({
107112
stripe_customer_id: null,
108113
banned: false,
109114
} as const
110-
return Object.fromEntries(fields.map((field) => [field, user[field as keyof typeof user]])) as {
115+
return Object.fromEntries(
116+
fields.map((field) => [field, user[field as keyof typeof user]]),
117+
) as {
111118
[K in T]: (typeof user)[K & keyof typeof user]
112119
}
113120
},
@@ -116,7 +123,9 @@ export const TEST_AGENT_RUNTIME_IMPL = Object.freeze({
116123
finishAgentRun: async () => {},
117124
addAgentStep: async () => 'test-agent-step-id',
118125
consumeCreditsWithFallback: async () => {
119-
throw new Error('consumeCreditsWithFallback not implemented in test runtime')
126+
throw new Error(
127+
'consumeCreditsWithFallback not implemented in test runtime',
128+
)
120129
},
121130
promptAiSdkStream: async function* () {
122131
throw new Error('promptAiSdkStream not implemented in test runtime')
@@ -233,7 +242,12 @@ export function createTestAgentRuntimeParams(
233242
overrides.promptAiSdkStream ??
234243
mock(async function* () {
235244
yield { type: 'text' as const, text: 'Mock response\n\n' }
236-
yield { type: 'tool-call' as const, toolName: 'end_turn', toolCallId: 'mock-id', input: {} }
245+
yield {
246+
type: 'tool-call' as const,
247+
toolName: 'end_turn',
248+
toolCallId: 'mock-id',
249+
input: {},
250+
}
237251
return 'mock-message-id'
238252
}),
239253
promptAiSdk: overrides.promptAiSdk ?? mock(async () => 'Mock response'),
@@ -261,7 +275,8 @@ export function createTestAgentRuntimeParams(
261275
email: 'test@example.com',
262276
})),
263277
handleStepsLogChunk: overrides.handleStepsLogChunk ?? mock(() => {}),
264-
requestOptionalFile: overrides.requestOptionalFile ?? mock(async () => null),
278+
requestOptionalFile:
279+
overrides.requestOptionalFile ?? mock(async () => null),
265280
sendSubagentChunk: overrides.sendSubagentChunk ?? mock(() => {}),
266281
...overrides,
267282
}
@@ -274,12 +289,20 @@ export function createTestAgentRuntimeDeps(): Omit<
274289
return {
275290
sendAction: mock(() => {}),
276291
requestFiles: mock(async () => ({})),
277-
requestToolCall: mock(async () => ({ success: true, result: 'mock result' })),
292+
requestToolCall: mock(async () => ({
293+
success: true,
294+
result: 'mock result',
295+
})),
278296
onResponseChunk: mock(() => {}),
279297
fileContext: mockFileContext,
280298
promptAiSdkStream: mock(async function* () {
281299
yield { type: 'text' as const, text: 'Mock response\n\n' }
282-
yield { type: 'tool-call' as const, toolName: 'end_turn', toolCallId: 'mock-id', input: {} }
300+
yield {
301+
type: 'tool-call' as const,
302+
toolName: 'end_turn',
303+
toolCallId: 'mock-id',
304+
input: {},
305+
}
283306
return 'mock-message-id'
284307
}),
285308
promptAiSdk: mock(async () => 'Mock response'),

common/src/testing/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ export { mockModule, clearMockedModules } from './mock-modules'
7171
// ============================================================================
7272

7373
export { createTestSetup, sleep, waitFor, captureCallArgs } from './setup'
74-
export type {
75-
CreateTestSetupOptions,
76-
TestSetupResult,
77-
} from './setup'
74+
export type { CreateTestSetupOptions, TestSetupResult } from './setup'
7875

7976
// ============================================================================
8077
// Environment Helpers (re-exported from sibling modules)

common/src/testing/mocks/crypto.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ export interface CryptoMockSpies {
8383
* ```
8484
*/
8585
export function createMockUuid(prefix: string, index?: number): UUID {
86-
const indexStr = index !== undefined ? String(index).padStart(12, '0') : '000000000000'
86+
const indexStr =
87+
index !== undefined ? String(index).padStart(12, '0') : '000000000000'
8788
return `${prefix}-0000-0000-0000-${indexStr}` as UUID
8889
}
8990

common/src/testing/mocks/database.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export interface MockSelectResult<T = unknown> {
6161
*/
6262
export interface MockSelectFromResult<T = unknown> {
6363
where: Mock<(condition: unknown) => MockSelectWhereResult<T>>
64-
leftJoin: Mock<(table: unknown, condition: unknown) => MockSelectFromResult<T>>
64+
leftJoin: Mock<
65+
(table: unknown, condition: unknown) => MockSelectFromResult<T>
66+
>
6567
innerJoin: Mock<
6668
(table: unknown, condition: unknown) => MockSelectFromResult<T>
6769
>
@@ -76,7 +78,9 @@ export interface MockSelectFromResult<T = unknown> {
7678
*/
7779
export interface MockSelectWhereResult<T = unknown> {
7880
then: Mock<(resolve: (value: T[]) => void) => Promise<T[]>>
79-
leftJoin: Mock<(table: unknown, condition: unknown) => MockSelectWhereResult<T>>
81+
leftJoin: Mock<
82+
(table: unknown, condition: unknown) => MockSelectWhereResult<T>
83+
>
8084
innerJoin: Mock<
8185
(table: unknown, condition: unknown) => MockSelectWhereResult<T>
8286
>
@@ -100,9 +104,7 @@ export interface MockDbOperations {
100104
update: Mock<(table: unknown) => MockUpdateResult>
101105
select: Mock<(columns?: unknown) => MockSelectResult>
102106
delete: Mock<(table: unknown) => MockDeleteResult>
103-
transaction: Mock<
104-
<T>(fn: (tx: MockDbOperations) => Promise<T>) => Promise<T>
105-
>
107+
transaction: Mock<<T>(fn: (tx: MockDbOperations) => Promise<T>) => Promise<T>>
106108
}
107109

108110
/**

0 commit comments

Comments
 (0)