Skip to content

Commit 2125cb2

Browse files
committed
fix: skip .agents integration tests when CODEBUFF_API_KEY is not set
- Use describe.skip pattern to skip entire test suites when API key is unavailable - Remove inline API key checks that threw errors mid-test - Tests will now skip gracefully in CI when CODEBUFF_API_KEY secret is not configured
1 parent 7dcd1b9 commit 2125cb2

File tree

3 files changed

+22
-33
lines changed

3 files changed

+22
-33
lines changed

.agents/__tests__/context-pruner.integration.test.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { API_KEY_ENV_VAR } from '@codebuff/common/old-constants'
2-
import { describe, expect, it } from 'bun:test'
2+
import { describe, expect, it, beforeAll } from 'bun:test'
33

44
import {
55
CodebuffClient,
@@ -11,12 +11,17 @@ import {
1111
type JSONValue,
1212
} from '@codebuff/sdk'
1313

14+
const apiKey = process.env[API_KEY_ENV_VAR]
15+
const describeWithApiKey = apiKey ? describe : describe.skip
16+
1417
/**
1518
* Integration tests for the context-pruner agent.
1619
* These tests verify that context-pruner correctly prunes message history
1720
* while maintaining tool-call/tool-result pair integrity for Anthropic API compliance.
21+
*
22+
* These tests require CODEBUFF_API_KEY to be set and are skipped otherwise.
1823
*/
19-
describe('Context Pruner Agent Integration', () => {
24+
describeWithApiKey('Context Pruner Agent Integration', () => {
2025
// Helper to create a text message
2126
const createMessage = (
2227
role: 'user' | 'assistant',
@@ -58,10 +63,6 @@ describe('Context Pruner Agent Integration', () => {
5863
it(
5964
'should prune large message history and maintain tool-call/tool-result pairs',
6065
async () => {
61-
const apiKey = process.env[API_KEY_ENV_VAR]
62-
if (!apiKey) {
63-
throw new Error('API key not found')
64-
}
6566

6667
// Create a test agent that spawns context-pruner and then does one more step
6768
const testAgent: AgentDefinition = {
@@ -205,10 +206,6 @@ Do not do anything else. Just spawn context-pruner and then report the result.`,
205206
it(
206207
'should prune context with small token limit and preserve tool pairs',
207208
async () => {
208-
const apiKey = process.env[API_KEY_ENV_VAR]
209-
if (!apiKey) {
210-
throw new Error('API key not found')
211-
}
212209

213210
// Create a test agent that spawns context-pruner with very aggressive pruning
214211
const testAgent: AgentDefinition = {

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

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

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

8+
const apiKey = process.env[API_KEY_ENV_VAR]
9+
const describeWithApiKey = apiKey ? describe : describe.skip
10+
811
/**
912
* Integration tests for the editor-best-of-n-max agent.
1013
* These tests verify that the best-of-n editor workflow works correctly:
1114
* 1. Spawns multiple implementor agents in parallel
1215
* 2. Collects their implementation proposals
1316
* 3. Uses a selector agent to choose the best implementation
1417
* 4. Applies the chosen implementation
18+
*
19+
* These tests require CODEBUFF_API_KEY to be set and are skipped otherwise.
1520
*/
16-
describe('Editor Best-of-N Max Agent Integration', () => {
21+
describeWithApiKey('Editor Best-of-N Max Agent Integration', () => {
1722
it.skip(
1823
'should generate and select the best implementation for a simple edit',
1924
async () => {
20-
const apiKey = process.env[API_KEY_ENV_VAR]
21-
if (!apiKey) {
22-
throw new Error('API key not found')
23-
}
2425

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

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

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

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

10+
const apiKey = process.env[API_KEY_ENV_VAR]
11+
const describeWithApiKey = apiKey ? describe : describe.skip
12+
1013
/**
1114
* Integration tests for agents that use the read_subtree tool.
1215
* These tests verify that the SDK properly initializes the session state
@@ -17,15 +20,13 @@ import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
1720
* - file-lister directly uses the read_subtree tool
1821
* - file-picker spawns file-lister as a subagent, adding complexity
1922
* - Testing file-lister directly verifies the core functionality
23+
*
24+
* These tests require CODEBUFF_API_KEY to be set and are skipped otherwise.
2025
*/
21-
describe('File Lister Agent Integration - read_subtree tool', () => {
26+
describeWithApiKey('File Lister Agent Integration - read_subtree tool', () => {
2227
it(
2328
'should find relevant files using read_subtree tool',
2429
async () => {
25-
const apiKey = process.env[API_KEY_ENV_VAR]
26-
if (!apiKey) {
27-
throw new Error('API key not found')
28-
}
2930

3031
// Create mock project files that the file-lister should be able to find
3132
const projectFiles: Record<string, string> = {
@@ -142,10 +143,6 @@ export interface User {
142143
it(
143144
'should use the file tree from session state',
144145
async () => {
145-
const apiKey = process.env[API_KEY_ENV_VAR]
146-
if (!apiKey) {
147-
throw new Error('API key not found')
148-
}
149146

150147
// Create a different set of project files with a specific structure
151148
const projectFiles: Record<string, string> = {
@@ -196,10 +193,6 @@ export interface User {
196193
it(
197194
'should respect directories parameter',
198195
async () => {
199-
const apiKey = process.env[API_KEY_ENV_VAR]
200-
if (!apiKey) {
201-
throw new Error('API key not found')
202-
}
203196

204197
// Create project with multiple top-level directories
205198
const projectFiles: Record<string, string> = {
@@ -252,19 +245,17 @@ export interface User {
252245
* Integration tests for the file-picker agent that spawns subagents.
253246
* The file-picker spawns file-lister as a subagent to find files.
254247
* This tests the spawn_agents tool functionality through the SDK.
248+
*
249+
* These tests require CODEBUFF_API_KEY to be set and are skipped otherwise.
255250
*/
256-
describe('File Picker Agent Integration - spawn_agents tool', () => {
251+
describeWithApiKey('File Picker Agent Integration - spawn_agents tool', () => {
257252
// Note: This test requires the local agent definitions to be used for both
258253
// file-picker AND its spawned file-lister subagent. Currently, the spawned
259254
// agent may resolve to the server version which has the old parsing bug.
260255
// Skip until we have a way to ensure spawned agents use local definitions.
261256
it.skip(
262257
'should spawn file-lister subagent and find relevant files',
263258
async () => {
264-
const apiKey = process.env[API_KEY_ENV_VAR]
265-
if (!apiKey) {
266-
throw new Error('API key not found')
267-
}
268259

269260
// Create mock project files
270261
const projectFiles: Record<string, string> = {

0 commit comments

Comments
 (0)