Skip to content

Commit 82dc367

Browse files
jesseturner21claude
andcommitted
fix(tests): hoist bootstrap mocks in idempotency test to survive clearAllMocks
checkBootstrapNeeded and bootstrapEnvironment were created as inline vi.fn() inside the vi.mock factory. vi.clearAllMocks() in beforeEach wipes their mockResolvedValue, causing handleImport to fail in CI where test execution order differs from local runs. Hoist the mocks and configure them in setupCommonMocks like all other mock functions in the file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9fdedb1 commit 82dc367

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/cli/commands/import/__tests__/idempotency.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const {
2121
mockValidateAwsCredentials,
2222
mockBuildCdkProject,
2323
mockSynthesizeCdk,
24+
mockCheckBootstrapNeeded,
25+
mockBootstrapEnvironment,
2426
mockSetupPythonProject,
2527
mockExecutePhase1,
2628
mockGetDeployedTemplate,
@@ -56,6 +58,8 @@ const {
5658
mockExecutePhase1: vi.fn(),
5759
mockGetDeployedTemplate: vi.fn(),
5860
mockExecutePhase2: vi.fn(),
61+
mockCheckBootstrapNeeded: vi.fn(),
62+
mockBootstrapEnvironment: vi.fn(),
5963
mockPublishCdkAssets: vi.fn(),
6064
mockParseStarterToolkitYaml: vi.fn(),
6165
mockExistsSync: vi.fn(),
@@ -82,6 +86,8 @@ vi.mock('../../../aws/account', () => ({
8286
vi.mock('../../../operations/deploy', () => ({
8387
buildCdkProject: (...args: unknown[]) => mockBuildCdkProject(...args),
8488
synthesizeCdk: (...args: unknown[]) => mockSynthesizeCdk(...args),
89+
checkBootstrapNeeded: (...args: unknown[]) => mockCheckBootstrapNeeded(...args),
90+
bootstrapEnvironment: (...args: unknown[]) => mockBootstrapEnvironment(...args),
8591
}));
8692

8793
vi.mock('../../../cdk/local-cdk-project', () => ({
@@ -92,6 +98,17 @@ vi.mock('../../../cdk/toolkit-lib', () => ({
9298
silentIoHost: {},
9399
}));
94100

101+
vi.mock('../../../logging', () => ({
102+
ExecLogger: class MockExecLogger {
103+
startStep = vi.fn();
104+
endStep = vi.fn();
105+
log = vi.fn();
106+
finalize = vi.fn();
107+
getRelativeLogPath = vi.fn().mockReturnValue('agentcore/.cli/logs/import/import-mock.log');
108+
logFilePath = 'agentcore/.cli/logs/import/import-mock.log';
109+
},
110+
}));
111+
95112
vi.mock('../../../operations/python/setup', () => ({
96113
setupPythonProject: (...args: unknown[]) => mockSetupPythonProject(...args),
97114
}));
@@ -223,6 +240,8 @@ function setupCommonMocks() {
223240
mockReaddirSync.mockReturnValue([]);
224241
mockReadFileSync.mockReturnValue(JSON.stringify(synthTemplate));
225242

243+
mockCheckBootstrapNeeded.mockResolvedValue({ needsBootstrap: false });
244+
mockBootstrapEnvironment.mockResolvedValue(undefined);
226245
mockBuildCdkProject.mockResolvedValue(undefined);
227246
mockSynthesizeCdk.mockResolvedValue({
228247
toolkitWrapper: {

0 commit comments

Comments
 (0)