-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(sandbox): allow openclaw.json writes for channel configuration (fixes #606) #637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -241,6 +241,52 @@ console.assert(state.lastAction === null, 'Should be cleared'); | |||||||||||||||||||
| console.log('State management: create, save, load, clear all working'); | ||||||||||||||||||||
| " && pass "NemoClaw state management works" || fail "State management broken" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # ------------------------------------------------------- | ||||||||||||||||||||
| info "11. Verify writable config overlay for runtime writes (#606)" | ||||||||||||||||||||
| # ------------------------------------------------------- | ||||||||||||||||||||
| python3 -c " | ||||||||||||||||||||
| import json, os, shutil | ||||||||||||||||||||
|
|
||||||||||||||||||||
| home = os.environ.get('HOME', '/sandbox') | ||||||||||||||||||||
| immutable = os.path.join(home, '.openclaw', 'openclaw.json') | ||||||||||||||||||||
| writable = os.path.join(home, '.openclaw-data', 'openclaw.json') | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Clean up any prior writable copy | ||||||||||||||||||||
| if os.path.exists(writable): | ||||||||||||||||||||
| os.remove(writable) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Simulate what prepare_writable_config does | ||||||||||||||||||||
| assert os.path.isfile(immutable), f'Immutable config missing: {immutable}' | ||||||||||||||||||||
| shutil.copy2(immutable, writable) | ||||||||||||||||||||
| os.chmod(writable, 0o600) | ||||||||||||||||||||
|
Comment on lines
+258
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Search for creation of .openclaw-data directory
rg -n '\.openclaw-data' --type sh --type pyRepository: NVIDIA/NemoClaw Length of output: 235 🏁 Script executed: # Search for any mkdir/makedirs operations
rg -n '(mkdir|makedirs)' --type sh --type pyRepository: NVIDIA/NemoClaw Length of output: 1597 🏁 Script executed: # Look at prepare_writable_config function in nemoclaw-start.sh
sed -n '130,150p' scripts/nemoclaw-start.shRepository: NVIDIA/NemoClaw Length of output: 889 🏁 Script executed: # Examine the complete test setup around lines 244-288
sed -n '244,288p' test/e2e-test.shRepository: NVIDIA/NemoClaw Length of output: 1692 🏁 Script executed: # Search for test setup/initialization
sed -n '1,243p' test/e2e-test.sh | grep -n -A2 -B2 "openclaw-data\|mkdirSync\|makedirs"Repository: NVIDIA/NemoClaw Length of output: 368 🏁 Script executed: # Check if there's a setup.sh or fixture that creates directories
git ls-files | grep -E "(setup|fixture|init)" | head -20Repository: NVIDIA/NemoClaw Length of output: 392 Missing directory creation before copying config. The test and 🛠️ Proposed fix for the test # Simulate what prepare_writable_config does
assert os.path.isfile(immutable), f'Immutable config missing: {immutable}'
+os.makedirs(os.path.dirname(writable), exist_ok=True)
shutil.copy2(immutable, writable)
os.chmod(writable, 0o600)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| # Verify the copy is writable by sandbox user | ||||||||||||||||||||
| with open(writable) as f: | ||||||||||||||||||||
| cfg = json.load(f) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Write a channel token to the writable copy | ||||||||||||||||||||
| cfg.setdefault('channels', {}).setdefault('discord', {})['botToken'] = 'test-token-606' | ||||||||||||||||||||
| with open(writable, 'w') as f: | ||||||||||||||||||||
| json.dump(cfg, f, indent=2) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Verify the write succeeded | ||||||||||||||||||||
| with open(writable) as f: | ||||||||||||||||||||
| updated = json.load(f) | ||||||||||||||||||||
| assert updated['channels']['discord']['botToken'] == 'test-token-606', 'Token write failed' | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Verify the immutable original is unchanged | ||||||||||||||||||||
| with open(immutable) as f: | ||||||||||||||||||||
| original = json.load(f) | ||||||||||||||||||||
| assert 'discord' not in original.get('channels', {}), 'Immutable config was modified!' | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Verify OPENCLAW_CONFIG_PATH would point to writable copy | ||||||||||||||||||||
| print(f'Writable config at: {writable}') | ||||||||||||||||||||
| print(f'Immutable config untouched: {immutable}') | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Clean up | ||||||||||||||||||||
| os.remove(writable) | ||||||||||||||||||||
| " && pass "Writable config overlay allows runtime writes without modifying immutable config" || fail "Writable config overlay failed" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| echo "" | ||||||||||||||||||||
| echo -e "${GREEN}========================================${NC}" | ||||||||||||||||||||
| echo -e "${GREEN} ALL E2E TESTS PASSED${NC}" | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing parent directory creation for writable config.
The
cpcommand on line 141 will fail with "No such file or directory" if~/.openclaw-data/doesn't exist. Add directory creation before copying.🛠️ Proposed fix
if [ ! -f "$writable_cfg" ] && [ -f "$immutable_cfg" ]; then + mkdir -p "$(dirname "$writable_cfg")" cp "$immutable_cfg" "$writable_cfg" chmod 600 "$writable_cfg" fi📝 Committable suggestion
🤖 Prompt for AI Agents