agentscope-ai / agentscope-ai/agentscope

fix: handle empty env vars in config loading (XDG_*, MODELSCOPE_*)

Ouverte Adaptée aux débutants
#2,447 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Python
Étoiles
31.6k
Forks
3.5k
Merge moyen
1 j 16 h
PR mergées (30 j)
103

Description

### Description

Similar to gptme's dirs handling, AgentScope's config loading checks `if var in os.environ` but doesn't handle empty string values.

### Example

```python
# Current
if "XDG_DATA_HOME" in os.environ:
path = Path(os.environ["XDG_DATA_HOME"]) / "agentscope"

# If env var is set to empty string (common in Docker or shell misconfig):
# Path("") / "agentscope" -> "agentscope" (relative, wrong location)
```

### Affected vars

- `XDG_DATA_HOME`, `XDG_CONFIG_HOME`, `XDG_STATE_HOME`
- Any custom env vars for model paths
- `AGENTSCOPE_*_DIR` etc.

### Proposed fix

Introduce helper:

```python
def get_env_path(var: str) -> Path | None:
val = os.environ.get(var, "").strip()
return Path(val) if val else None
```

And use:

```python
if (env_path := get_env_path("XDG_DATA_HOME")) is not None:
...
```

### Why

Prevents bugs in containers where env vars may be set to empty string. Improves robustness.

### Checklist

- [x] Searched existing issues
- [x] Single focused fix
- [x] Will add tests

Can I PR this?

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Start in the config-loading code path that checks `XDG_*` and `AGENTSCOPE_*` env vars as described in the issue. First read how those env values are currently read and then switch to a helper that trims and ignores empty/whitespace values before building paths. Add/extend tests for env loading behavior, run the config-related tests (or the full test suite if no dedicated one is listed), and mark done when empty env vars are treated as unset and valid paths still behave correctly.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
backend
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
Active
Clarté
Clairement spécifiée
Accessibilité débutants
78/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.