Skip to content

Commit 2e5559c

Browse files
committed
await for all mockModules
1 parent 59122e4 commit 2e5559c

File tree

15 files changed

+47
-44
lines changed

15 files changed

+47
-44
lines changed

backend/src/__tests__/auto-topup.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Auto Top-up System', () => {
3232
warn: () => {},
3333
}
3434

35-
beforeAll(() => {
35+
beforeAll(async () => {
3636
// Set up default mocks
3737
dbMock = mock(() =>
3838
Promise.resolve({
@@ -45,7 +45,7 @@ describe('Auto Top-up System', () => {
4545
)
4646

4747
// Mock the database
48-
mockModule('@codebuff/internal/db', () => ({
48+
await mockModule('@codebuff/internal/db', () => ({
4949
default: {
5050
query: {
5151
user: {
@@ -61,7 +61,7 @@ describe('Auto Top-up System', () => {
6161
}))
6262

6363
// Mock Stripe payment intent creation
64-
mockModule('@codebuff/internal/util/stripe', () => ({
64+
await mockModule('@codebuff/internal/util/stripe', () => ({
6565
stripeServer: {
6666
paymentIntents: {
6767
create: mock(() =>

backend/src/__tests__/usage-calculation.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ describe('Usage Calculation System', () => {
1717
warn: () => {},
1818
}
1919

20-
beforeAll(() => {
20+
beforeAll(async () => {
2121
// Mock the database module before importing the function
22-
mockModule('@codebuff/internal/db', () => ({
22+
await mockModule('@codebuff/internal/db', () => ({
2323
default: {
2424
select: () => ({
2525
from: () => ({
@@ -61,7 +61,7 @@ describe('Usage Calculation System', () => {
6161
]
6262

6363
// Mock the database module with the test data
64-
mockModule('@codebuff/internal/db', () => ({
64+
await mockModule('@codebuff/internal/db', () => ({
6565
default: {
6666
select: () => ({
6767
from: () => ({
@@ -98,7 +98,7 @@ describe('Usage Calculation System', () => {
9898
]
9999

100100
// Mock the database module with the test data
101-
mockModule('@codebuff/internal/db', () => ({
101+
await mockModule('@codebuff/internal/db', () => ({
102102
default: {
103103
select: () => ({
104104
from: () => ({
@@ -145,7 +145,7 @@ describe('Usage Calculation System', () => {
145145
]
146146

147147
// Mock the database module with the test data
148-
mockModule('@codebuff/internal/db', () => ({
148+
await mockModule('@codebuff/internal/db', () => ({
149149
default: {
150150
select: () => ({
151151
from: () => ({
@@ -201,7 +201,7 @@ describe('Usage Calculation System', () => {
201201
]
202202

203203
// Mock the database module with the test data
204-
mockModule('@codebuff/internal/db', () => ({
204+
await mockModule('@codebuff/internal/db', () => ({
205205
default: {
206206
select: () => ({
207207
from: () => ({

common/src/testing/mock-modules.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ let mockModuleCache: Record<string, MockResult> = {}
1313
* @param renderMocks - function to generate mocks (by their named or default exports)
1414
* @returns an object
1515
*/
16-
export const mockModule = async (
16+
export async function mockModule(
1717
modulePath: string,
1818
renderMocks: () => Record<string, any>,
19-
): Promise<MockResult> => {
19+
): Promise<MockResult> {
2020
let original = originalModuleCache[modulePath] ?? {
2121
...(await import(modulePath)),
2222
}

evals/git-evals/run-single-eval-process.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function main() {
6060
// Setup environment for this process
6161
setProjectRoot(projectPath)
6262
setupTestEnvironmentVariables()
63-
createFileReadingMock(projectPath)
63+
await createFileReadingMock(projectPath)
6464
recreateShell(projectPath)
6565
setWorkingDirectory(projectPath)
6666

evals/git-evals/run-single-eval.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async function runSingleEvalTask(options: {
176176

177177
// Setup project context
178178
setProjectRoot(projectPath)
179-
createFileReadingMock(projectPath)
179+
await createFileReadingMock(projectPath)
180180
recreateShell(projectPath)
181181
setWorkingDirectory(projectPath)
182182

evals/scaffolding.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ function readMockFile(projectRoot: string, filePath: string): string | null {
7676

7777
let toolCalls: ClientToolCall[] = []
7878
let toolResults: ToolResultPart[] = []
79-
export function createFileReadingMock(projectRoot: string) {
80-
mockModule('@codebuff/backend/websockets/websocket-action', () => ({
79+
export async function createFileReadingMock(projectRoot: string) {
80+
await mockModule('@codebuff/backend/websockets/websocket-action', () => ({
8181
requestFiles: ((params: { ws: WebSocket; filePaths: string[] }) => {
8282
const files: Record<string, string | null> = {}
8383
for (const filePath of params.filePaths) {

evals/test-setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export async function setupTestEnvironment(projectName: string) {
155155

156156
const repoPath = path.join(TEST_REPOS_DIR, projectName)
157157
setProjectRoot(repoPath)
158-
createFileReadingMock(repoPath)
158+
await createFileReadingMock(repoPath)
159159
recreateShell(repoPath)
160160
setWorkingDirectory(repoPath)
161161

knowledge.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ base-lite "fix this bug" # Works right away!
8787
- For automated operations, prefer non-interactive git commands when possible (e.g., `git rebase --continue` after resolving conflicts programmatically)
8888

8989
**Common Interactive Git Commands (require tmux):**
90+
9091
- `git rebase --continue` - Continue rebase after resolving conflicts
9192
- `git rebase --skip` - Skip current commit during rebase
9293
- `git rebase --abort` - Abort rebase operation
@@ -106,6 +107,7 @@ base-lite "fix this bug" # Works right away!
106107
- Any git command that opens an editor (commit messages, rebase todo list, etc.)
107108

108109
**Example:**
110+
109111
```bash
110112
# ❌ Bad: Will hang waiting for input
111113
git rebase --continue
@@ -270,7 +272,8 @@ spyOn(Date, 'now').mockImplementation(() => 1234567890)
270272
Only use for overriding module constants when absolutely necessary:
271273

272274
- Use wrapper functions in `@codebuff/common/testing/mock-modules.ts`
273-
- Call `clearMockedModules()` in `afterAll`
275+
- Use `await mockModule(...)` as a drop-in replacement for `mock.module`
276+
- Call `clearMockedModules()` in `afterAll` (or `afterEach`)
274277

275278
### Test Setup Patterns
276279

npm-app/src/__tests__/tool-handlers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ describe('handleCodeSearch', () => {
2626
return projectRoot
2727
})
2828

29-
beforeAll(() => {
30-
mockModule('@codebuff/npm-app/project-files', () => ({
29+
beforeAll(async () => {
30+
await mockModule('@codebuff/npm-app/project-files', () => ({
3131
getProjectRoot: mockGetProjectRoot,
3232
}))
3333
})

npm-app/src/utils/__tests__/rage-detector.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ describe('Rage Detectors', () => {
3535
let timeoutId = 1
3636
const mockTrackEvent = mock(() => {})
3737

38-
beforeAll(() => {
38+
beforeAll(async () => {
3939
// Mock the analytics module
40-
mockModule('@codebuff/npm-app/utils/analytics', () => ({
40+
await mockModule('@codebuff/npm-app/utils/analytics', () => ({
4141
trackEvent: mockTrackEvent,
4242
}))
4343

4444
// Mock the sleep function from common/util/promise
45-
mockModule('@codebuff/common/util/promise', () => ({
45+
await mockModule('@codebuff/common/util/promise', () => ({
4646
sleep: mock(() => Promise.resolve()),
4747
}))
4848
})

0 commit comments

Comments
 (0)