@@ -10,7 +10,7 @@ import {
1010 type AgentDefinition ,
1111 type Message ,
1212} from '@codebuff/sdk'
13- import { describe , expect , it } from 'bun:test'
13+ import { beforeAll , describe , expect , it } from 'bun:test'
1414
1515import base2Free from '../base2/base2-free'
1616import contextPruner from '../context-pruner'
@@ -64,6 +64,33 @@ function detectSummaryImitation(text: string): string[] {
6464 return matches
6565}
6666
67+ const loadEnvFile = async ( filePath : string ) => {
68+ try {
69+ const content = await fs . promises . readFile ( filePath , 'utf-8' )
70+ for ( const rawLine of content . split ( '\n' ) ) {
71+ const line = rawLine . trim ( )
72+ if ( ! line || line . startsWith ( '#' ) ) continue
73+ const normalized = line . startsWith ( 'export ' )
74+ ? line . slice ( 'export ' . length )
75+ : line
76+ const equalsIndex = normalized . indexOf ( '=' )
77+ if ( equalsIndex <= 0 ) continue
78+ const key = normalized . slice ( 0 , equalsIndex ) . trim ( )
79+ if ( ! key || process . env [ key ] ) continue
80+ let value = normalized . slice ( equalsIndex + 1 ) . trim ( )
81+ if (
82+ ( value . startsWith ( '"' ) && value . endsWith ( '"' ) ) ||
83+ ( value . startsWith ( "'" ) && value . endsWith ( "'" ) )
84+ ) {
85+ value = value . slice ( 1 , - 1 )
86+ }
87+ process . env [ key ] = value
88+ }
89+ } catch {
90+ // ignore missing env files
91+ }
92+ }
93+
6794/**
6895 * Creates a pre-summarized conversation that mimics what the context pruner produces.
6996 * NOTE: The disclaimer text here must be kept in sync with the one in
@@ -213,6 +240,11 @@ const PROJECT_FILES: Record<string, string> = {
213240describe ( 'Base2-Free Summary Format Compliance' , ( ) => {
214241 const NUM_PARALLEL_RUNS = 3
215242
243+ beforeAll ( async ( ) => {
244+ await loadEnvFile ( path . resolve ( process . cwd ( ) , '.env.local' ) )
245+ await loadEnvFile ( path . resolve ( process . cwd ( ) , '../.env.local' ) )
246+ } )
247+
216248 const getApiKeyOrSkip = ( ) : string | null => {
217249 const apiKey = process . env [ API_KEY_ENV_VAR ]
218250 if ( ! apiKey ) {
0 commit comments