Files
tensors/tests
aladac c911abfe69 feat(generate): accept YAML in --input alongside JSON
`tsr generate --input <file>` previously only understood JSON, which was
awkward for hand-authored template libraries (e.g. ~/Projects/draw/templates/
ships *.yml scene files with embedded newlines and unquoted keys that mirror
the `tsr template` output shape).

Behavior:
- Files with .yml / .yaml extension parse as YAML; .json (or unknown
  extensions whose first non-whitespace char is '{' or '[') parse as JSON.
- Inline strings starting with '{' still parse as JSON (regression-safe).
- Inline strings without leading '{' now parse as YAML, enabling
  `tsr generate --input 'prompt: foo\nmodel: bar.safetensors'` without
  shell-quoting a JSON object.
- All downstream key-mapping / CLI-override / character / scene / lora
  / count handling is identical to the JSON path — parsing only differs.

Implementation:
- New `_parse_generate_input(value)` helper in tensors/cli.py centralizes
  source detection (file vs inline), format selection (extension or
  content sniff), and rich-formatted error reporting via typer.Exit(1).
- The pre-existing inline JSON merge block in `generate` is reduced to a
  single call to the helper.
- Adds pyyaml>=6.0 as a runtime dep. It was already transitively pulled
  in by huggingface_hub, but we depend on it directly so the surface
  contract is explicit and survives a hub re-pin.
- mypy override added for the yaml module (no upstream stubs in tree).

Tests:
- 20 new tests in tests/test_generate_input.py covering inline JSON,
  inline YAML, file by extension (.json/.yml/.yaml), unknown extension
  content sniffing, non-mapping rejection, malformed input handling,
  CLI-flag-wins-over-input precedence, and a full smoke against the
  exact draw template shape (with embedded newlines in the scene list).
- 359 -> 379 total tests. Lint clean on changed lines.

Co-Authored-By: OpenCode <noreply@anomaly.co>
2026-05-18 21:16:11 +02:00
..
2026-02-15 21:45:23 +01:00