fix(compose): fix package command with cross-service dependency outputs#13438
fix(compose): fix package command with cross-service dependency outputs#13438tmatilai wants to merge 3 commits into
package command with cross-service dependency outputs#13438Conversation
…puts
`serverless package` in a compose setup with service dependencies (e.g.
`${service-a.queueUrl}`) failed because `package` was not handled in the
param resolution fallback — only `print` and `remove` were.
Additionally, `updateLocalState` treated empty state (`{}`) from commands that
don't query CloudFormation as meaningful, which would overwrite previously
saved outputs in the remote state store. Now only state with actual outputs is
persisted, and the remote store is used as fallback.
|
All contributors have signed the CLA ✍️ ✅ |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
📝 WalkthroughWalkthroughFixed the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I have read the CLA Document and I hereby sign the CLA |
|
Disclaimer: AI has been heavily used to diagnose and fix the issues, and for writing the unit tests. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/sf-core/src/lib/runners/compose/index.js`:
- Around line 322-327: The check treating stateValue as missing incorrectly
flags valid falsy outputs (0, false, ''); update the unresolved-output condition
in the block that reads stateValue =
state?.localState?.[splitKey[0]]?.outputs?.[splitKey[1]] so it only treats
null/undefined as unresolved (use explicit null/undefined check or stateValue ==
null), then keep the existing branches that set serviceParams[key] to
'NOT_AVAILABLE_AT_PACKAGE_TIME' for command[0] === 'print' || 'package' and the
remove handling for 'remove'.
In `@packages/sf-core/tests/unit/runners/compose/index.test.js`:
- Around line 1-4: Move the static import of parseComposeGraph so the
jest.unstable_mockModule declaration runs first: remove or relocate the line
importing parseComposeGraph from '../../../../src/lib/runners/compose/index.js'
and instead import parseComposeGraph after calling
jest.unstable_mockModule('@serverless/util', ...) and awaiting or using dynamic
import (e.g., via await import(...)) so the mocked '@serverless/util' is applied
before parseComposeGraph (refer to parseComposeGraph and
jest.unstable_mockModule to find the relevant code).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 32433cfc-3572-444c-93e0-945f9791e621
📒 Files selected for processing (3)
packages/serverless/test/unit/lib/plugins/aws/appsync/utils.test.jspackages/sf-core/src/lib/runners/compose/index.jspackages/sf-core/tests/unit/runners/compose/index.test.js
| const stateValue = | ||
| state?.localState?.[splitKey[0]]?.outputs?.[splitKey[1]] | ||
| if (!stateValue) { | ||
| if (command[0] === 'print') { | ||
| serviceParams[key] = 'NOT_AVAILABLE_IN_PRINT_COMMAND' | ||
| if (command[0] === 'print' || command[0] === 'package') { | ||
| serviceParams[key] = 'NOT_AVAILABLE_AT_PACKAGE_TIME' | ||
| } else if (command[0] === 'remove') { |
There was a problem hiding this comment.
Treat only null/undefined as unresolved cross-service outputs.
The current check treats valid falsy outputs as missing. If a dependency output is 0, false, or '', it will incorrectly fall into placeholder/error logic.
💡 Proposed fix
- if (!stateValue) {
+ if (stateValue === undefined || stateValue === null) {
if (command[0] === 'print' || command[0] === 'package') {
serviceParams[key] = 'NOT_AVAILABLE_AT_PACKAGE_TIME'
} else if (command[0] === 'remove') {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/sf-core/src/lib/runners/compose/index.js` around lines 322 - 327,
The check treating stateValue as missing incorrectly flags valid falsy outputs
(0, false, ''); update the unresolved-output condition in the block that reads
stateValue = state?.localState?.[splitKey[0]]?.outputs?.[splitKey[1]] so it only
treats null/undefined as unresolved (use explicit null/undefined check or
stateValue == null), then keep the existing branches that set serviceParams[key]
to 'NOT_AVAILABLE_AT_PACKAGE_TIME' for command[0] === 'print' || 'package' and
the remove handling for 'remove'.
There was a problem hiding this comment.
This sounds like a correct finding, but it's not directly related to the issue that this PR is fixing. So I would say it's out of scope here, but I'll leave it to the maintainers.
There was a problem hiding this comment.
@tmatilai, understood — the fix here is specifically about enabling package to resolve cross-service dependency outputs, so this is indeed a pre-existing edge case. Would you like me to open a follow-up GitHub issue to track fixing the falsy-output check (!stateValue → stateValue == null) so it doesn't get lost?
…ith-refs # Conflicts: # packages/serverless/test/unit/lib/plugins/aws/appsync/utils.test.js
serverless packagein a compose setup with service dependencies (e.g.${service-a.queueUrl}) failed becausepackagewas not handled in the param resolution fallback — onlyprintandremovewere.Additionally,
updateLocalStatetreated empty state ({}) from commands that don't query CloudFormation as meaningful, which would overwrite previously saved outputs in the remote state store. Now only state with actual outputs is persisted, and the remote store is used as fallback.Also fix unit tests in a non-UTC timezone.
Closes: #13437
Summary by CodeRabbit
Tests
Bug Fixes