Skip to content

fix: resolve #761#903

Closed
aidandaly24 wants to merge 3 commits intomainfrom
fix/761
Closed

fix: resolve #761#903
aidandaly24 wants to merge 3 commits intomainfrom
fix/761

Conversation

@aidandaly24
Copy link
Copy Markdown
Contributor

@aidandaly24 aidandaly24 commented Apr 21, 2026

This is end to end AI generated please do not merge this is for testing

Summary\nFixes https://github.com/aws/agentcore-cli/issues/761\n\nRound 1: 19 findings

Round 2: 7 findings
Round 3: 0 findings, all approved

Developer added 3 commits April 21, 2026 17:48
This fix addresses issue #761 where deploying with valid AWS credentials
for a different account than the target would fail late in the process
at the 'publish assets' step with a generic error.

Changes:
- Add AccountMismatchError class with clear error messages including
  both account IDs and fix instructions
- Add validateAccountMatch() function that compares credentials account
  with target account using STS GetCallerIdentity
- Add isAccountMismatchError() helper function in errors.ts
- Update validateProject() in preflight.ts to validate account match
  early (before build/synth steps)
- Update handleDeploy() in actions.ts to use validateAccountMatch for
  teardown deploys
- Update useCdkPreflight hook to handle AccountMismatchError properly
- Add comprehensive unit tests for account mismatch validation

The fix ensures users get immediate feedback when their credentials
don't match the target account, rather than waiting for deployment
to fail at the 'publish assets' step.
HIGH: Document that only first target is validated (deploys target one account at a time)
- Added comment explaining multi-target deployments require separate deploy commands

MEDIUM fixes:
- Extract createNoCredentialsError() helper to eliminate duplicate error handling
- Improve error message to distinguish 'not configured' vs 'detection failed'
- Add shortMessage property to AccountMismatchError for TUI consistency
- Use err.shortMessage in TUI hook instead of hardcoded string
- Add target.account validation (12-digit AWS account ID) in deploy actions
- Refactor import-utils.ts to use validateAccountMatch() instead of manual logic
- Improve isAccountMismatchError() to check specific properties for type safety

LOW fixes:
- Export AccountMismatchError and validateAccountMatch from aws/index.ts
- Remove non-null assertion in preflight.ts, use explicit if (target) check
- Update test comments to clarify detectAccount null return behavior
- Add test for AccountMismatchError.shortMessage property
- Update test assertions to match new error message wording
MEDIUM fixes:
- useCdkPreflight.ts:294: Handle AccountMismatchError in validateProject catch block
  to use shortMessage in interactive mode, matching the pattern at line 328
- errors.test.ts: Add test coverage for isAccessDeniedError function
- errors.test.ts: Add test coverage for isAccountMismatchError function
- preflight.test.ts: Add tests for account mismatch scenarios including:
  - Throws AccountMismatchError when credentials don't match target
  - Validates against first target when multiple targets exist
  - Falls back to validateAwsCredentials when no targets configured
  - Skips credential validation for teardown deploys

LOW fixes:
- account-extended.test.ts: Add explanatory comment for AccessDenied handling
  during STS:GetCallerIdentity (credentials error vs authorization error)

Note: useCdkPreflight hook test file not created as it would require extensive
React testing infrastructure setup. The critical error handling paths are now
covered by the preflight.test.ts tests.
@aidandaly24 aidandaly24 requested a review from a team April 21, 2026 18:37
@github-actions github-actions Bot added the size/m PR size: M label Apr 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Package Tarball

aws-agentcore-0.9.1.tgz

How to install

npm install https://github.com/aws/agentcore-cli/releases/download/pr-903-tarball/aws-agentcore-0.9.1.tgz

@aidandaly24 aidandaly24 marked this pull request as draft April 21, 2026 18:43
@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 42.52% 7192 / 16913
🔵 Statements 41.92% 7625 / 18187
🔵 Functions 40.22% 1277 / 3175
🔵 Branches 41.12% 4822 / 11726
Generated in workflow #1868 for commit ee04e0c by the Vitest Coverage Report Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants