Skip to content

Commit 919a1f0

Browse files
committed
Revert "chore: prep sdk types before checks"
This reverts commit 9195ca4.
1 parent 5deead9 commit 919a1f0

File tree

10 files changed

+141
-745
lines changed

10 files changed

+141
-745
lines changed

cli/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
"prebuild": "bun run build:sdk",
2020
"build": "bun build src/index.tsx --outdir dist --target node --format esm",
2121
"build:sdk": "cd ../sdk && bun run build",
22-
"build:sdk-types": "cd ../sdk && bun run build:types",
2322
"build:binary": "bun ./scripts/build-binary.ts codecane $npm_package_version",
2423
"start": "bun run dist/index.js",
2524
"test": "bun test",
2625
"test:tmux-poc": "bun run src/__tests__/tmux-poc.ts",
27-
"pretypecheck": "bun run build:sdk-types",
26+
"pretypecheck": "bun run build:sdk",
2827
"typecheck": "tsc --noEmit -p ."
2928
},
3029
"sideEffects": false,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"format": "prettier --write \"**/*.{ts,tsx,json,md}\"",
3333
"release:npm-app": "bun run --cwd=npm-app release",
3434
"clean-ts": "find . -name '*.tsbuildinfo' -type f -delete && find . -name '.next' -type d -exec rm -rf {} + 2>/dev/null || true && find . -name 'node_modules' -type d -exec rm -rf {} + 2>/dev/null || true && bun install",
35-
"typecheck": "bun --cwd=sdk run build:types && bun --filter='*' run typecheck && echo '✅ All type checks passed!'",
35+
"typecheck": "bun --filter='*' run typecheck && echo '✅ All type checks passed!'",
3636
"test": "bun --filter='{@codebuff/backend,@codebuff/common,@codebuff/npm-app,@codebuff/agents}' run test",
3737
"init-worktree": "bun scripts/init-worktree.ts",
3838
"cleanup-worktree": "bash scripts/cleanup-worktree.sh",

packages/billing/src/__tests__/credit-delegation.test.ts

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ describe('Credit Delegation', () => {
1717
error: () => {},
1818
}
1919

20-
beforeAll(async () => {
20+
beforeAll(() => {
2121
// Mock the org-billing functions that credit-delegation depends on
22-
await mockModule('@codebuff/billing/org-billing', () => ({
22+
mockModule('@codebuff/billing/org-billing', () => ({
2323
normalizeRepositoryUrl: mock((url: string) => url.toLowerCase().trim()),
2424
extractOwnerAndRepo: mock((url: string) => {
2525
if (url.includes('codebuffai/codebuff')) {
@@ -31,61 +31,26 @@ describe('Credit Delegation', () => {
3131
}))
3232

3333
// Mock common dependencies
34-
await mockModule('@codebuff/common/db', () => {
35-
const select = mock((fields: Record<string, unknown>) => {
36-
if ('orgId' in fields && 'orgName' in fields) {
37-
return {
38-
from: () => ({
39-
innerJoin: () => ({
40-
where: () =>
41-
Promise.resolve([
42-
{
43-
orgId: 'org-123',
44-
orgName: 'CodebuffAI',
45-
orgSlug: 'codebuffai',
46-
},
47-
]),
48-
}),
49-
}),
50-
}
51-
}
52-
53-
if ('repoUrl' in fields) {
54-
return {
55-
from: () => ({
56-
where: () =>
57-
Promise.resolve([
58-
{
59-
repoUrl: 'https://github.com/codebuffai/codebuff',
60-
repoName: 'codebuff',
61-
isActive: true,
62-
},
63-
]),
64-
}),
65-
}
66-
}
67-
68-
return {
69-
from: () => ({
70-
where: () => Promise.resolve([]),
71-
}),
72-
}
73-
})
74-
75-
return {
76-
default: {
77-
select,
78-
},
79-
}
80-
})
34+
mockModule('@codebuff/common/db', () => ({
35+
default: {
36+
select: mock(() => ({
37+
from: mock(() => ({
38+
innerJoin: mock(() => ({
39+
where: mock(() =>
40+
Promise.resolve([{ orgId: 'org-123', orgName: 'CodebuffAI' }]),
41+
),
42+
})),
43+
})),
44+
})),
45+
},
46+
}))
8147

82-
await mockModule('@codebuff/common/db/schema', () => ({
48+
mockModule('@codebuff/common/db/schema', () => ({
8349
orgMember: { org_id: 'org_id', user_id: 'user_id' },
84-
org: { id: 'id', name: 'name', slug: 'slug' },
50+
org: { id: 'id', name: 'name' },
8551
orgRepo: {
8652
org_id: 'org_id',
8753
repo_url: 'repo_url',
88-
repo_name: 'repo_name',
8954
is_active: 'is_active',
9055
},
9156
}))

packages/billing/src/__tests__/org-billing.test.ts

Lines changed: 67 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
clearMockedModules,
33
mockModule,
44
} from '@codebuff/common/testing/mock-modules'
5-
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'bun:test'
5+
import { afterAll, beforeAll, describe, expect, it } from 'bun:test'
66

77
import {
88
calculateOrganizationUsageAndBalance,
@@ -49,70 +49,56 @@ const logger: Logger = {
4949
warn: () => {},
5050
}
5151

52-
const createDbMock = (options?: {
53-
grants?: typeof mockGrants | any[]
54-
insert?: () => { values: () => Promise<unknown> }
55-
update?: () => { set: () => { where: () => Promise<unknown> } }
56-
}) => {
57-
const {
58-
grants = mockGrants,
59-
insert,
60-
update,
61-
} = options ?? {}
62-
63-
return {
64-
select: () => ({
65-
from: () => ({
66-
where: () => ({
67-
orderBy: () => grants,
52+
describe('Organization Billing', () => {
53+
beforeAll(() => {
54+
mockModule('@codebuff/common/db', () => ({
55+
default: {
56+
select: () => ({
57+
from: () => ({
58+
where: () => ({
59+
orderBy: () => mockGrants,
60+
}),
61+
}),
6862
}),
69-
}),
70-
}),
71-
insert:
72-
insert ??
73-
(() => ({
74-
values: () => Promise.resolve(),
75-
})),
76-
update:
77-
update ??
78-
(() => ({
79-
set: () => ({
80-
where: () => Promise.resolve(),
63+
insert: () => ({
64+
values: () => Promise.resolve(),
8165
}),
82-
})),
83-
}
84-
}
85-
86-
describe('Organization Billing', () => {
87-
beforeAll(async () => {
88-
await mockModule('@codebuff/common/db', () => ({
89-
default: createDbMock(),
66+
update: () => ({
67+
set: () => ({
68+
where: () => Promise.resolve(),
69+
}),
70+
}),
71+
},
9072
}))
9173

92-
await mockModule('@codebuff/common/db/transaction', () => ({
93-
withSerializableTransaction: async ({
94-
callback,
95-
}: {
96-
callback: (tx: any) => Promise<unknown> | unknown
97-
}) => await callback(createDbMock()),
74+
mockModule('@codebuff/common/db/transaction', () => ({
75+
withSerializableTransaction: (fn: any) =>
76+
fn({
77+
select: () => ({
78+
from: () => ({
79+
where: () => ({
80+
orderBy: () => mockGrants,
81+
}),
82+
}),
83+
}),
84+
update: () => ({
85+
set: () => ({
86+
where: () => Promise.resolve(),
87+
}),
88+
}),
89+
}),
9890
}))
9991
})
10092

10193
afterAll(() => {
10294
clearMockedModules()
10395
})
10496

105-
afterEach(async () => {
106-
await mockModule('@codebuff/common/db', () => ({
107-
default: createDbMock(),
108-
}))
109-
})
110-
111-
describe('calculateOrganizationUsageAndBalance', () => {
112-
it('should calculate balance correctly with positive and negative balances', async () => {
113-
const organizationId = 'org-123'
114-
const quotaResetDate = new Date('2024-01-01')
115-
const now = new Date('2024-06-01')
97+
describe('calculateOrganizationUsageAndBalance', () => {
98+
it('should calculate balance correctly with positive and negative balances', async () => {
99+
const organizationId = 'org-123'
100+
const quotaResetDate = new Date('2024-01-01')
101+
const now = new Date('2024-06-01')
116102

117103
const result = await calculateOrganizationUsageAndBalance({
118104
organizationId,
@@ -132,11 +118,19 @@ describe('calculateOrganizationUsageAndBalance', () => {
132118
expect(result.usageThisCycle).toBe(800)
133119
})
134120

135-
it('should handle organization with no grants', async () => {
136-
// Mock empty grants
137-
await mockModule('@codebuff/common/db', () => ({
138-
default: createDbMock({ grants: [] }),
139-
}))
121+
it('should handle organization with no grants', async () => {
122+
// Mock empty grants
123+
mockModule('@codebuff/common/db', () => ({
124+
default: {
125+
select: () => ({
126+
from: () => ({
127+
where: () => ({
128+
orderBy: () => [],
129+
}),
130+
}),
131+
}),
132+
},
133+
}))
140134

141135
const organizationId = 'org-empty'
142136
const quotaResetDate = new Date('2024-01-01')
@@ -207,7 +201,7 @@ describe('calculateOrganizationUsageAndBalance', () => {
207201
it('should reject malformed URLs', () => {
208202
const result = validateAndNormalizeRepositoryUrl('not-a-url')
209203
expect(result.isValid).toBe(false)
210-
expect(result.error).toBe('Repository domain not allowed')
204+
expect(result.error).toBe('Invalid URL format')
211205
})
212206

213207
it('should accept allowed domains', () => {
@@ -261,19 +255,19 @@ describe('calculateOrganizationUsageAndBalance', () => {
261255
})
262256

263257
it('should handle duplicate operation IDs gracefully', async () => {
264-
// Mock database constraint error
265-
await mockModule('@codebuff/common/db', () => ({
266-
default: createDbMock({
267-
insert: () => ({
268-
values: () => {
269-
const error = new Error('Duplicate key')
270-
;(error as any).code = '23505'
271-
;(error as any).constraint = 'credit_ledger_pkey'
272-
throw error
273-
},
274-
}),
275-
}),
276-
}))
258+
// Mock database constraint error
259+
mockModule('@codebuff/common/db', () => ({
260+
default: {
261+
insert: () => ({
262+
values: () => {
263+
const error = new Error('Duplicate key')
264+
;(error as any).code = '23505'
265+
;(error as any).constraint = 'credit_ledger_pkey'
266+
throw error
267+
},
268+
}),
269+
},
270+
}))
277271

278272
const organizationId = 'org-123'
279273
const userId = 'user-123'

packages/code-map/__tests__/languages.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ describe('languages module', () => {
2222
languageTable.forEach((config) => {
2323
expect(config).toHaveProperty('extensions')
2424
expect(config).toHaveProperty('wasmFile')
25-
expect(config).toHaveProperty('queryPathOrContent')
25+
expect(config).toHaveProperty('queryText')
2626
expect(Array.isArray(config.extensions)).toBe(true)
2727
expect(config.extensions.length).toBeGreaterThan(0)
2828
expect(typeof config.wasmFile).toBe('string')
29-
expect(typeof config.queryPathOrContent).toBe('string')
29+
expect(typeof config.queryText).toBe('string')
3030
})
3131
})
3232

3333
it('should support TypeScript files', () => {
3434
const tsConfig = languageTable.find(c => c.extensions.includes('.ts'))
3535
expect(tsConfig).toBeDefined()
3636
expect(tsConfig?.wasmFile).toBe('tree-sitter-typescript.wasm')
37-
expect(tsConfig?.queryPathOrContent).toBeDefined()
37+
expect(tsConfig?.queryText).toBeDefined()
3838
})
3939

4040
it('should support TSX files', () => {
@@ -209,12 +209,12 @@ describe('languages module', () => {
209209
const config: LanguageConfig = {
210210
extensions: ['.test'],
211211
wasmFile: 'test.wasm',
212-
queryPathOrContent: 'test query',
212+
queryText: 'test query',
213213
}
214214

215215
expect(config.extensions).toEqual(['.test'])
216216
expect(config.wasmFile).toBe('test.wasm')
217-
expect(config.queryPathOrContent).toBe('test query')
217+
expect(config.queryText).toBe('test query')
218218
expect(config.parser).toBeUndefined()
219219
expect(config.query).toBeUndefined()
220220
expect(config.language).toBeUndefined()

0 commit comments

Comments
 (0)