Skip to content

Comments

Stacks Cleanup#1855

Merged
lionello merged 2 commits intomainfrom
jordan/stacks
Jan 23, 2026
Merged

Stacks Cleanup#1855
lionello merged 2 commits intomainfrom
jordan/stacks

Conversation

@jordanstephens
Copy link
Member

@jordanstephens jordanstephens commented Jan 23, 2026

Description

  • Avoid reading from global.Stack when session.Stack is available
  • Set options.RequireStack = true for deployments to force selection when interactive

Linked Issues

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 configuration and mode now properly use active session context instead of global settings, improving multi-session workflow handling.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

This PR shifts stack context sourcing from global to per-session references in the CLI command layer, updating stack mode propagation and initialization checks in cd.go and compose.go to use the active session stack instead of the global stack.

Changes

Cohort / File(s) Summary
Stack Context Migration
src/cmd/cli/command/cd.go, src/cmd/cli/command/compose.go
Replaced global stack references with session stack across the compose-up and cd flows. In cd.go, Mode source changed to session.Stack.Mode. In compose.go, added options.RequireStack = true, switched debugger initialization, mode propagation, and stack existence checks to use session.Stack instead of global.Stack.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Global stacks? Oh how they used to roam,
But now each session calls its stack back home,
Per-context references hop and play,
Building cleaner CLI logic today! 🌿✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
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.
Title check ❓ Inconclusive The title 'Stacks Cleanup' is vague and does not clearly describe the specific changes made to the codebase. While related to stacks, it lacks specificity about the actual modifications (migrating from global.Stack to session.Stack). Revise the title to be more specific, such as 'Migrate stack references from global to session context' or 'Use session.Stack instead of global.Stack for compose operations'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings

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"


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

@lionello lionello marked this pull request as ready for review January 23, 2026 03:46
@lionello lionello merged commit f46a8f9 into main Jan 23, 2026
14 checks passed
@lionello lionello deleted the jordan/stacks branch January 23, 2026 06:20
lionello added a commit that referenced this pull request Jan 24, 2026
* Retry setting the policies on service account up to 3 times (#1851)

* Retry setting the policies on service account up to 3 times

* Address code rabbit comment

* continue to the correct outter check policy loop

---------

Co-authored-by: Edward J <edw@defang.io>

* fix(upgrade): avoid running slow "brew config" unless necessary (#1859)

* fix: use shortened links for docs (#1858)

* Stacks Cleanup (#1855)

* avoid reading from global stacks when session stacks is available

* require stack during deployment in interactive mode

* Lio/stacks (#1860)

* avoid reading from global stacks when session stacks is available

* require stack during deployment in interactive mode

* fix: panic when DEFANG_PROVIDER is not set

would cause GetRegionVarName("")

* fix: handle empty stack file

* fix: abort stack loading on ctrl-c

---------

Co-authored-by: Jordan Stephens <jordan@stephens.io>

* chore: fix estimate unit test

* Standardize the file and dir mode for context test (#1852)

* Standardize the file and dir mode for context test

* Update src/pkg/cli/compose/context_test.go

* Remove unused import term

---------

Co-authored-by: Edward J <edw@defang.io>
Co-authored-by: Lio李歐 <lionello@users.noreply.github.com>

* allow --provider to override default stack (#1862)

* allow fallback stack when !RequireStack

* s/RequireStack/DisallowFallbackStack/

* only log fallback when actually using fallback

* s/RequireStack/DisallowFallbackStack/

* prefer --provider if available

* coderabbbit feedback

* refactor: improve error handling and warnings in whoami command

---------

Co-authored-by: Lionello Lunesu <lio+git@lunesu.com>
Co-authored-by: Hao Jiang <edwardrf@gmail.com>

* fix: don't overwrite known state with NOT_SPECIFIED

* fix(aws): add CloudFormation metadata

---------

Co-authored-by: Hao Jiang <edwardrf@gmail.com>
Co-authored-by: Edward J <edw@defang.io>
Co-authored-by: Jordan Stephens <jordan@stephens.io>
lionello added a commit that referenced this pull request Jan 25, 2026
* fix(aws): make CIRoleArn output ARN

* feat(aws): CloudFormation metadata (#1863)

* Retry setting the policies on service account up to 3 times (#1851)

* Retry setting the policies on service account up to 3 times

* Address code rabbit comment

* continue to the correct outter check policy loop

---------

Co-authored-by: Edward J <edw@defang.io>

* fix(upgrade): avoid running slow "brew config" unless necessary (#1859)

* fix: use shortened links for docs (#1858)

* Stacks Cleanup (#1855)

* avoid reading from global stacks when session stacks is available

* require stack during deployment in interactive mode

* Lio/stacks (#1860)

* avoid reading from global stacks when session stacks is available

* require stack during deployment in interactive mode

* fix: panic when DEFANG_PROVIDER is not set

would cause GetRegionVarName("")

* fix: handle empty stack file

* fix: abort stack loading on ctrl-c

---------

Co-authored-by: Jordan Stephens <jordan@stephens.io>

* chore: fix estimate unit test

* Standardize the file and dir mode for context test (#1852)

* Standardize the file and dir mode for context test

* Update src/pkg/cli/compose/context_test.go

* Remove unused import term

---------

Co-authored-by: Edward J <edw@defang.io>
Co-authored-by: Lio李歐 <lionello@users.noreply.github.com>

* allow --provider to override default stack (#1862)

* allow fallback stack when !RequireStack

* s/RequireStack/DisallowFallbackStack/

* only log fallback when actually using fallback

* s/RequireStack/DisallowFallbackStack/

* prefer --provider if available

* coderabbbit feedback

* refactor: improve error handling and warnings in whoami command

---------

Co-authored-by: Lionello Lunesu <lio+git@lunesu.com>
Co-authored-by: Hao Jiang <edwardrf@gmail.com>

* fix: don't overwrite known state with NOT_SPECIFIED

* fix(aws): add CloudFormation metadata

---------

Co-authored-by: Hao Jiang <edwardrf@gmail.com>
Co-authored-by: Edward J <edw@defang.io>
Co-authored-by: Jordan Stephens <jordan@stephens.io>

---------

Co-authored-by: Hao Jiang <edwardrf@gmail.com>
Co-authored-by: Edward J <edw@defang.io>
Co-authored-by: Jordan Stephens <jordan@stephens.io>
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