Skip to content

fix(project): refuse status outside the project's deployed region - #2241

Merged
AlexanderRichey merged 1 commit into
refactorfrom
status-region-guard
Sep 4, 2026
Merged

fix(project): refuse status outside the project's deployed region#2241
AlexanderRichey merged 1 commit into
refactorfrom
status-region-guard

Conversation

@AlexanderRichey

Copy link
Copy Markdown
Contributor

What

project status now refuses to describe a project whose target is deployed in a region other than the one the command runs in. The CLI throws a ProjectStateError naming both regions; the bare TUI shows the same message in place of the Linked Resources tree and keeps esc as the way back. Rerun with --region <target region> to see the report.

Why

A bare project status links each deployed row to its detail page with ?region=<target>, but the actions those pages open in turn (endpoints, events, detail JSON, …) run in the ambient region, so a project deployed anywhere else broke one step past the tree. #2239 tried to carry the region through every flow instead; this is the smaller guard. The headless report has the same problem one step later: the ids it prints only work with the same --region.

How

  • src/handlers/project/status/index.ts: compare the resolved target's region with the context's RegionKey after resolving resources and before rendering.
  • src/handlers/project/status/screen.tsx: ProjectStatusView takes the context, and renders the mismatch message instead of the resources heading and tree.

Tests

  • Headless (index.test.ts): the suite pins AWS_REGION to the default target's region (restored after each test), since withRegion would otherwise read the developer's shell. The --target staging case now passes a matching --region. New case: a mismatched target rejects with a ProjectStateError that names both regions, an explicit --region takes part in the same comparison, and nothing is written to stdout.
  • Screen (status.screen.test.tsx): renderStatus pins RegionKey to the target's region so the existing tree and navigation tests still apply. New case: with the base context's us-east-1 against a eu-west-1 target, the message renders, no agent group or runtime row does, enter stays put, and esc returns to the project menu.
  • Both new cases fail against the previous source and pass with the change.

Checks

🤖 Generated with Claude Code

https://claude.ai/code/session_016KnHdxcPYTnQiDY7Y1PY6s

A bare `project status` links each deployed row to its detail page with
?region=<target>, but the actions those pages open in turn (endpoints,
events, detail JSON, …) run in the ambient region, so a project deployed
anywhere else breaks one step past the tree (#2239 tried to thread the
region through every flow instead). The headless report has the same
problem one step later: the ids it prints only work with the same
--region.

Compare the resolved target's region with the context's before rendering.
The CLI throws a ProjectStateError naming both regions; the screen shows
the same message in place of the tree and keeps esc as the way out. Rerun
with --region <target region> to see the report.

The headless tests pin AWS_REGION to the default target's region, since
withRegion would otherwise read the developer's shell, and the screen
tests pin RegionKey to the target's so the tree still renders; each
suite gains a mismatch case of its own.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016KnHdxcPYTnQiDY7Y1PY6s
@github-actions github-actions Bot added the size/m PR size: M label Sep 4, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added agentcore-harness-reviewing AgentCore Harness review in progress claude-security-reviewing Claude Code /security-review in progress labels Sep 4, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Sep 4, 2026

@agentcore-devx-automation agentcore-devx-automation Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AgentCore Harness Review

Verdict: Looks good

Nice, focused change. The behavior is well-motivated (downstream commands run in the ambient region, so listing IDs from another region invites errors) and the same rule is applied consistently in the headless handler and the TUI screen, with matching wording.

A few observations, none blocking:

  • Both ctx.require(RegionKey) sites are safe: withRegion middleware always resolves a value at the root, and the screen test harness (baseContext in src/testing/renderScreen.tsx) always pins RegionKey, matching production behavior.
  • resolveProjectResources uses target.region for the describeStack call, so resolution correctly succeeds against the target's region before the ambient-region check gates rendering. That means an out-of-region call still incurs the CloudFormation round-trip, but that's needed to construct a helpful error and matches the TUI's flow.
  • In screen.tsx, when isWrongRegion is true the Layout still advertises ↑↓/jk navigate, enter open key hints even though nothing is focusable. Minor UX polish, not a blocker.
  • Headless --json callers now get a thrown ProjectStateError instead of a JSON report when they omit --region. That's consistent with other ProjectStateError sites in the CLI, so this is fine.

No changes required from me.

@agentcore-devx-automation agentcore-devx-automation Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Sep 4, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.04%. Comparing base (0e5d680) to head (f401fd3).

Additional details and impacted files
@@            Coverage Diff            @@
##           refactor    #2241   +/-   ##
=========================================
  Coverage     97.04%   97.04%           
=========================================
  Files           566      566           
  Lines         39392    39409   +17     
=========================================
+ Hits          38227    38244   +17     
  Misses         1165     1165           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This project is deployed to {status.data.target.region}, not {region}
</Text>
)}
{!isWrongRegion && (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we also throw ProjectStateError here

@AlexanderRichey
AlexanderRichey merged commit d9ab959 into refactor Sep 4, 2026
18 of 24 checks passed
@AlexanderRichey
AlexanderRichey deleted the status-region-guard branch September 4, 2026 21:48
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.

5 participants