# Navigate to the examples directory (pre-configured test environment)
cd examples
# Initialize shell integration
eval "$(envlit init)"
# Now you can use 'el' and 'eul' aliases
el dev --cuda 2
eulThis guide helps you validate envlit's behavior, not prescribe every test case. Use the pre-configured examples/.envlit/ configs and explore freely in a fresh terminal.
What to check:
- Run
envlit load dev --help- Do flags from YAML (--cuda,--backend) appear? - Are flag aliases working? (e.g.,
-gfor--cuda) - Do default values show up in help text?
- Can you set flags:
el dev --cuda 3 --backend g?
Expected behavior:
- YAML-defined flags become real CLI options
- Help messages reflect current config
- Flags override env section values
What to check:
# Load dev profile with flags
el dev --cuda 2 --backend t
# Verify variables are set
echo $CUDA_VISIBLE_DEVICES # Should be "2"
echo $ML_COMPUTE_BACKEND # Should be "TPU" (mapped from "t")
echo $PROJECT_MODE # Should be "Development"
echo $DEBUG # Should be "true"Expected behavior:
- Variables are exported correctly
- Flag mappings work (backend: c→CPU, g→GPU, t→TPU)
- PATH operations apply (check
echo $PATHfor prepended values) - Hooks execute and print messages
This is where the Compare-and-Swap algorithm matters most.
# Start fresh
export CUDA_VISIBLE_DEVICES="0"
echo "Initial: $CUDA_VISIBLE_DEVICES"
# Load 1
el dev --cuda 1
echo "After load 1: $CUDA_VISIBLE_DEVICES" # Should be "1"
# Load 2 (without unload)
el dev --cuda 2
echo "After load 2: $CUDA_VISIBLE_DEVICES" # Should be "2"
# Unload
eul
echo "After unload: $CUDA_VISIBLE_DEVICES" # Should be "0" (original!)Expected: Unload restores to the very first original value (0), not 1 or 2.
# Start fresh
export CUDA_VISIBLE_DEVICES="0"
# Load 1
el dev --cuda 1
echo "After load: $CUDA_VISIBLE_DEVICES" # Should be "1"
# Manual intervention (you change it yourself)
export CUDA_VISIBLE_DEVICES="7"
echo "After manual change: $CUDA_VISIBLE_DEVICES" # Is "7"
# Load 2 (envlit detects interference!)
el dev --cuda 3
echo "After load 2: $CUDA_VISIBLE_DEVICES" # Should be "3"
# Unload
eul
echo "After unload: $CUDA_VISIBLE_DEVICES" # Should be "7" (respects your manual change!)Expected: When you manually change a tracked variable, envlit treats that as the new "original" to restore to. This is the smart part of Compare-and-Swap.
# Start fresh (DEBUG not set)
unset DEBUG
# Load dev profile
el dev
echo "After load: $DEBUG" # Should be "true" (from config)
# Manual change after load
export DEBUG=false
echo "After manual change: $DEBUG" # Is "false"
# Unload directly (without reload)
eul
echo "After unload: $DEBUG" # Should be "false" (preserves your manual change!)Expected: envlit detects manual changes at unload time and preserves them. If you changed DEBUG from true to false, unload will restore it to false, not unset it or revert to the config value.
Why this matters: This ensures manual tweaks made during development aren't lost when switching contexts.
What to check:
# Append /usr/local/old-tools
export PATH="$PATH:/usr/local/old-tools"
echo "Before: $PATH"
el dev
echo "After: $PATH"
# Verify:
# - "./bin" and "./scripts" are prepended
# - "/usr/local/old-tools" is removed (if it was there)Expected behavior:
prependadds to frontappendadds to endremoveeliminates all occurrences- Operations apply in order
What to check:
el dev 2>&1 | grep -E "Hello|Checking dependencies|Development environment loaded"
eul 2>&1 | grep -E "Unloading|restored"Expected behavior:
- Pre-load hooks run before variables are set
- Post-load hooks run after variables are set
- Hook output is visible
- Inheritance works (base.yaml hooks + dev.yaml hooks both execute)
What to check:
# dev.yaml extends base.yaml
el dev 2>&1
# Look for:
# "Hello, this is pre-load hook from common base." (from base.yaml)
# "🐍 Checking dependencies..." or similar (from dev.yaml)Expected behavior:
- Base config is loaded first
- Child config merges/overrides
- Hooks from both configs execute
# Fresh terminal, no envlit state
eul
# Expected: Should handle gracefully, not crashel dev --cuda 1
echo $DEBUG $CUDA_VISIBLE_DEVICES # Should be "true" and "1"
el prod # Load different profile without unload
echo $DEBUG $CUDA_VISIBLE_DEVICES # Should be "false" and "1"
# Current behavior: Variables accumulate (this might be expected or not)String values (shortcut for set):
cat > /tmp/test-ops.yaml << 'EOF'
env:
PROJECT_MODE: "Development"
DEBUG: "true"
EOF
el -c /tmp/test-ops.yaml
echo $PROJECT_MODE # Should be "Development"
echo $DEBUG # Should be "true"
eulExplicit operations:
cat > /tmp/test-ops2.yaml << 'EOF'
env:
API_URL:
op: set
value: "http://localhost:8000"
PRODUCTION_KEY:
op: unset
PATH:
op: prepend
value: "./venv/bin"
EOF
export PRODUCTION_KEY="secret"
el -c /tmp/test-ops2.yaml
echo $API_URL # Should be "http://localhost:8000"
echo $PRODUCTION_KEY # Should be unset (no output)
echo $PATH | head -c 20 # Should start with "./venv/bin"
eulOperation pipeline:
cat > /tmp/test-pipeline.yaml << 'EOF'
env:
PATH:
- op: remove
value: "/old/path"
- op: prepend
value: "./bin"
- op: append
value: "/opt/bin"
EOF
export PATH="/usr/bin:/old/path:/bin"
el -c /tmp/test-pipeline.yaml
echo $PATH # Should be "./bin:/usr/bin:/bin:/opt/bin" (removed /old/path)
eul
echo $PATH # Should be "/usr/bin:/old/path:/bin" (restored)# Create test config with special chars
cat > /tmp/test-special.yaml << 'EOF'
env:
FOO: 0
BAR: $FOO
BAZ: ${SOME_ENV_VAR:-default}
# Literal dollar: use interpolate: false
PRICE:
op: set
value: "Item costs $100"
interpolate: false
DOLLAR_VAR:
op: set
value: "$JAVA_HOME is the variable name"
interpolate: false
# Backticks are always literal (auto-escaped)
NOTE: "Use `command` syntax"
# Quotes work via YAML alternation
SINGLE: "Has 'single' quotes"
DOUBLE: 'Has "double" quotes'
TEST_REF: '${HOME}/path'
EOF
el -c /tmp/test-special.yaml
echo $FOO # Should be "0"
echo $BAR # Should be "0" (expanded from $FOO)
echo $BAZ # Should be "default"
echo $PRICE # Should be "Item costs $100" (literal dollar)
echo $DOLLAR_VAR # Should be "$JAVA_HOME is the variable name"
echo $NOTE # Should be "Use `command` syntax" (backticks literal)
echo $TEST_REF # ${HOME} should be expanded by shell# Variable starts unset
unset CUDA_VISIBLE_DEVICES
el dev --cuda 0 # If config sets CUDA_VISIBLE_DEVICES
eul # Should CUDA_VISIBLE_DEVICES be unset again (not empty string)?
env | grep CUDA_VISIBLE_DEVICES # Expected: No output (still unset)
# Variable starts empty
export CUDA_VISIBLE_DEVICES=""
el dev --cuda 0
eul # Should CUDA_VISIBLE_DEVICES be "" (empty), not unset?
env | grep CUDA_VISIBLE_DEVICES # Expected: CUDA_VISIBLE_DEVICES="" (still set, but empty)Expected: envlit distinguishes between null (unset) and "" (empty).
✅ Idempotency: Loading the same config twice should be safe ✅ Reversibility: Unload should restore original state ✅ Transparency: User can see what envlit will do before sourcing ✅ Predictability: Manual changes are respected (Compare-and-Swap) ✅ Informativeness: Error messages guide users to solutions
❌ Variables not restored correctly after unload
❌ Dynamic flags missing from --help
❌ Hooks not executing or executing in wrong order
❌ Special characters causing shell injection or errors
❌ State corruption after manual interference
❌ Cryptic error messages
- Use fresh terminals for each test scenario to avoid state pollution
- Check intermediate state: Look at
$__ENVLIT_STATE_<hash>to see tracked variables (it's JSON) - Read generated scripts:
envlit load devshows what would be sourced - Test error paths: Try loading non-existent profiles, invalid YAML, missing flags
- Verify hooks: Add
set -xin hooks to see execution trace - Compare outputs: Does behavior match design spec from the main document?
An AI agent should be able to:
- Load any example config and verify variables are set correctly
- Perform the two main Compare-and-Swap scenarios successfully
- Identify when behavior deviates from design spec
- Propose fixes for any issues found
envlit/state.py- Compare-and-Swap algorithm implementationenvlit/internal.py- State tracking (begin/end/restore)envlit/script_generator.py- Shell script generation & escapingenvlit/config.py- YAML parsing & inheritanceenvlit/cli.py- Dynamic flag injectiontests/test_*.py- Unit tests show expected behavior
The Compare-and-Swap Algorithm:
envlit tracks
original(restore point) andcurrent(last value envlit set). When loading, it compares the actual shell value withcurrent. If they differ, user interference is detected, andoriginalis updated to the user's value. This ensures unload always restores to what the user expects, not what envlit first saw.
Your testing should confirm this principle holds in practice.