Skip to content

fix(generate): don't fall back to stale OZ examples when GitHub API fails - #649

Merged
chadoh merged 1 commit into
mainfrom
fix/oz-examples-cache
Oct 25, 2026
Merged

chadoh merged 1 commit into
mainfrom
fix/oz-examples-cache

Conversation

@pselle

@pselle pselle commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

What

Follow-up to #647. In v0.0.33, stellar scaffold generate contract --from oz/nft-royalties could still produce a contract that doesn't compile:

⚠️  Failed to update examples cache: HTTP status client error (403 Forbidden) for url (https://api.github.com/repos/OpenZeppelin/stellar-contracts/releases/tags/v0.8.0)
⚠️  Workspace stellar-tokens version doesn't match the example's 0.6.0 (example might not compile).
✅ Successfully downloaded example 'nft-royalties' to contracts/nft-royalties

Before downloading, the CLI called the GitHub releases API to look up the tag it had already pinned. When that call failed (403 is GitHub's response to the unauthenticated rate limit), it fell back to the newest release in the local cache. After an upgrade, that is the v0.6.0 cached by older CLI versions, so the 0.6.0 sources were copied into a 0.8.0 project.

Changes

  • Drop the releases API call. The OZ tag is pinned, so it's used directly, and once it's cached nothing is fetched at all. The archive still comes from github.com/.../archive/<tag>.tar.gz, which isn't subject to the REST API rate limit.
  • Remove the fallback to other cached versions (it also picked the "latest" tag by string comparison, which is wrong for both v0.10 vs v0.9 and the soroban-examples commit hash). If the pinned examples can't be downloaded, the command fails with the download error.
  • Extract downloads into a temporary directory and rename into place on success, so an interrupted download can't leave a cache entry that's treated as complete.
  • Replace the outdated "modify your environments.toml" hint with how to add the contract to scaffold.yml (type: workspace, source: <package name>, constructor args), matching the CLI docs. The --from-wizard instructions get the same update.

The --ls usage lines (contract generate → generate contract) are left for a separate PR.

Testing

  • Cache holding only v0.6.0 (the reported state): with no network, the command now errors instead of copying v0.6.0 sources.
  • Cache holding v0.6.0 and v0.8.0: uses v0.8.0 without any network call; the generated nft-royalties compiles in the UI template workspace.
  • New unit test for the pinned-cache lookup ignoring stale releases; removed the tests for the deleted API helper. cargo test -p stellar-scaffold-cli --lib (241 passed), clippy and fmt clean.

…ails

`generate contract --from oz/...` asked the GitHub releases API for the
pinned OZ tag before downloading. When that call failed (e.g. a 403 from
the unauthenticated rate limit), it fell back to the newest *cached*
release, which after upgrading the CLI is the old v0.6.0, so the
generated contract again didn't compile against the 0.8.0 deps.

- Drop the releases API call: the tag is pinned, so use it directly and
  skip the network entirely once it's cached
- Remove the fallback to other cached versions; fail with the download
  error instead
- Extract downloads to a temporary dir and rename on success, so an
  interrupted download can't leave a cache entry that looks complete
- Replace the outdated environments.toml hint with how to add the
  contract to scaffold.yml

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jca3yR4pe5iqLYCw8bXqes
@pselle pselle self-assigned this Oct 25, 2026
@chadoh
chadoh merged commit dbce274 into main Oct 25, 2026
9 checks passed
@chadoh
chadoh deleted the fix/oz-examples-cache branch October 25, 2026 15:37
pselle pushed a commit that referenced this pull request Oct 25, 2026
## 🤖 New release

* `stellar-scaffold-cli`: 0.0.33 -> 0.0.34 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[0.0.34](stellar-scaffold-cli-v0.0.33...stellar-scaffold-cli-v0.0.34)
- 2026-10-25

### Fixed

- *(generate)* don't fall back to stale OZ examples when GitHub API
fails ([#649](#649))

### Other

- Fix --ls listing incorrect commands at the end
([#648](#648))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: aha-release-plz[bot] <211513279+aha-release-plz[bot]@users.noreply.github.com>
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.

3 participants