Skip to content

Commit 4d5458c

Browse files
authored
fix: keep long frontmatter values on a single line (#3989)
`CommandRegistrar.render_frontmatter` calls `yaml.dump()` without `width=`, so PyYAML applies its default ~80-column wrap and folds any long scalar onto a continuation line. A `description` longer than roughly 80 characters is therefore rendered as: --- name: speckit-implement description: Execute the implementation plan by processing and executing all tasks defined in tasks.md --- The YAML remains valid and round-trips faithfully through `yaml.safe_load`, so this is not data loss. It is a shape inconsistency with real consequences: - Hand-written core command templates always keep `description` on one line, so preset- and extension-rendered commands do not match the files they sit beside in the same directory. - Consumers that read frontmatter line-wise rather than with a YAML parser see the description truncated at the fold, followed by a stray line. Spec Kit itself hand-builds SKILL.md frontmatter in the skills path (see #3391), so this is not a hypothetical class of consumer. - `speckit.implement`'s own description is 89 characters, so a preset that overrides it hits this immediately. `width=float("inf")` disables the line-wrapping only; escaping, quoting and the handling of genuinely multi-line values are unchanged, since PyYAML selects the scalar style before applying width. Adds a regression test that fails without the change. Verified against the repo's own suite: 6354 passed. Four failures in tests/integrations/test_integration_subcommand.py are present on a clean checkout too (ANSI escapes in captured output) and are unrelated.
1 parent 0ecb277 commit 4d5458c

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎src/specify_cli/agents.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ def render_frontmatter(fm: dict) -> str:
157157
return ""
158158

159159
yaml_str = yaml.dump(
160-
fm, default_flow_style=False, sort_keys=False, allow_unicode=True
160+
fm,
161+
default_flow_style=False,
162+
sort_keys=False,
163+
allow_unicode=True,
164+
width=float("inf"),
161165
)
162166
return f"---\n{yaml_str}---\n"
163167

‎tests/test_extensions.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import tempfile
1818
import shutil
1919
import tomllib
20+
import yaml
2021
from contextlib import contextmanager
2122
from pathlib import Path
2223
from datetime import datetime, timezone
@@ -2996,6 +2997,30 @@ def test_render_frontmatter_unicode(self):
29962997
assert "Prüfe Konformität" in output
29972998
assert "\\u" not in output
29982999

3000+
def test_render_frontmatter_keeps_long_description_on_one_line(self):
3001+
"""A long description must not be folded across lines.
3002+
3003+
PyYAML wraps plain scalars at ~80 columns by default, which splits a
3004+
long ``description`` onto a continuation line. The YAML stays valid,
3005+
but the rendered frontmatter then differs in shape from the
3006+
hand-written core command templates, where ``description`` is always a
3007+
single line -- and consumers that read frontmatter line-wise see a
3008+
truncated description followed by a stray line.
3009+
"""
3010+
long_description = (
3011+
"Execute the implementation plan by processing and executing all "
3012+
"tasks defined in tasks.md"
3013+
)
3014+
frontmatter = {"name": "speckit-implement", "description": long_description}
3015+
3016+
registrar = CommandRegistrar()
3017+
output = registrar.render_frontmatter(frontmatter)
3018+
3019+
assert f"description: {long_description}\n" in output
3020+
3021+
body = output.split("---\n")[1]
3022+
assert yaml.safe_load(body)["description"] == long_description
3023+
29993024
def test_adjust_script_paths_does_not_mutate_input(self):
30003025
"""Path adjustments should not mutate caller-owned frontmatter dicts."""
30013026
from specify_cli.agents import CommandRegistrar as AgentCommandRegistrar

0 commit comments

Comments
 (0)