Skip to content

Commit bd7fe20

Browse files
committed
fix: resolve typecheck issues
1 parent 5ecbedf commit bd7fe20

File tree

4 files changed

+56
-22
lines changed

4 files changed

+56
-22
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,17 @@ export const TEST_AGENT_RUNTIME_IMPL = Object.freeze<
133133
* Matches the shape of @codebuff/common/analytics.
134134
*/
135135
type AnalyticsModule = {
136-
initAnalytics: (...args: unknown[]) => void
137-
trackEvent: (...args: unknown[]) => void
138-
flushAnalytics?: (...args: unknown[]) => Promise<void>
136+
initAnalytics: (...args: any[]) => void
137+
trackEvent: (...args: any[]) => void
138+
flushAnalytics?: (...args: any[]) => Promise<void>
139139
}
140140

141141
/**
142142
* Type for the bigquery module to be mocked.
143143
* Matches the shape of @codebuff/bigquery.
144144
*/
145145
type BigQueryModule = {
146-
insertTrace: (...args: unknown[]) => Promise<boolean>
146+
insertTrace: (...args: any[]) => Promise<boolean>
147147
}
148148

149149
/**

packages/internal/src/utils/__tests__/version-utils.test.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77

88
import * as versionUtils from '../version-utils'
99

10+
import type { CodebuffPgDatabase } from '../../db/types'
11+
1012
const {
1113
versionOne,
1214
parseVersion,
@@ -127,7 +129,7 @@ describe('version-utils', () => {
127129

128130
describe('getLatestAgentVersion', () => {
129131
it('should return version 0.0.0 when no agent exists', async () => {
130-
const mockDb = createVersionQueryDbMock([])
132+
const mockDb = createVersionQueryDbMock([]) as unknown as CodebuffPgDatabase
131133

132134
const result = await getLatestAgentVersion({
133135
agentId: 'test-agent',
@@ -138,7 +140,9 @@ describe('version-utils', () => {
138140
})
139141

140142
it('should return latest version when agent exists', async () => {
141-
const mockDb = createVersionQueryDbMock([{ major: 1, minor: 2, patch: 3 }])
143+
const mockDb = createVersionQueryDbMock([
144+
{ major: 1, minor: 2, patch: 3 },
145+
]) as unknown as CodebuffPgDatabase
142146

143147
const result = await getLatestAgentVersion({
144148
agentId: 'test-agent',
@@ -149,7 +153,9 @@ describe('version-utils', () => {
149153
})
150154

151155
it('should handle null values in database response', async () => {
152-
const mockDb = createVersionQueryDbMock([{ major: null, minor: null, patch: null }])
156+
const mockDb = createVersionQueryDbMock([
157+
{ major: null, minor: null, patch: null },
158+
]) as unknown as CodebuffPgDatabase
153159

154160
const result = await getLatestAgentVersion({
155161
agentId: 'test-agent',
@@ -162,7 +168,9 @@ describe('version-utils', () => {
162168

163169
describe('determineNextVersion', () => {
164170
it('should increment patch of latest version when no version provided', async () => {
165-
const mockDb = createVersionQueryDbMock([{ major: 1, minor: 2, patch: 3 }])
171+
const mockDb = createVersionQueryDbMock([
172+
{ major: 1, minor: 2, patch: 3 },
173+
]) as unknown as CodebuffPgDatabase
166174

167175
const result = await determineNextVersion({
168176
agentId: 'test-agent',
@@ -173,7 +181,7 @@ describe('version-utils', () => {
173181
})
174182

175183
it('should use provided version when higher than latest', async () => {
176-
const mockDb = createVersionQueryDbMock([])
184+
const mockDb = createVersionQueryDbMock([]) as unknown as CodebuffPgDatabase
177185

178186
const result = await determineNextVersion({
179187
agentId: 'test-agent',
@@ -185,7 +193,9 @@ describe('version-utils', () => {
185193
})
186194

187195
it('should throw error when provided version is not greater than latest', async () => {
188-
const mockDb = createVersionQueryDbMock([{ major: 2, minor: 0, patch: 0 }])
196+
const mockDb = createVersionQueryDbMock([
197+
{ major: 2, minor: 0, patch: 0 },
198+
]) as unknown as CodebuffPgDatabase
189199

190200
await expect(
191201
determineNextVersion({
@@ -200,7 +210,9 @@ describe('version-utils', () => {
200210
})
201211

202212
it('should throw error when provided version equals latest', async () => {
203-
const mockDb = createVersionQueryDbMock([{ major: 1, minor: 5, patch: 0 }])
213+
const mockDb = createVersionQueryDbMock([
214+
{ major: 1, minor: 5, patch: 0 },
215+
]) as unknown as CodebuffPgDatabase
204216

205217
await expect(
206218
determineNextVersion({
@@ -215,7 +227,7 @@ describe('version-utils', () => {
215227
})
216228

217229
it('should throw error for invalid provided version', async () => {
218-
const mockDb = createVersionQueryDbMock([])
230+
const mockDb = createVersionQueryDbMock([]) as unknown as CodebuffPgDatabase
219231

220232
await expect(
221233
determineNextVersion({
@@ -232,7 +244,9 @@ describe('version-utils', () => {
232244

233245
describe('versionExists', () => {
234246
it('should return true when version exists', async () => {
235-
const mockDb = createExistsQueryDbMock([{ id: 'test-agent' }])
247+
const mockDb = createExistsQueryDbMock([
248+
{ id: 'test-agent' },
249+
]) as unknown as CodebuffPgDatabase
236250

237251
const result = await versionExists({
238252
agentId: 'test-agent',
@@ -244,7 +258,7 @@ describe('version-utils', () => {
244258
})
245259

246260
it('should return false when version does not exist', async () => {
247-
const mockDb = createExistsQueryDbMock([])
261+
const mockDb = createExistsQueryDbMock([]) as unknown as CodebuffPgDatabase
248262

249263
const result = await versionExists({
250264
agentId: 'test-agent',

sdk/src/__tests__/code-search.test.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
import { EventEmitter } from 'events'
2+
import { PassThrough } from 'stream'
23

34
import { describe, expect, it, beforeEach, afterEach, spyOn } from 'bun:test'
45

56
import { codeSearchWithSpawn, type SpawnFn } from '../tools/code-search'
67

7-
import type { ChildProcess } from 'child_process'
8+
import type { ChildProcessByStdio } from 'child_process'
9+
import type { Readable } from 'stream'
810

911
// Helper to create a mock child process with proper ChildProcess shape
10-
function createMockChildProcess(): ChildProcess {
11-
const proc = new EventEmitter() as ChildProcess
12-
const stdout = new EventEmitter()
13-
const stderr = new EventEmitter()
12+
function createMockChildProcess(): ChildProcessByStdio<null, Readable, Readable> {
13+
const proc = new EventEmitter() as unknown as ChildProcessByStdio<
14+
null,
15+
Readable,
16+
Readable
17+
>
18+
const stdout: Readable = new PassThrough()
19+
const stderr: Readable = new PassThrough()
1420

1521
Object.defineProperty(proc, 'stdout', { value: stdout, writable: false })
1622
Object.defineProperty(proc, 'stderr', { value: stderr, writable: false })
1723
Object.defineProperty(proc, 'stdin', { value: null, writable: false })
18-
Object.defineProperty(proc, 'stdio', { value: [null, stdout, stderr], writable: false })
24+
Object.defineProperty(proc, 'stdio', {
25+
value: [null, stdout, stderr, undefined, undefined],
26+
writable: false,
27+
})
1928
Object.defineProperty(proc, 'pid', { value: 12345, writable: false })
2029
Object.defineProperty(proc, 'killed', { value: false, writable: true })
2130
Object.defineProperty(proc, 'connected', { value: false, writable: false })
@@ -29,7 +38,7 @@ function createMockChildProcess(): ChildProcess {
2938

3039
/** Creates a typed mock spawn function that captures calls and returns controlled processes */
3140
function createMockSpawn() {
32-
let currentProcess: ChildProcess = createMockChildProcess()
41+
let currentProcess = createMockChildProcess()
3342
const calls: Array<{ command: string; args: string[]; options: any }> = []
3443

3544
const spawn: SpawnFn = (command, args, options) => {

sdk/src/tools/code-search.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import * as path from 'path'
55
import { formatCodeSearchOutput } from '../../../common/src/util/format-code-search'
66
import { getBundledRgPath } from '../native/ripgrep'
77

8+
import type {
9+
ChildProcessByStdio,
10+
SpawnOptionsWithStdioTuple,
11+
StdioNull,
12+
StdioPipe,
13+
} from 'child_process'
814
import type { CodebuffToolOutput } from '../../../common/src/tools/list'
15+
import type { Readable } from 'stream'
916

1017
// Hidden directories to include in code search by default.
1118
// These are searched in addition to '.' to ensure important config/workflow files are discoverable.
@@ -18,7 +25,11 @@ const INCLUDED_HIDDEN_DIRS = [
1825
'.husky', // Git hooks
1926
]
2027

21-
export type SpawnFn = typeof nodeSpawn
28+
export type SpawnFn = (
29+
command: string,
30+
args: readonly string[],
31+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
32+
) => ChildProcessByStdio<null, Readable, Readable>
2233

2334
export function codeSearchWithSpawn(
2435
spawn: SpawnFn,

0 commit comments

Comments
 (0)