Skip to content

Commit c306c08

Browse files
committed
fix: add CODEBUFF_API_KEY to CI env vars for SDK tests
- Add additionalCiEnvVars array for env vars needed by SDK/CLI but excluded from web - CODEBUFF_API_KEY is injected into CI for SDK integration tests - Maintains type-level protection: web still cannot access env.CODEBUFF_API_KEY
1 parent 849c480 commit c306c08

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

packages/internal/src/env-schema.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { clientEnvSchema, clientProcessEnv } from '@codebuff/common/env-schema'
22
import z from 'zod/v4'
33

44
export const serverEnvSchema = clientEnvSchema.extend({
5+
// Codebuff API key - used by CLI/SDK for authentication
6+
// NOTE: Web should NOT use this directly - users must provide their own key
7+
// See web/.eslintrc.cjs for enforcement
8+
CODEBUFF_API_KEY: z.string().optional(),
59
// LLM API keys
610
OPEN_ROUTER_API_KEY: z.string().min(1),
711
OPENAI_API_KEY: z.string().min(1),
@@ -36,6 +40,8 @@ export type ServerEnv = z.infer<typeof serverEnvSchema>
3640
export const serverProcessEnv: ServerInput = {
3741
...clientProcessEnv,
3842

43+
// Codebuff API key
44+
CODEBUFF_API_KEY: process.env.CODEBUFF_API_KEY,
3945
// LLM API keys
4046
OPEN_ROUTER_API_KEY: process.env.OPEN_ROUTER_API_KEY,
4147
OPENAI_API_KEY: process.env.OPENAI_API_KEY,

scripts/generate-ci-env.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ function parseArgs() {
4747
return { prefix, scope }
4848
}
4949

50+
// Additional env vars needed for CI that aren't in the web env schema
51+
// CODEBUFF_API_KEY is used by SDK/CLI but intentionally excluded from web's typed env
52+
const additionalCiEnvVars = ['CODEBUFF_API_KEY']
53+
5054
function generateGitHubEnv() {
5155
const { prefix, scope } = parseArgs()
5256
const varsByScope = {
53-
all: serverEnvVars,
57+
all: [...serverEnvVars, ...additionalCiEnvVars],
5458
client: clientEnvVars,
5559
}
5660

sdk/src/__tests__/run.integration.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@ import { describe, expect, it } from 'bun:test'
33

44
import { CodebuffClient } from '../client'
55

6+
const skipIfNoApiKey = () => !process.env[API_KEY_ENV_VAR]
7+
68
describe('Prompt Caching', () => {
79
it(
810
'should be cheaper on second request',
911
async () => {
12+
if (skipIfNoApiKey()) {
13+
console.log('Skipping test: CODEBUFF_API_KEY not set')
14+
return
15+
}
16+
1017
const filler =
1118
`Run UUID: ${crypto.randomUUID()} ` +
1219
'Ignore this text. This is just to make the prompt longer. '.repeat(500)

0 commit comments

Comments
 (0)