Skip to content

Commit 961c300

Browse files
committed
Consolidate sdk scripts with a "verify" script for all non-traditional tests
1 parent 8e662a3 commit 961c300

File tree

4 files changed

+208
-98
lines changed

4 files changed

+208
-98
lines changed

sdk/package.json

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,20 @@
2323
],
2424
"scripts": {
2525
"build": "bun run scripts/build.ts",
26-
"build:types": "bunx dts-bundle-generator -o dist/index.d.ts --no-check --export-referenced-types=false src/index.ts",
27-
"build:verify": "bun run build && bun run smoke-test:dist && bun run test:cjs && bun run test:esm && bun run test:ripgrep && bun run test:tree-sitter-queries",
28-
"test:typecheck-strict": "tsc --noEmit --strict dist/index.d.ts",
29-
"smoke-test:dist": "bun run smoke-test-dist.ts",
30-
"test:cjs": "cd test/cjs-compatibility && npm install --silent && npm run test:all",
31-
"test:esm": "cd test/esm-compatibility && npm install --silent && npm run test:all",
32-
"test:ripgrep": "cd test/ripgrep-bundling && npm install --silent && npm run test:all",
33-
"test:tree-sitter-queries": "cd test/tree-sitter-queries && npm install --silent && npm run test:all",
34-
"test:types": "bun run scripts/test-types.ts",
26+
"clean": "rm -rf dist",
27+
"typecheck": "tsc --noEmit -p .",
28+
"test": "bun test",
3529
"test:e2e": "bun test e2e/streaming/ e2e/workflows/ e2e/custom-agents/ e2e/features/",
3630
"test:integration": "bun test e2e/integration/",
37-
"test:unit:e2e": "bun test e2e/utils/__tests__/",
38-
"clean": "rm -rf dist",
31+
"verify": "bun run scripts/verify.ts",
32+
"verify:skip-build": "bun run scripts/verify.ts --skip-build",
33+
"smoke-test:dist": "bun run smoke-test-dist.ts",
3934
"prepare-dist": "bun run scripts/publish.ts --dry-run",
4035
"publish-sdk": "bun run scripts/publish.ts --public",
41-
"publish-dry-run": "bun run build:verify && bun run scripts/publish.ts --dry-run",
36+
"publish-dry-run": "bun run verify && bun run scripts/publish.ts --dry-run",
4237
"release": "bun run scripts/release.js",
4338
"fetch-ripgrep": "bun scripts/fetch-ripgrep.ts",
4439
"prepack": "bun run build",
45-
"typecheck": "tsc --noEmit -p .",
46-
"test": "bun test",
4740
"dev": "bun run build"
4841
},
4942
"engines": {

sdk/scripts/test-types.ts

Lines changed: 0 additions & 83 deletions
This file was deleted.

sdk/scripts/verify.ts

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#!/usr/bin/env bun
2+
/**
3+
* Comprehensive SDK verification script.
4+
* Runs all build, typecheck, and compatibility tests in one command.
5+
*
6+
* Usage:
7+
* bun run verify # Run full verification
8+
* bun run verify --skip-build # Skip build step (use existing dist)
9+
*/
10+
11+
import { execSync, type ExecSyncOptions } from 'child_process'
12+
import { existsSync, rmSync } from 'fs'
13+
import { join } from 'path'
14+
15+
const sdkRoot = join(import.meta.dirname, '..')
16+
const testDir = join(sdkRoot, 'test')
17+
const distPath = join(sdkRoot, 'dist')
18+
19+
// Test subprojects that use dist copy setup
20+
const DIST_COPY_SUBPROJECTS = [
21+
'cjs-compatibility',
22+
'esm-compatibility',
23+
'ripgrep-bundling',
24+
]
25+
26+
// Test subprojects that use file reference (different setup)
27+
const FILE_REF_SUBPROJECTS = ['tree-sitter-queries']
28+
29+
interface VerifyOptions {
30+
skipBuild?: boolean
31+
}
32+
33+
function log(message: string) {
34+
console.log(`\n${'='.repeat(60)}`)
35+
console.log(`📦 ${message}`)
36+
console.log('='.repeat(60))
37+
}
38+
39+
function step(message: string) {
40+
console.log(`\n → ${message}`)
41+
}
42+
43+
function success(message: string) {
44+
console.log(` ✅ ${message}`)
45+
}
46+
47+
function run(command: string, options: ExecSyncOptions = {}) {
48+
execSync(command, { cwd: sdkRoot, stdio: 'inherit', ...options })
49+
}
50+
51+
function removeOldSdk(projectPath: string) {
52+
const sdkPath = join(projectPath, 'node_modules', '@codebuff', 'sdk')
53+
if (existsSync(sdkPath)) {
54+
step(`Removing old SDK at ${sdkPath}`)
55+
rmSync(sdkPath, { recursive: true, force: true })
56+
}
57+
}
58+
59+
function cleanAndBuild() {
60+
log('Step 1: Clean and Build')
61+
62+
step('Cleaning dist directory...')
63+
rmSync(distPath, { recursive: true, force: true })
64+
65+
step('Building SDK...')
66+
run('bun run build')
67+
68+
success('Build complete')
69+
}
70+
71+
function typecheck() {
72+
log('Step 2: TypeScript Check')
73+
74+
step('Running typecheck on source...')
75+
run('tsc --noEmit -p .')
76+
77+
success('TypeScript check passed')
78+
}
79+
80+
function smokeTest() {
81+
log('Step 3: Smoke Test')
82+
83+
step('Running dist smoke tests...')
84+
run('bun run smoke-test-dist.ts')
85+
86+
success('Smoke test passed')
87+
}
88+
89+
function runDistCopySubproject(projectName: string) {
90+
const projectPath = join(testDir, projectName)
91+
92+
if (!existsSync(projectPath)) {
93+
throw new Error(`Project not found: ${projectPath}`)
94+
}
95+
96+
step(`Testing ${projectName}...`)
97+
98+
// Remove old SDK installation
99+
removeOldSdk(projectPath)
100+
101+
// Install dependencies
102+
execSync('npm install --silent', { cwd: projectPath, stdio: 'inherit' })
103+
104+
// Run setup (copies dist to node_modules)
105+
execSync('npm run setup', { cwd: projectPath, stdio: 'inherit' })
106+
107+
// Run all tests (imports + types)
108+
execSync('npm run test:all', { cwd: projectPath, stdio: 'inherit' })
109+
110+
success(`${projectName} passed`)
111+
}
112+
113+
function runFileRefSubproject(projectName: string) {
114+
const projectPath = join(testDir, projectName)
115+
116+
if (!existsSync(projectPath)) {
117+
throw new Error(`Project not found: ${projectPath}`)
118+
}
119+
120+
step(`Testing ${projectName}...`)
121+
122+
// Install dependencies (uses file: reference)
123+
execSync('npm install --silent', { cwd: projectPath, stdio: 'inherit' })
124+
125+
// Run all tests
126+
execSync('npm run test:all', { cwd: projectPath, stdio: 'inherit' })
127+
128+
success(`${projectName} passed`)
129+
}
130+
131+
function compatibilityTests() {
132+
log('Step 4: Compatibility Tests')
133+
134+
// Run dist-copy subprojects (CJS, ESM, ripgrep)
135+
for (const project of DIST_COPY_SUBPROJECTS) {
136+
runDistCopySubproject(project)
137+
}
138+
139+
// Run file-reference subprojects (tree-sitter-queries)
140+
for (const project of FILE_REF_SUBPROJECTS) {
141+
runFileRefSubproject(project)
142+
}
143+
144+
success('All compatibility tests passed')
145+
}
146+
147+
function parseArgs(): VerifyOptions {
148+
const args = process.argv.slice(2)
149+
return {
150+
skipBuild: args.includes('--skip-build'),
151+
}
152+
}
153+
154+
async function main() {
155+
const options = parseArgs()
156+
157+
console.log('🔍 SDK Verification Script')
158+
console.log('==========================')
159+
console.log('')
160+
console.log('This script will:')
161+
console.log(' 1. Clean and build the SDK')
162+
console.log(' 2. Run TypeScript checks')
163+
console.log(' 3. Run smoke tests on dist')
164+
console.log(' 4. Run all compatibility tests (CJS, ESM, ripgrep, tree-sitter)')
165+
166+
if (options.skipBuild) {
167+
console.log('\n⚠️ Skipping build step (--skip-build flag)')
168+
if (!existsSync(distPath)) {
169+
throw new Error('dist directory not found. Run without --skip-build first.')
170+
}
171+
}
172+
173+
const startTime = Date.now()
174+
175+
// Step 1: Clean and Build
176+
if (!options.skipBuild) {
177+
cleanAndBuild()
178+
}
179+
180+
// Step 2: TypeScript Check
181+
typecheck()
182+
183+
// Step 3: Smoke Test
184+
smokeTest()
185+
186+
// Step 4: Compatibility Tests
187+
compatibilityTests()
188+
189+
// Summary
190+
const duration = ((Date.now() - startTime) / 1000).toFixed(1)
191+
console.log('')
192+
console.log('='.repeat(60))
193+
console.log(`🎉 All verification steps passed! (${duration}s)`)
194+
console.log('='.repeat(60))
195+
}
196+
197+
main().catch((error) => {
198+
console.error('\n❌ Verification failed:', error.message)
199+
process.exit(1)
200+
})

sdk/test/tree-sitter-queries/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)