Skip to content

fix(scaffold): preserve source in scaffold config - #2869

Open
jorrite wants to merge 2 commits into
cloudposse:mainfrom
jorrite:fix-scaffold-source
Open

fix(scaffold): preserve source in scaffold config#2869
jorrite wants to merge 2 commits into
cloudposse:mainfrom
jorrite:fix-scaffold-source

Conversation

@jorrite

@jorrite jorrite commented Aug 5, 2026

Copy link
Copy Markdown

what

  • Fix atmos scaffold generate/atmos init recording a dangling, already-deleted temp-directory path in spec.source of .atmos/scaffold.yaml whenever the template source is remote (git::... or a bare https://... URL).
  • In the filepkg/generator/source/resolver.go: in resolveRemote(), set conf.Source = src (the original source string the caller passed in) after loading the template configuration from the temporary download directory, instead of leaving Configuration.Source as whatever LoadConfigurationFromDir was given (the temp dir itself).
  • pkg/generator/source/resolver_test.go: added/extended tests asserting Configuration.Source holds the original source for both local and remote paths, plus a dedicated regression test (TestResolve_RemoteRecordsOriginalSource) that fails on the pre-fix code and passes after.
  • No change to local source handling (resolveLocal), which already recorded the correct value.

why

  • For a remote scaffold source, resolveRemote() downloads the template into os.MkdirTemp("", "atmos-scaffold-"), then loaded the config with that temp dir passed in as the "source" — so Configuration.Source, and
    therefore the persisted spec.source, ended up holding something like /var/folders/xx/.../atmos-scaffold-1234567890. That directory is removed by cleanup() immediately after the command finishes, so the recorded provenance is a dangling reference to nothing as soon as generation completes — useless for anything that might want to read it back later (e.g. a future --update/re-resolve flow), and directly contradicts SaveProjectRecord's own doc comment: "spec.source and spec.baseRef record provenance for future updates."
  • Local sources (a relative/absolute path, or file://...) were correct only by accident of not having a temp-dir indirection step in resolveLocal, not because anything special-cased provenance for them.
  • Reproduced directly: atmos scaffold generate "git::https://.../scaffold-template.git" ./out --defaults, then cat ./out/.atmos/scaffold.yaml shows a /var/folders/...//tmp/... path for spec.source, and that path no longer exists on disk.

references

  • No upstream GitHub issue — checked issue search and the web for cloudposse/atmos + spec.source/scaffold, nothing matched as of 2026-08.

Summary by CodeRabbit

  • Bug Fixes
    • Remote scaffolds now retain their original source URI after resolution instead of displaying a temporary download location.
    • Local scaffold operations consistently preserve the original source path.

@jorrite
jorrite requested a review from a team as a code owner August 5, 2026 13:00
@atmos-pro

atmos-pro Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@github-actions github-actions Bot added the size/s Small size PR label Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The resolver now preserves the original source path or URI after local, hydrated, and remote scaffold resolution. Tests verify source preservation and remote ZIP loading.

Changes

Source provenance

Layer / File(s) Summary
Resolver source preservation and validation
pkg/generator/source/resolver.go, pkg/generator/source/resolver_test.go
Remote resolution records the caller-provided source URI instead of the temporary download directory. Tests verify local, hydrated, and remote source values. The remote test also verifies files loaded from an HTTP-served ZIP archive.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: patch

Suggested reviewers: aknysh

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preserving the original source in scaffold configuration.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/generator/source/resolver_test.go`:
- Around line 244-259: Update TestResolve_RemoteRecordsOriginalSource to avoid
invoking the git binary or requiring requireGit, initSourceTestGitRepo, or
runSourceTestGit. Use Go-native fixture files with a mocked fetcher, or move the
remote-source fixture setup into test-only implementation support, while
preserving the assertion that cfg.Source equals the original remote source
string.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 815c2a22-a02a-4869-b88b-6a464f49ceed

📥 Commits

Reviewing files that changed from the base of the PR and between c14ce82 and aade2ed.

📒 Files selected for processing (2)
  • pkg/generator/source/resolver.go
  • pkg/generator/source/resolver_test.go

Comment thread pkg/generator/source/resolver_test.go
@jorrite
jorrite force-pushed the fix-scaffold-source branch from aade2ed to f2d9362 Compare August 5, 2026 17:39
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@jorrite jorrite changed the title fix: preserve source in scaffold config fix(scaffold): preserve source in scaffold config Aug 6, 2026
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.77%. Comparing base (d2b8e81) to head (f2d9362).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2869      +/-   ##
==========================================
+ Coverage   82.76%   82.77%   +0.01%     
==========================================
  Files        1861     1861              
  Lines      180438   180439       +1     
==========================================
+ Hits       149342   149363      +21     
+ Misses      23309    23289      -20     
  Partials     7787     7787              
Flag Coverage Δ
unittests 82.77% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/generator/source/resolver.go 82.24% <100.00%> (+0.16%) ⬆️

... and 7 files with indirect coverage changes

🚀 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.

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

Labels

size/s Small size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant