This document explains how to configure and use secrets when running integration tests in the GitHub Copilot agent environment.
The game-builder project requires API keys for LLM services (Anthropic Claude) to run integration tests. This guide covers how to properly set up and access these secrets.
GitHub Copilot can inject secrets into the agent environment. When properly configured, you'll see:
COPILOT_AGENT_INJECTED_SECRET_NAMES=ANTHROPIC_API_KEYThis environment variable indicates which secrets have been configured for injection.
Important: As of the current Copilot agent implementation, injected secrets listed in COPILOT_AGENT_INJECTED_SECRET_NAMES may not be directly accessible as environment variables in all contexts (bash, Node.js, etc.).
-
Add Secret to Repository
- Navigate to your repository settings
- Go to: Settings → Secrets and variables → Codespaces → Repository secrets
- Click "New repository secret"
- Name:
ANTHROPIC_API_KEY - Value: Your Anthropic API key
- Click "Add secret"
-
Verify Secret is Available to Copilot
- The secret should appear in
COPILOT_AGENT_INJECTED_SECRET_NAMESwhen the agent runs - Check with:
echo $COPILOT_AGENT_INJECTED_SECRET_NAMES
- The secret should appear in
For local development and testing, you can use a .env file:
-
Create .env File
cp .env.example .env
-
Add Your API Key Edit
.envand replace placeholder values:ANTHROPIC_API_KEY=sk-ant-your-actual-api-key-here # Model configurations LATEST_SONNET_MODEL=claude-sonnet-4-5-20250929 LATEST_HAIKU_MODEL=claude-haiku-4-5-20251001 HAIKU_3_5_MODEL=claude-3-5-haiku-20241022 CHAINCRAFT_SIM_SCHEMA_EXTRACTION_MODEL=${LATEST_SONNET_MODEL} CHAINCRAFT_SPEC_TRANSITIONS_MODEL=${LATEST_SONNET_MODEL} CHAINCRAFT_SIM_INSTRUCTIONS_MODEL=${LATEST_SONNET_MODEL}
-
Security: Never commit
.envfile- The
.envfile is already in.gitignore - Never commit actual API keys to the repository
- The
-
Install Dependencies
npm install
-
Build Project
npm run build
Tests the planner-only schema extraction (no JSON Schema conversion):
npm run test:sim:schema-extractExpected duration: 60-120 seconds (includes LLM API calls)
Tests that transitions work with planner schema format:
npm run test:sim:transitions-extractExpected duration: 90-180 seconds
Tests that instructions work with planner schema:
npm run test:sim:instructions-extractExpected duration: 120-240 seconds
Tests complete pipeline (schema → transitions → instructions):
node --experimental-vm-modules node_modules/jest/bin/jest.js \
src/ai/simulate/__tests__/spec-processing-graph.test.tsExpected duration: 180-360 seconds
All integration tests require:
- ✅ Valid
ANTHROPIC_API_KEYenvironment variable - ✅ Network access to
api.anthropic.com - ✅ Model configuration environment variables (from
.env)
Symptoms:
Error: Anthropic API key not found
at new ChatAnthropicMessages
Solutions:
-
Check if API key is accessible:
# In bash: echo $ANTHROPIC_API_KEY # In Node.js: node -e "console.log(process.env.ANTHROPIC_API_KEY)"
-
If using Copilot: Verify the secret is configured in repository settings
-
If using .env: Ensure the
.envfile exists and contains the API key -
Export directly (temporary workaround):
export ANTHROPIC_API_KEY="your-api-key-here" npm run test:sim:schema-extract
Symptoms:
Error: Model name must be provided either through options or environment variables
Solution:
Ensure your .env file has model configuration:
LATEST_SONNET_MODEL=claude-sonnet-4-5-20250929
CHAINCRAFT_SIM_SCHEMA_EXTRACTION_MODEL=${LATEST_SONNET_MODEL}Symptoms:
Error: Connection error
Cause: getaddrinfo ENOTFOUND api.anthropic.com
Solution:
Network access to api.anthropic.com may be blocked. Check:
- Firewall settings
- VPN configuration
- Corporate proxy settings
For Copilot environment: Ensure api.anthropic.com is on the allow list
- Never commit secrets to the repository
- Use .env for local development only
- Use GitHub Secrets for CI/CD and Copilot environments
- Rotate API keys regularly
- Use minimal permissions for API keys
- Run tests sequentially when using API limits
- Use timeouts appropriately (LLM calls can take 30-120s)
- Check costs - Each test run makes multiple API calls
- Cache test artifacts when possible
When reviewing PRs with test changes:
- Verify tests work without requiring secrets in code
- Check that
.env.exampleis updated if needed - Ensure documentation reflects any new requirements
ANTHROPIC_API_KEY- Your Anthropic API key
LATEST_SONNET_MODEL- Latest Sonnet model nameLATEST_HAIKU_MODEL- Latest Haiku model nameCHAINCRAFT_SIM_SCHEMA_EXTRACTION_MODEL- Model for schema extractionCHAINCRAFT_SPEC_TRANSITIONS_MODEL- Model for transitionsCHAINCRAFT_SIM_INSTRUCTIONS_MODEL- Model for instructions
LANGSMITH_TRACING- Enable/disable LangSmith tracing (default: false)LANGSMITH_API_KEY- LangSmith API key if tracing enabled
If you encounter issues with secret configuration or test execution:
- Check this documentation first
- Review the troubleshooting section
- Check
API_KEY_STATUS.mdfor detailed diagnostics - Open an issue with the
testinglabel