Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions core/wren/src/wren/genbi/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,21 @@ def _data_mode_guidance(data_mode: str) -> str:
raise ValueError(f"unknown data-mode {data_mode!r}; expected one of {DATA_MODES}")


def _format_model_inventory(models: list[dict]) -> str:
def _format_model_inventory(models: list[dict] | None) -> str:
"""One markdown bullet per model with its column names."""
if not models:
return "- (no models found — run `wren context build` first)"
lines = []
for model in models:
cols = ", ".join(c.get("name", "?") for c in model.get("columns", []))
if not isinstance(model, dict):
continue
raw_cols = model.get("columns") or []
if not isinstance(raw_cols, list):
raw_cols = []
cols = ", ".join(c.get("name", "?") for c in raw_cols if isinstance(c, dict))
lines.append(f"- **{model.get('name', '?')}**: {cols}")
if not lines:
return "- (no models found — run `wren context build` first)"
return "\n".join(lines)


Expand Down
30 changes: 30 additions & 0 deletions core/wren/tests/unit/test_genbi_format_model_inventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from wren.genbi.composer import _format_model_inventory


def test_formats_clean_models():
text = _format_model_inventory(
[{"name": "orders", "columns": [{"name": "id"}, {"name": "total"}]}]
)
assert "orders" in text
assert "id" in text


def test_skips_non_dict_models_and_columns():
text = _format_model_inventory(
[
None,
"x",
{
"name": "t",
"columns": [None, {"name": "a"}, "bad"],
},
]
)
assert "t" in text
assert "a" in text
assert "None" not in text


def test_all_junk_falls_back_to_empty_message():
text = _format_model_inventory([None, "x", 1])
assert "no models found" in text
Loading