fix(e2e): DigitalOcean name mismatch and bash 3.2 compat (#2218)

1. promptSpawnName() now checks DO_DROPLET_NAME before generating a
   random name, matching getServerName() behavior. This fixes the e2e
   harness creating droplets as spawn-XXXX when it expects
   e2e-digitalocean-AGENT-TIMESTAMP.

2. Replace BASH_REMATCH with sed-based parsing in provision.sh for
   macOS bash 3.2 compatibility. BASH_REMATCH was returning empty
   values, causing `export: '=': not a valid identifier`.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: L <6723574+louisgv@users.noreply.github.com>
This commit is contained in:
Ahmed Abushagur 2026-03-05 10:44:32 -08:00 committed by GitHub
parent 89e5e980c0
commit 08cf5e6d8a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 8 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "0.13.0",
"version": "0.13.1",
"type": "module",
"bin": {
"spawn": "cli.js"

View file

@ -1134,6 +1134,18 @@ export async function promptSpawnName(): Promise<void> {
return;
}
// Honour DO_DROPLET_NAME so headless/e2e callers can control the droplet name
if (process.env.DO_DROPLET_NAME) {
const name = process.env.DO_DROPLET_NAME;
if (validateServerName(name)) {
process.env.SPAWN_NAME_DISPLAY = name;
process.env.SPAWN_NAME_KEBAB = name;
logInfo(`Using resource name: ${name}`);
return;
}
logWarn(`Invalid DO_DROPLET_NAME '${name}', falling back to prompt`);
}
let kebab: string;
if (process.env.SPAWN_NON_INTERACTIVE === "1") {
kebab = (process.env.SPAWN_NAME ? toKebabCase(process.env.SPAWN_NAME) : "") || defaultSpawnName();

View file

@ -56,15 +56,25 @@ provision_agent() {
export OPENROUTER_API_KEY="${OPENROUTER_API_KEY}"
# Apply cloud-specific env vars (safe: only processes export VAR="VALUE" lines)
# Uses sed instead of BASH_REMATCH for macOS bash 3.2 compatibility
while IFS= read -r _env_line; do
if [[ "${_env_line}" =~ ^export[[:space:]]+([A-Za-z_][A-Za-z0-9_]*)=\"(.*)\"$ ]]; then
# Validate value against a safe character whitelist
if ! [[ "${BASH_REMATCH[2]}" =~ ^[A-Za-z0-9@%+=:,./_-]*$ ]]; then
log_err "Invalid characters in env value for ${BASH_REMATCH[1]}"
continue
fi
export "${BASH_REMATCH[1]}"="${BASH_REMATCH[2]}"
# Skip lines that don't look like export VAR="VALUE"
case "${_env_line}" in
export\ *=*) ;;
*) continue ;;
esac
# Extract variable name and value using sed
_env_name=$(printf '%s' "${_env_line}" | sed -n 's/^export *\([A-Za-z_][A-Za-z0-9_]*\)="\(.*\)"$/\1/p')
_env_val=$(printf '%s' "${_env_line}" | sed -n 's/^export *\([A-Za-z_][A-Za-z0-9_]*\)="\(.*\)"$/\2/p')
if [ -z "${_env_name}" ]; then
continue
fi
# Validate value against a safe character whitelist
if printf '%s' "${_env_val}" | grep -qE '[^A-Za-z0-9@%+=:,./_-]'; then
log_err "Invalid characters in env value for ${_env_name}"
continue
fi
export "${_env_name}=${_env_val}"
done <<CLOUD_ENV
$(cloud_headless_env "${app_name}" "${agent}")
CLOUD_ENV