Skip to content

Comments

prefer remote stack to local #1891

Merged
jordanstephens merged 3 commits intomainfrom
jordan/2655
Feb 3, 2026
Merged

prefer remote stack to local #1891
jordanstephens merged 3 commits intomainfrom
jordan/2655

Conversation

@jordanstephens
Copy link
Member

@jordanstephens jordanstephens commented Feb 2, 2026

Description

Prefer remote to local stacks when listing

Linked Issues

Fixes https://github.com/DefangLabs/defang-mvp/issues/2655

Checklist

  • I have performed a self-review of my code
  • I have added appropriate tests
  • I have updated the Defang CLI docs and/or README to reflect my changes, if necessary

Summary by CodeRabbit

  • Bug Fixes

    • Stack merge now prioritizes remote stacks when names conflict; remote metadata (deployment timing and defaults) take precedence and local-only fields are no longer merged into remote entries.
  • Tests

    • Updated test expectations to reflect remote-wins merge behavior, including changes to region, mode, and local environment variable propagation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

List() merge behavior changed to a remote-wins strategy: local stacks are inserted first, then remote stacks overwrite entries with matching names. Previous post-merge alignment of fields like DeployedAt and Default was removed.

Changes

Cohort / File(s) Summary
Merge Strategy Simplification
src/pkg/stacks/manager.go
Rewrote List() merge to insert local stacks into a map then overwrite with remote stacks; removed post-merge copying of DeployedAt/Default and local-only ListItem construction.
Test Expectations Update
src/pkg/stacks/manager_test.go
Updated TestManager_ListMerged to reflect remote-wins: shared stack region now us-east-1, mode becomes ModeUnspecified, and local AWS_PROFILE no longer carried over.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • lionello

Poem

🐰 I hopped through lines of code today,

Remote stacks now lead the way.
No more copying fields askew,
Simpler logic, clean and true.
A carrot-cheer for builds anew 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'prefer remote stack to local' directly and clearly describes the main change to the merge logic in manager.go where remote stacks now overwrite local entries.
Linked Issues check ✅ Passed The PR changes implement the requirement from issue #2655 to prefer remote deployment information over local stack file values, ensuring the displayed mode matches the latest deployed mode.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective of preferring remote stacks over local stacks; no unrelated modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jordan/2655

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

level=warning msg="[linters_context] running gomodguard failed: unable to read module file go.mod: current working directory must have a go.mod file: if you are not using go modules it is suggested to disable this linter"
level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Failure to add the new IP will result in interrupted reviews.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/pkg/stacks/manager_test.go`:
- Line 419: The assertion message for assert.Equal(t, "us-east-1",
sharedStack.Region, ...) is misleading — it mentions “local region” while the
test expects the remote region to win; update the message to reflect remote-wins
behavior (e.g., "Expected shared stack to use remote region us-east-1" or
similar) so it matches the expected value and clarifies the test intent; locate
the assertion referencing sharedStack.Region in manager_test.go and replace the
message string accordingly.

In `@src/pkg/stacks/manager.go`:
- Around line 65-73: The merge currently overwrites stackMap entries with later
remoteStacks entries causing older duplicates to replace newer ones; update the
remote merge so the most recent remote wins by either iterating remoteStacks in
reverse or comparing timestamps: in the loop that processes remoteStacks (which
populates stackMap from remote into ListItem), check existing :=
stackMap[remote.Name]; if existing exists and existing.DeployedAt is after
remote.DeployedAt, skip assignment; otherwise set stackMap[remote.Name] = remote
so the entry with the latest DeployedAt (newest) is kept for List().

Copy link
Member

@lionello lionello left a comment

Choose a reason for hiding this comment

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

I see how this fixes the issue, but can't say for sure this is the best solution. What to do if local stack (used when I do up) differs from remote?

Perhaps we should add a column to show whether the info was local or remote.

@lionello lionello changed the title prefer remote stack to local. Fixes #2655 prefer remote stack to local Feb 3, 2026
@jordanstephens
Copy link
Member Author

I see how this fixes the issue, but can't say for sure this is the best solution. What to do if local stack (used when I do up) differs from remote?

Perhaps we should add a column to show whether the info was local or remote.

I agree, but I think this PR is a good step forward for the moment.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@jordanstephens jordanstephens merged commit 6adc8d9 into main Feb 3, 2026
13 checks passed
@jordanstephens jordanstephens deleted the jordan/2655 branch February 3, 2026 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants