Example Scenarios
Scenario 1: First Hex Package Download
Dependency: {jsx, "3.1.0"}
Execution: rebar3 compile (first time)
Flow:
- Resolution determines need for jsx 3.1.0
- Call
maybe_fetch→ needs download - Call
rebar_pkg_resource:download/4 - Check cache:
~/.cache/rebar3/hex/hexpm/packages/jsx-3.1.0.tardoesn't exist - Request from Hex:
GET /tarballs/jsx-3.1.0 - Download tarball (HTTP 200)
- Verify checksum:
sha256(tarball)vs registry checksum - Store in cache with ETag
- Extract to
_build/default/lib/jsx/ - Read
jsx/rebar.config - Discover jsx application
- Mark as available
Files Created:
~/.cache/rebar3/hex/hexpm/packages/jsx-3.1.0.tar~/.cache/rebar3/hex/hexpm/packages/jsx-3.1.0.etag_build/default/lib/jsx/(full source tree)
Scenario 2: Cached Hex Package (ETag Valid)
Dependency: {jsx, "3.1.0"}
Execution: rebar3 compile (after clean, cache still valid)
Flow:
- Check cache: tarball exists
- Read ETag file:
"abc123" - Request from Hex with
If-None-Match: "abc123" - Hex returns HTTP 304 Not Modified
- Use cached tarball
- Extract to
_build/default/lib/jsx/ - Discover application
Network: Minimal (only HTTP HEAD request equivalent)
Scenario 3: Git Dependency with Tag
Dependency:
{cowboy, {git, "https://github.com/ninenines/cowboy.git", {tag, "2.9.0"}}}
Execution: rebar3 compile (first time)
Flow:
-
Call
rebar_git_resource:download/4 -
Detect Git version: 2.30.0
-
Execute:
git clone --depth 1 --no-single-branch \ https://github.com/ninenines/cowboy.git \ /tmp/rebar-abc123/cowboy \ -b 2.9.0 --single-branch -
Clone completes to temporary directory
-
Move to
_build/default/lib/cowboy/ -
Read
cowboy/rebar.config:{deps, [cowlib, ranch]}. -
Discover cowboy application
-
Add cowlib and ranch to dependency queue
Subsequent Runs:
- Check if update needed:
git describe --tags --exact-match - Compare with "2.9.0"
- If match: skip re-download
Scenario 4: Git Dependency with Branch
Dependency:
{my_dep, {git, "https://github.com/user/my_dep.git", {branch, "main"}}}
First Run:
- Clone with
-b main --single-branch - Extract to
_build/default/lib/my_dep/
Subsequent Runs:
-
Check for updates:
cd _build/default/lib/my_dep git fetch origin main git log HEAD..origin/main --oneline -
If output not empty: new commits available
-
Pull updates
-
Re-compile
Warning: Branches are mutable; can cause non-reproducible builds
Scenario 5: Offline Mode with Cache
Setup:
- jsx 3.1.0 previously downloaded and cached
- Offline mode enabled
Execution: REBAR_OFFLINE=1 rebar3 compile
Flow:
- Attempt fetch for jsx
- Detect offline mode
- Check cache: tarball exists
- Use cached tarball without network request
- Extract and proceed
Success: Works without network
Scenario 6: Offline Mode Without Cache
Setup:
- Fresh dependency not in cache
- Offline mode enabled
Execution: REBAR_OFFLINE=1 rebar3 compile
Flow:
- Attempt fetch for new_dep
- Detect offline mode
- Check cache: not found
- Error: cannot fetch in offline mode
Error:
Cannot fetch dependency in offline mode
Solution: Disable offline mode or pre-cache
Scenario 7: Corrupted Package Cache
Setup: Cached package has wrong checksum (corruption or tampering)
Execution: rebar3 compile
Flow:
- Check cache: jsx-3.1.0.tar exists
- Use cached tarball
- Calculate checksum
- Compare with registry
- Mismatch detected
- Clear ETag file
- Error reported
Error:
The checksum for package at jsx-3.1.0 (WRONG_HASH) does not match
the checksum expected from the registry (CORRECT_HASH).
Run `rebar3 do unlock jsx, update` and then try again.
Recovery:
rm ~/.cache/rebar3/hex/hexpm/packages/jsx-3.1.0.*
rebar3 compile
Scenario 8: Authentication Required for Private Git Repo
Dependency:
{private_dep, {git, "git@github.com:company/private_dep.git", {tag, "1.0.0"}}}
Execution: rebar3 compile
Prerequisites: SSH key added to GitHub account
Flow:
- Git uses SSH authentication
- Reads
~/.ssh/id_rsaor configured key - Authenticates with GitHub
- Clone proceeds normally
If Authentication Fails:
Permission denied (publickey).
fatal: Could not read from remote repository.
Solution:
- Add SSH key to GitHub
- Or use HTTPS with token:
https://TOKEN@github.com/company/private_dep.git