Guides
Testing & Debugging
Strategies for testing and debugging AMP integrations.
Test Mode
Always use test mode API keys during development:
# Test keys start with amp_sk_test_
AMP_API_KEY=amp_sk_test_1234567890abcdef- Free unlimited requests
- Isolated data from production
- Profiles reset monthly
Unit Testing
Mocking AMP
// Mock AMP in tests
jest.mock('@amp-protocol/client');
const mockGetContext = jest.fn().mockResolvedValue({
requestId: 'test_req',
suggestedFraming: 'achievement',
communicationStyle: 'brief_directive',
complexity: 'break_into_steps',
confidence: 0.8
});
AMP.prototype.getContext = mockGetContext;
test('adapts response based on AMP context', async () => {
const response = await handleUserQuery('user_123', 'test task');
expect(mockGetContext).toHaveBeenCalledWith({
userId: 'user_123',
task: 'test task'
});
expect(response).toContain('step-by-step');
});Testing Different Contexts
test.each([
['achievement', 'Complete this feature'],
['learning', 'Learn how to implement'],
['micro_task', 'First, create the file'],
['challenge', 'Can you solve this'],
])('handles %s framing', async (framing, expectedPhrase) => {
mockGetContext.mockResolvedValue({
suggestedFraming: framing,
// ...
});
const response = await generateResponse('build login');
expect(response).toContain(expectedPhrase);
});Integration Testing
// Test against real AMP (in test mode)
describe('AMP Integration', () => {
let amp: AMP;
beforeAll(() => {
amp = new AMP({
apiKey: process.env.AMP_TEST_API_KEY
});
});
it('returns valid context', async () => {
const context = await amp.getContext({
userId: 'test_user_' + Date.now(),
task: 'test task'
});
expect(context.requestId).toBeDefined();
expect(context.confidence).toBeGreaterThanOrEqual(0);
expect(context.confidence).toBeLessThanOrEqual(1);
});
it('accepts outcome reports', async () => {
const context = await amp.getContext({
userId: 'test_user_' + Date.now(),
task: 'test task'
});
await expect(amp.reportOutcome({
requestId: context.requestId,
started: true,
completed: true
})).resolves.not.toThrow();
});
});Debugging
Enable Debug Logging
const amp = new AMP({
apiKey: process.env.AMP_API_KEY,
debug: true // Logs all requests and responses
});
// Or set environment variable
DEBUG=amp:* node server.jsInspect Context Rationale
const context = await amp.getContext({ userId, task });
console.log('AMP Recommendation:', {
framing: context.suggestedFraming,
confidence: context.confidence,
rationale: context.rationale, // Why this recommendation?
profilePhase: context.metadata.profilePhase
});Track Profile Evolution
// Monitor how a profile changes over time
async function trackProfile(userId: string) {
for (let i = 0; i < 10; i++) {
const context = await amp.getContext({
userId,
task: `test task ${i}`
});
console.log(`Iteration ${i}:`, {
framing: context.suggestedFraming,
confidence: context.confidence,
phase: context.metadata.profilePhase
});
// Report positive outcome
await amp.reportOutcome({
requestId: context.requestId,
started: true,
completed: true
});
await sleep(1000);
}
}Common Issues
Low Confidence Persists
Problem: Confidence stays low after many interactions
Cause: Inconsistent outcomes or vague task descriptions
Fix: Provide better task descriptions and accurate outcome reporting
Same Recommendation Every Time
Problem: AMP always returns the same context
Cause: Not reporting outcomes or using cached responses
Fix: Ensure outcome reporting is working, reduce cache TTL
Unexpected Recommendations
Problem: Recommendations don't match expectations
Cause: User behaviour differs from assumptions
Fix: Check rationale field, review actual user outcomes
💡 Debug Tip: Use the metadata field to track which version of your code generated each request. Makes debugging production issues easier.