Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions containers/agent/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,27 @@ if [ -n "$CLAUDE_CODE_API_KEY_HELPER" ]; then
fi
echo "[entrypoint] ✓ $label apiKeyHelper validated"
else
echo "[entrypoint] $label exists but missing apiKeyHelper, writing..."
echo "{\"apiKeyHelper\":\"$CLAUDE_CODE_API_KEY_HELPER\"}" > "$config_file"
chmod 666 "$config_file"
echo "[entrypoint] ✓ Wrote apiKeyHelper to $label"
echo "[entrypoint] $label exists but missing apiKeyHelper, merging..."
# Use node to safely add apiKeyHelper to existing JSON without losing other fields
# (e.g. hasCompletedOnboarding, session tokens, user preferences)
if AWF_CONFIG_FILE="$config_file" AWF_KEY_HELPER="$CLAUDE_CODE_API_KEY_HELPER" \
node -e "
const fs = require('fs');
const file = process.env.AWF_CONFIG_FILE;
const helper = process.env.AWF_KEY_HELPER;
let obj = {};
try { obj = JSON.parse(fs.readFileSync(file, 'utf8')); } catch(e) {}
obj.apiKeyHelper = helper;
fs.writeFileSync(file, JSON.stringify(obj) + '\n');
" 2>/dev/null; then
chmod 666 "$config_file"
echo "[entrypoint] ✓ Merged apiKeyHelper into $label"
else
Comment on lines +185 to +200

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is fixing a CI blocker by preserving existing Claude Code config fields while adding apiKeyHelper, but there doesn’t appear to be an automated test that exercises the write_api_key_helper behavior (e.g., pre-seeded ~/.claude.json and ~/.claude/settings.json with additional fields, then verifying they are preserved and apiKeyHelper is set). Adding an integration test for this merge path would help prevent regressions in future entrypoint edits.

Copilot uses AI. Check for mistakes.
# Fallback if node is unavailable or the file is not valid JSON
echo "{\"apiKeyHelper\":\"$CLAUDE_CODE_API_KEY_HELPER\"}" > "$config_file"
chmod 666 "$config_file"
echo "[entrypoint] ✓ Wrote apiKeyHelper to $label (overwrite fallback)"
Comment on lines +201 to +204

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback JSON write uses echo "{\"apiKeyHelper\":\"$CLAUDE_CODE_API_KEY_HELPER\"}", which will produce invalid JSON (or change semantics) if CLAUDE_CODE_API_KEY_HELPER contains characters like quotes, backslashes, or newlines. Since this branch is used when node is missing/fails, it would be safer to generate JSON via a proper encoder (e.g., Node/JSON.stringify or another escaping approach) rather than interpolating directly into a JSON string.

See below for a potential fix:

          AWF_KEY_HELPER="$CLAUDE_CODE_API_KEY_HELPER" python - << 'EOF' > "$config_file"
import json, os, sys
helper = os.environ.get("AWF_KEY_HELPER", "")
json.dump({"apiKeyHelper": helper}, sys.stdout)
sys.stdout.write("\n")
EOF
          chmod 666 "$config_file"
          echo "[entrypoint] ✓ Wrote apiKeyHelper to $label (overwrite fallback)"
        fi
      fi
    else
      echo "[entrypoint] Creating $label with apiKeyHelper..."
      AWF_KEY_HELPER="$CLAUDE_CODE_API_KEY_HELPER" python - << 'EOF' > "$config_file"
import json, os, sys
helper = os.environ.get("AWF_KEY_HELPER", "")
json.dump({"apiKeyHelper": helper}, sys.stdout)
sys.stdout.write("\n")
EOF

Copilot uses AI. Check for mistakes.
fi
Comment on lines +193 to +205

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The node -e merge currently treats invalid JSON as success because JSON.parse(...) errors are swallowed. That means the else branch (commented as "file is not valid JSON") will never run for parse failures, and the log will say "Merged" even though the file was effectively overwritten with only apiKeyHelper. Consider making parse failures cause a non-zero exit (so the fallback path is taken and/or a clearer log is emitted), or update the comment/logging to reflect the actual behavior.

Copilot uses AI. Check for mistakes.
fi
else
echo "[entrypoint] Creating $label with apiKeyHelper..."
Expand Down
Loading