Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions core/wren/src/wren/genbi/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,20 @@ def remove_app(project_path: Path, name: str) -> bool:

def get_app(project_path: Path, name: str) -> dict | None:
"""Return the entry for ``name`` or None if not registered."""
return load_index(project_path)["apps"].get(name)
entry = load_index(project_path)["apps"].get(name)
# Hand-edited apps.yml may put a scalar/list under an app key; treat as
# unregistered rather than letting callers AttributeError on .get keys.
if entry is not None and not isinstance(entry, dict):
return None
return entry


def update_app(project_path: Path, name: str, **fields) -> dict:
"""Merge ``fields`` into the entry for ``name`` and persist."""
index = load_index(project_path)
entry = index["apps"][name]
entry = index["apps"].get(name)
if not isinstance(entry, dict):
raise KeyError(name)
entry.update(fields)
save_index(project_path, index)
return entry
13 changes: 13 additions & 0 deletions core/wren/tests/unit/test_genbi_get_app_guard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pathlib import Path

import yaml

from wren.genbi.index import get_app, load_index, save_index


def test_get_app_skips_non_dict_entry(tmp_path: Path):
idx = {"schema_version": 1, "apps": {"bad": "not-a-map", "good": {"source": "apps/good"}}}
save_index(tmp_path, idx)
assert get_app(tmp_path, "bad") is None
assert get_app(tmp_path, "good") == {"source": "apps/good"}
assert get_app(tmp_path, "missing") is None
Loading