Skip to content

Commit 701db65

Browse files
committed
Guard agent and SDK integrations when API key is missing
1 parent 0794d3f commit 701db65

File tree

3 files changed

+58
-20
lines changed

3 files changed

+58
-20
lines changed

.agents/__tests__/editor-best-of-n.integration.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ import { CodebuffClient } from '@codebuff/sdk'
55

66
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
77

8+
function getApiKeyOrSkip(): string | null {
9+
const apiKey = process.env[API_KEY_ENV_VAR]
10+
const isPlaceholder = !apiKey || ['test-codebuff', 'dummy-token'].includes(apiKey)
11+
12+
if (!process.env.CI && isPlaceholder) {
13+
console.warn('Skipping editor-best-of-n integration test: CODEBUFF_API_KEY missing or placeholder')
14+
return null
15+
}
16+
17+
if (!apiKey) {
18+
throw new Error('API key not found')
19+
}
20+
21+
return apiKey
22+
}
23+
824
/**
925
* Integration tests for the editor-best-of-n-max agent.
1026
* These tests verify that the best-of-n editor workflow works correctly:
@@ -17,10 +33,8 @@ describe('Editor Best-of-N Max Agent Integration', () => {
1733
it(
1834
'should generate and select the best implementation for a simple edit',
1935
async () => {
20-
const apiKey = process.env[API_KEY_ENV_VAR]
21-
if (!apiKey) {
22-
throw new Error('API key not found')
23-
}
36+
const apiKey = getApiKeyOrSkip()
37+
if (!apiKey) return
2438

2539
// Create mock project files with a simple TypeScript file to edit
2640
const projectFiles: Record<string, string> = {

.agents/__tests__/file-explorer.integration.test.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ import fileListerDefinition from '../file-explorer/file-lister'
77

88
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
99

10+
function getApiKeyOrSkip(): string | null {
11+
const apiKey = process.env[API_KEY_ENV_VAR]
12+
const isPlaceholder = !apiKey || ['test-codebuff', 'dummy-token'].includes(apiKey)
13+
14+
if (!process.env.CI && isPlaceholder) {
15+
console.warn('Skipping file-explorer integration test: CODEBUFF_API_KEY missing or placeholder')
16+
return null
17+
}
18+
19+
if (!apiKey) {
20+
throw new Error('API key not found')
21+
}
22+
23+
return apiKey
24+
}
25+
1026
/**
1127
* Integration tests for agents that use the read_subtree tool.
1228
* These tests verify that the SDK properly initializes the session state
@@ -22,10 +38,8 @@ describe('File Lister Agent Integration - read_subtree tool', () => {
2238
it(
2339
'should find relevant files using read_subtree tool',
2440
async () => {
25-
const apiKey = process.env[API_KEY_ENV_VAR]
26-
if (!apiKey) {
27-
throw new Error('API key not found')
28-
}
41+
const apiKey = getApiKeyOrSkip()
42+
if (!apiKey) return
2943

3044
// Create mock project files that the file-lister should be able to find
3145
const projectFiles: Record<string, string> = {
@@ -142,10 +156,8 @@ export interface User {
142156
it(
143157
'should use the file tree from session state',
144158
async () => {
145-
const apiKey = process.env[API_KEY_ENV_VAR]
146-
if (!apiKey) {
147-
throw new Error('API key not found')
148-
}
159+
const apiKey = getApiKeyOrSkip()
160+
if (!apiKey) return
149161

150162
// Create a different set of project files with a specific structure
151163
const projectFiles: Record<string, string> = {
@@ -196,10 +208,8 @@ export interface User {
196208
it(
197209
'should respect directories parameter',
198210
async () => {
199-
const apiKey = process.env[API_KEY_ENV_VAR]
200-
if (!apiKey) {
201-
throw new Error('API key not found')
202-
}
211+
const apiKey = getApiKeyOrSkip()
212+
if (!apiKey) return
203213

204214
// Create project with multiple top-level directories
205215
const projectFiles: Record<string, string> = {

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ import { describe, expect, it } from 'bun:test'
33

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

6+
function getApiKeyOrSkip(): string | null {
7+
const apiKey = process.env[API_KEY_ENV_VAR]
8+
const isPlaceholder = !apiKey || ['test-codebuff', 'dummy-token'].includes(apiKey)
9+
10+
if (!process.env.CI && isPlaceholder) {
11+
console.warn('Skipping SDK prompt caching integration: CODEBUFF_API_KEY missing or placeholder')
12+
return null
13+
}
14+
15+
if (!apiKey) {
16+
throw new Error('API key not found')
17+
}
18+
19+
return apiKey
20+
}
21+
622
describe('Prompt Caching', () => {
723
it(
824
'should be cheaper on second request',
@@ -12,10 +28,8 @@ describe('Prompt Caching', () => {
1228
'Ignore this text. This is just to make the prompt longer. '.repeat(500)
1329
const prompt = 'respond with "hi"'
1430

15-
const apiKey = process.env[API_KEY_ENV_VAR]
16-
if (!apiKey) {
17-
throw new Error('API key not found')
18-
}
31+
const apiKey = getApiKeyOrSkip()
32+
if (!apiKey) return
1933

2034
const client = new CodebuffClient({
2135
apiKey,

0 commit comments

Comments
 (0)