Skip to content

Commit d8eae1c

Browse files
committed
fix(e2e): add shared debug logging for all import test failures
Add dumpImportDebugInfo to e2e-helper that prints the import log file and CloudFormation stack events when an import fails. Used by both import-resources and import-gateway tests to diagnose CI failures. Confidence: high Scope-risk: narrow
1 parent 8a0edf7 commit d8eae1c

3 files changed

Lines changed: 50 additions & 44 deletions

File tree

e2e-tests/e2e-helper.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '@aws-sdk/client-bedrock-agentcore-control';
1515
import { execSync } from 'node:child_process';
1616
import { randomUUID } from 'node:crypto';
17-
import { mkdir, rm, writeFile } from 'node:fs/promises';
17+
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
1818
import { tmpdir } from 'node:os';
1919
import { join } from 'node:path';
2020
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
@@ -377,3 +377,44 @@ export async function teardownE2EProject(projectPath: string, agentName: string,
377377
await deleteCredentialProvider(client, `${agentName}${modelProvider}`);
378378
}
379379
}
380+
381+
export async function dumpImportDebugInfo(
382+
label: string,
383+
result: RunResult,
384+
projectPath: string,
385+
stackName: string,
386+
region: string
387+
): Promise<void> {
388+
console.log(`Import ${label} stdout:`, result.stdout);
389+
console.log(`Import ${label} stderr:`, result.stderr);
390+
391+
const logMatch = /Log: (.+)/.exec(result.stderr);
392+
if (logMatch) {
393+
try {
394+
const logContents = await readFile(join(projectPath, logMatch[1]!), 'utf-8');
395+
console.log(`Import ${label} log:\n`, logContents);
396+
} catch {
397+
/* log file may not exist */
398+
}
399+
}
400+
401+
const cfnEvents = await spawnAndCollect(
402+
'aws',
403+
[
404+
'cloudformation',
405+
'describe-stack-events',
406+
'--stack-name',
407+
stackName,
408+
'--query',
409+
'StackEvents[?ResourceStatus==`IMPORT_FAILED` || ResourceStatus==`IMPORT_ROLLBACK_IN_PROGRESS`]',
410+
'--output',
411+
'json',
412+
'--region',
413+
region,
414+
],
415+
projectPath
416+
);
417+
if (cfnEvents.exitCode === 0 && cfnEvents.stdout.trim() !== '[]') {
418+
console.log(`CloudFormation failed events for ${label}:`, cfnEvents.stdout);
419+
}
420+
}

e2e-tests/import-gateway.test.ts

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
spawnAndCollect,
88
stripAnsi,
99
} from '../src/test-utils/index.js';
10-
import { installCdkTarball, runAgentCoreCLI, writeAwsTargets } from './e2e-helper.js';
10+
import { dumpImportDebugInfo, installCdkTarball, runAgentCoreCLI, writeAwsTargets } from './e2e-helper.js';
1111
import { execSync } from 'node:child_process';
1212
import { randomUUID } from 'node:crypto';
1313
import { mkdir, readFile, rm } from 'node:fs/promises';
@@ -89,6 +89,7 @@ describe.sequential('e2e: import gateway', () => {
8989
}, 600_000);
9090

9191
const run = (args: string[]): Promise<RunResult> => runAgentCoreCLI(args, projectPath);
92+
const stackName = `AgentCore-${agentName}-default`;
9293

9394
// ── Import test ───────────────────────────────────────────────────
9495

@@ -98,41 +99,7 @@ describe.sequential('e2e: import gateway', () => {
9899
const result = await run(['import', 'gateway', '--arn', gatewayArn]);
99100

100101
if (result.exitCode !== 0) {
101-
console.log('Import gateway stdout:', result.stdout);
102-
console.log('Import gateway stderr:', result.stderr);
103-
104-
// Print the import log file for debugging CI failures
105-
const logMatch = /Log: (.+)/.exec(result.stderr);
106-
if (logMatch) {
107-
const logPath = join(projectPath, logMatch[1]!);
108-
try {
109-
const logContents = await readFile(logPath, 'utf-8');
110-
console.log('Import gateway log:\n', logContents);
111-
} catch {
112-
console.log('Could not read log file:', logPath);
113-
}
114-
}
115-
116-
// Print CloudFormation stack events for the failed import
117-
const cfnEvents = await spawnAndCollect(
118-
'aws',
119-
[
120-
'cloudformation',
121-
'describe-stack-events',
122-
'--stack-name',
123-
`AgentCore-${agentName}-default`,
124-
'--query',
125-
'StackEvents[?ResourceStatus==`IMPORT_FAILED` || ResourceStatus==`IMPORT_ROLLBACK_IN_PROGRESS`]',
126-
'--output',
127-
'json',
128-
'--region',
129-
region,
130-
],
131-
projectPath
132-
);
133-
if (cfnEvents.exitCode === 0) {
134-
console.log('CloudFormation failed events:', cfnEvents.stdout);
135-
}
102+
await dumpImportDebugInfo('gateway', result, projectPath, stackName, region);
136103
}
137104

138105
expect(result.exitCode, `Import gateway failed: ${result.stderr}`).toBe(0);

e2e-tests/import-resources.test.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
spawnAndCollect,
1010
stripAnsi,
1111
} from '../src/test-utils/index.js';
12-
import { installCdkTarball, runAgentCoreCLI, writeAwsTargets } from './e2e-helper.js';
12+
import { dumpImportDebugInfo, installCdkTarball, runAgentCoreCLI, writeAwsTargets } from './e2e-helper.js';
1313
import { execSync } from 'node:child_process';
1414
import { randomUUID } from 'node:crypto';
1515
import { mkdir, readFile, rm } from 'node:fs/promises';
@@ -112,6 +112,7 @@ describe.sequential('e2e: import runtime/memory/evaluator', () => {
112112
}, 600_000);
113113

114114
const run = (args: string[]): Promise<RunResult> => runAgentCoreCLI(args, projectPath);
115+
const stackName = `AgentCore-${agentName}-default`;
115116

116117
// ── Import tests ──────────────────────────────────────────────────
117118

@@ -121,8 +122,7 @@ describe.sequential('e2e: import runtime/memory/evaluator', () => {
121122
const result = await run(['import', 'runtime', '--arn', runtimeArn, '--code', appDir, '--name', agentName, '-y']);
122123

123124
if (result.exitCode !== 0) {
124-
console.log('Import runtime stdout:', result.stdout);
125-
console.log('Import runtime stderr:', result.stderr);
125+
await dumpImportDebugInfo('runtime', result, projectPath, stackName, region);
126126
}
127127

128128
expect(result.exitCode, `Import runtime failed: ${result.stderr}`).toBe(0);
@@ -137,8 +137,7 @@ describe.sequential('e2e: import runtime/memory/evaluator', () => {
137137
const result = await run(['import', 'memory', '--arn', memoryArn, '-y']);
138138

139139
if (result.exitCode !== 0) {
140-
console.log('Import memory stdout:', result.stdout);
141-
console.log('Import memory stderr:', result.stderr);
140+
await dumpImportDebugInfo('memory', result, projectPath, stackName, region);
142141
}
143142

144143
expect(result.exitCode, `Import memory failed: ${result.stderr}`).toBe(0);
@@ -153,8 +152,7 @@ describe.sequential('e2e: import runtime/memory/evaluator', () => {
153152
const result = await run(['import', 'evaluator', '--arn', evaluatorArn]);
154153

155154
if (result.exitCode !== 0) {
156-
console.log('Import evaluator stdout:', result.stdout);
157-
console.log('Import evaluator stderr:', result.stderr);
155+
await dumpImportDebugInfo('evaluator', result, projectPath, stackName, region);
158156
}
159157

160158
expect(result.exitCode, `Import evaluator failed: ${result.stderr}`).toBe(0);

0 commit comments

Comments
 (0)